Sign in to follow this  

Weird Windows API Build Error With MSVC++ .NET

This topic is 4866 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The error I get is: c:\Documents and Settings\Owner\My Documents\Visual Studio Projects\DirectX\main.cpp(72) : error C2371: 'wParam' : redefinition; different basic types c:\Documents and Settings\Owner\My Documents\Visual Studio Projects\DirectX\main.cpp(72) : see declaration of 'wParam' c:\Documents and Settings\Owner\My Documents\Visual Studio Projects\DirectX\main.cpp(72) : fatal error C1903: unable to recover from previous error(s); stopping compilation On that line, is this: LRESULT CALLBACK WndProc(HWND hWindow, UINT Message, WPARAM wParam, LPARAM wParam) { (That's where I define the Windows Process Handler.) This has never happened before to me.

Share this post


Link to post
Share on other sites
Try going Edit->Find In Files, type in wParam, hit Search. Then tell us the results (post little code excerpts where you found the occurences).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It looks like a typo :) you'll know what's wrong if you read the compiler errors carefully

LRESULT CALLBACK WndProc(HWND hWindow, UINT Message, WPARAM wParam, LPARAM lParam)

Share this post


Link to post
Share on other sites
Find all "wParam", Subfolders, Find Results 1, Current Project: DirectX.vcproj, "*.*"
C:\Documents and Settings\Owner\My Documents\Visual Studio Projects\DirectX\main.cpp(7):LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
C:\Documents and Settings\Owner\My Documents\Visual Studio Projects\DirectX\main.cpp(72):LRESULT CALLBACK WndProc(HWND hWindow, UINT Message, WPARAM wParam, LPARAM wParam)
C:\Documents and Settings\Owner\My Documents\Visual Studio Projects\DirectX\main.cpp(94): return DefWindowProc(hWindow, Message, wParam, lParam);
Total found: 3 Matching files: 1 Total files searched: 1

On the first one, it is the function prototype. The second is where I define the function, and the third is what I return when exiting the function.

Share this post


Link to post
Share on other sites
And the complete source code is...



#include <windows.h>

HWND hWindow;
MSG Message;

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

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

WNDCLASS WindowClass;

WindowClass.cbClsExtra = 0;
WindowClass.cbWndExtra = 0;
WindowClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
WindowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WindowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WindowClass.hInstance = hInstance;
WindowClass.lpfnWndProc = WndProc;
WindowClass.lpszClassName = "Window Class";
WindowClass.lpszMenuName = NULL;
WindowClass.style = 0;

if (!RegisterClass(&WindowClass))
{

return 0;

}

if (!(hWindow = CreateWindow("Window Class", "DirectX", WS_OVERLAPPEDWINDOW, 0, 0, 640, 480, NULL, NULL, hInstance, NULL)))
{

return 0;

}
else
{

ShowWindow(hWindow, 0);
UpdateWindow(hWindow);

}

while (1)
{

if (PeekMessage(&Message, NULL, 0, 0, 0))
{

TranslateMessage(&Message);
DispatchMessage(&Message);

}

}

UnregisterClass("Window Class", hInstance);

return 0;

}

LRESULT CALLBACK WndProc(HWND hWindow, UINT Message, WPARAM wParam, LPARAM wParam)
{

switch (Message)
{

case WM_CLOSE:

DestroyWindow(hWindow);
break;

case WM_DESTROY:

PostQuitMessage(0);
break;

default:

break;

}

return DefWindowProc(hWindow, Message, wParam, lParam);

}



Share this post


Link to post
Share on other sites
Look at the line that the AP wrote; there's one little important difference from yours.

What the typo was is that you've defined a parameter named 'wParam' twice: Once as a WPARAM, the second time as a LPARAM.

Share this post


Link to post
Share on other sites

This topic is 4866 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this