Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / General Programming / problem with WndProc - really need help here Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
pixelpajas

February 12, 2005, 06:50 AM

I think Iím going crazy pretty soon. Iím Trying to fix a problem that is probably so simple that I will have to kill myself after I have solved it.

The error message I get in VC++ 2005 (beta1) compiler:

screen.obj : error LNK2019: unresolved external symbol "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) referenced in function "int __fastcall ptc_open(char *,int,int)" (?ptc_open@@YIHPADHH@Z)


I have been playing around with tiny_ptc and wanted to pull out WndProc (out of screen.cpp) to a separate file called: msghandler.cpp

This is what parts of the file structure /w content looks like for the project:


screen.cpp - handles all the screen ddraw graphics
-------------------------------------------------------
int ptc_open(char *title,int width,int height) {...}
int ptc_update(void *buffer) {...}
void ptc_close() {...}
void ptc_paint_primary() {...}


screen.h - declarations
-------------------------------------------------------
int ptc_open(char *title,int width,int height);
int ptc_update(void *buffer);
void ptc_close();
void ptc_paint_primary();


msghandler.cpp - handels all the events
-------------------------------------------------------
static LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam) {...}


msghandler.h - declaration
-------------------------------------------------------
LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);




So it seem like the linker can't quite find WndProc(...) when referenced in the function ptc_open(...). How come ?

When WndProc is in screen.cpp it all works fine. But when i pull it out to a separate file it does not want to play with me anymore. =(

Is there anyone here that could help me out and give me a pointer on where Iím making my mistake?


thanks
//iman

 
Chris

February 12, 2005, 06:57 AM

static LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam) {...}

why "static" ? It isn't a member of any class, so static makes no sense here. If it were a member, "static" belonged into the header, not into the implementation.

Does screen.cpp include msghandler.h ?

Do the call conventions (fastcall, cdecl, stdcall, etc.) match ? CALLBACK is effectively __stdcall.

Finally, do a complete rebuild.

 
pixelpajas

February 12, 2005, 07:04 AM

> why "static" ? It isn't a member of any class ...

Nope. Not a member of a class. No OO in the code. Just C like code using some of the benefits of the C++ compiler.

> Does screen.cpp include msghandler.h ?

Yes.

> Do the call conventions (fastcall, cdecl, stdcall, etc.) match ? CALLBACK is effectively __stdcall.

Yes.

> Finally, do a complete rebuild.

Done it a million times by now. =|


 
pixelpajas

February 12, 2005, 07:11 AM


I managed to fix my problem now.
So thanks anyway.


cheers
//iman

 
Chris

February 12, 2005, 09:07 AM

> Just C like code using some of the benefits of the C++ compiler.

"static" gives no benefit here. What do you think I does for you ?

 
pixelpajas

February 12, 2005, 09:33 AM

> Just C like code using some of the benefits of the C++ compiler.

>> "static" gives no benefit here. What do you think I does for you ?

I was not reffering to the usage of static keyword. Sorry for the confusion.
I was reffering to that i was using the C++ compiler but not OO (classes and such).

I removed static a while ago. But it kind of slipped (dont ask me why) when i put out the post.

 
criznach

February 14, 2005, 09:56 AM

Good that you did, because I believe the static keyword on a globally declared function makes it's linkage local to that source file... Which would have caused the problem you were having.

See this link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/basic_37.asp

and here's a quote...
"Objects and variables defined outside all blocks have static lifetime and external linkage by default. A global object or variable that is explicitly declared as static has internal linkage."

 
This thread contains 7 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.