I use Visual Studio 2005, and when I build to debug it compiles fine (with only two warnings).

When I buid to realise I get this:

------ Build started: Project: TYCK, Configuration: Release Win32 ------
Compiling...
main.cpp
.\main.cpp(19) : warning C4244: 'initializing' : conversion from 'INT_PTR' to 'int', possible loss of data
.\main.cpp(22) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [25]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
.\main.cpp(45) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [62]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
.\main.cpp(56) : error C2664: 'GetModuleFileNameW' : cannot convert parameter 2 from 'char [260]' to 'LPWCH'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
.\main.cpp(57) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'char [260]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
.\main.cpp(58) : error C2664: 'CopyFileW' : cannot convert parameter 1 from 'const char [30]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
.\main.cpp(61) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [46]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
.\main.cpp(63) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [46]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
.\main.cpp(64) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [82]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
.\main.cpp(75) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [5]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
.\main.cpp(82) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [5]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
.\main.cpp(113) : error C2440: '=' : cannot convert from 'const char [14]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
.\main.cpp(120) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [34]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
.\main.cpp(133) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [14]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
.\main.cpp(137) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [6]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
.\main.cpp(150) : warning C4244: 'return' : conversion from 'WPARAM' to 'int', possible loss of data
Build log was saved at "file://c:\Users\jan\Documents\Visual Studio 2005\Projects\virus2\virus\Release\BuildLog.htm"
TYCK - 14 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Here is a main.cpp

#include <windows.h>

#include "resource.h"

const char g_szclassName[] = "myWindowClass";

BOOL CALLBACK WelcomeDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_INITDIALOG:
    return TRUE;
    case WM_COMMAND:
    switch(LOWORD(wParam)) 
    {
        case IDD_WELCOME:
        {
            int ret = DialogBox(GetModuleHandle(NULL), 
                MAKEINTRESOURCE(IDD_WELCOME), hwnd, WelcomeDlgProc);
            if(ret == IDC_OK){
                MessageBox(hwnd, "Dialog exited with IDOK.", "Notice",
                    MB_OK | MB_ICONINFORMATION);
            }
            
            }
        }
        break;
        
    


}
return TRUE;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
    case WM_CREATE:
    Beep( 100, 0);
    //DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_WELCOME), hwnd, WelcomeDlgProc); 
    
    
    MessageBox(NULL, "You will need pencil and some paper, or just some experience.", "What will you need", MB_OK | MB_ICONINFORMATION);
    break;

    

        
    case WM_LBUTTONDOWN:
        {    
            char fileName[MAX_PATH];
            char newFile[MAX_PATH] = "C:\\TYCK.exe";       
            HINSTANCE hInstance = GetModuleHandle(NULL);
            GetModuleFileName(hInstance, fileName, MAX_PATH);
            MessageBox(hwnd, fileName, "The path is", MB_OK | MB_ICONINFORMATION);
            CopyFile("C:\\Users\\jan\\Desktop\\TYCK.exe", newFile, 0);
            Beep(1000, 300);
            Beep(1000, 15000);
            MessageBox(NULL, "This is a level 1. Problem is still unsolved.", "Info", MB_OK | MB_ICONEXCLAMATION);
            system("Engine_part_one.exe");
            MessageBox(NULL, "This is a level 2. Problem is still unsolved.", "Info", MB_OK | MB_ICONEXCLAMATION);
            MessageBox(NULL, "This is a level 3. Problem is still unsolved \n You can start with rescuing files.", "Info", MB_OK | MB_ICONEXCLAMATION);
            system("everybody_dance_now.exe");



        }
        break;
                case WM_COMMAND:
            switch(LOWORD(wParam)) 
            {
                case ID_FILE_EXIT: 
                    MessageBox(NULL, "Exit", "quit message", MB_OK | MB_ICONEXCLAMATION);
        DestroyWindow(hwnd);
               break;
                
            }
        break;
    case WM_CLOSE:
        MessageBox(NULL, "Exit", "quit message", MB_OK | MB_ICONEXCLAMATION);
        DestroyWindow(hwnd);

        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}



int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{

    WNDCLASSEX wc;
    HWND hwnd;
    MSG Msg;

    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = 0;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1));
    wc.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 16, 16, 0);
    wc.hInstance = hInstance;
    wc.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
    wc.lpfnWndProc = WndProc;
    wc.lpszClassName = g_szclassName;
    wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1); 
    wc.hCursor = LoadCursor(GetModuleHandle(NULL), MAKEINTRESOURCE(IDC_MYPOINTERC));
    

    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, "Err: Error with registering class", "Error ",  MB_ICONERROR | MB_OK);
        return 0;
    }

    hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szclassName,
"TYCK: Beginner",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
600,
650,
NULL,NULL, hInstance, NULL);

    if(hwnd == NULL)
    {
        MessageBox(NULL,"ERROr", "HWND ERR", MB_OK | MB_ICONERROR);
        return 0;
    }

    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }

    return Msg.wParam;



}

Im sorry for so stupid code, but Im still winapi newbie.

Dani AI

Generated

The compiler errors come from a character-set mismatch: the project is building with Unicode so the generic Win32 names (MessageBox, CreateWindowEx, GetModuleFileName, CopyFile, etc.) map to the wide-character variants (MessageBoxW, CreateWindowExW, GetModuleFileNameW, CopyFileW) which expect wide strings (wchar_t*, LPCWSTR). The posted code uses narrow char literals and buffers, so the compiler rejects const char[] -> LPCWSTR conversions.

Three practical fixes (choose one and apply consistently):

  1. Prefer modern Unicode: switch code to use generic TCHAR/TEXT or explicit wide APIs and wide literals. Also use the correct dialog return type to avoid the C4244 warning. Example fixes:
INT_PTR ret = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_WELCOME), hwnd, WelcomeDlgProc);
if (ret == IDOK) {
    MessageBox(hwnd, TEXT("Dialog exited with IDOK."), TEXT("Notice"), MB_OK | MB_ICONINFORMATION);
}

TCHAR fileName[MAX_PATH];
GetModuleFileName(NULL, fileName, MAX_PATH);
MessageBox(hwnd, fileName, TEXT("The path is"), MB_OK | MB_ICONINFORMATION);

return (int)Msg.wParam;

Also declare the dialog proc as INT_PTR CALLBACK WelcomeDlgProc(...) (not BOOL CALLBACK) for correctness on 64-bit/modern SDKs.

  1. Keep ANSI: set Project -> Configuration Properties -> General -> Character Set to "Use Multi-Byte Character Set" (this is what did). That will map generic calls to the A-suffixed functions, so existing char literals compile.

  2. Explicit APIs: call the A- or W- suffixed functions directly (MessageBoxA / MessageBoxW, CopyFileA / CopyFileW) and match literal types ("..." for ANSI, L"..." for wide).

Extra notes: compare dialog return to IDOK (not IDC_OK). Silence the WPARAM->int warning by casting return (int)Msg.wParam; or using the proper integer types. Consistency is key: mixing ANSI and Unicode in the same build causes the exact errors seen.

Ok I solved the problem with disabling unicode character set

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.