argument of type char * is incompatible with parameter of type lpwstr

I am reading up on a older tutorial on how to make a window and I was told to write this code fragment into WndProc, but I get an error saying: "argument of type char * is incompatible with parameter of type lpwstr", what could I be doing wrong?
This is suppose to show the user the name of the program when they click the window.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;

	switch (message)
	{
		
	case WM_LBUTTONDOWN://I added code below
	{
		char szFileName[MAX_PATH];
		HINSTANCE hInstance = GetModuleHandle(NULL);

		GetModuleFileName(hInstance, szFileName, "This program is:", MB_OK | MB_ICONINFORMATION);

	}
		break;//I added code above
	case WM_COMMAND:
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// Parse the menu selections:
		switch (wmId)
		{
		case IDM_ABOUT:
			DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
			break;
		case IDM_EXIT:
			DestroyWindow(hWnd);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		break;
	case WM_PAINT:
		hdc = BeginPaint(hWnd, &ps);
		// TODO: Add any drawing code here...
		EndPaint(hWnd, &ps);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
sounds like an asci problem then i googled it and the first result confirmed my thought.
google your error exact words and you find you are not the only one.
"argument of type char * is incompatible with parameter of type lpwstr"
other then the asci i can't help any further.
good luck.
How many parameters does the function GetModuleFileName() take?

According to MSDN, is should be three:
1
2
3
    HMODULE hModule,
    LPTSTR lpFilename,
    DWORD nSize


but the above code tries to pass four:
1
2
3
4
    hInstance, 
    szFileName, 
    "This program is:", 
    MB_OK | MB_ICONINFORMATION

That problem needs to be fixed first, before starting to consider the type and purpose of each parameter.

It looks as though two completely different functions, GetModuleFileName() and MessageBox() have been mixed up in a single statement.


Many Windows functions come in three different flavours, such as:
1
2
3
GetModuleFileName
GetModuleFileNameW
GetModuleFileNameA
when using ordinary character strings, the version with the 'A' suffix should be used, such as GetModuleFileNameA() or MessageBoxA()

1
2
3
4
5
6
7
8
9
10
    case WM_LBUTTONDOWN:
    {
        char FileName[MAX_PATH];
        HINSTANCE hInstance = GetModuleHandle(NULL);

        GetModuleFileNameA(hInstance, FileName, sizeof(FileName));

        MessageBoxA(hWnd, FileName, "This program is:", MB_ICONINFORMATION);
    }
    break;


http://msdn.microsoft.com/en-gb/library/windows/desktop/ms683197%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms645505%28v=vs.85%29.aspx
Last edited on
Topic archived. No new replies allowed.