Sign in to follow this  

How the Windows Procedure works?

This topic is 4690 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

Hi, I'm wondering a bit about how the Windows Procedure works, because I think i'm trying to do something similar to it. I'm creating a DX sorta GUI system, and in the final project, it would be initialized something like this..
void GUIProc(UINT Msg, UNIT ID, UNIT Data);
GUI GUISystem;

int WINAPI WinMain(blah blah)
{
   GUISystem.SetGUIProc(GUIProc)
   GUISystem.Initalize(GUI.xml, Direct3dDevice);
   //initialize Windows and DX
   //...
}

void GUIProc(UINT Msg, UINT ID, UINT DATA)
{
switch (Msg)
//blah blah
}

It's suppose to work very similar to the WndProc. The GUIProc would handle all the GUI messages and such, but that part isn't the part i'm worried about, its the part where the GUI system is acutally coded..right now I have in my GUI.dll
void ( *GUIProc) (unsigned int Msg, unsigned int ID, unsigned int DATA);
and then within the dll i send out the messages like..
//button was pressed
GUIProc(GL_LBUTTONDOWN, GetID(), 0);
the dll all compiles fine, but then i get the very simple
Initialization.obj : error LNK2001: unresolved external symbol "void (__cdecl* GUIProc)(unsigned int,unsigned int,unsigned int)" (?GUIProc@@3P6AXIII@ZA)
main.obj : error LNK2001: unresolved external symbol "void (__cdecl* GUIProc)(unsigned int,unsigned int,unsigned int)" (?GUIProc@@3P6AXIII@ZA)
error messages in the final project.. i'm not quite sure what i'm doing wrong, and I'm curious if i'm suppose to be using a function pointer like i'm doing? (thats why I asked how the WndProc works? Thanks a bunch

Share this post


Link to post
Share on other sites
You are defining a pointer to function, and it looks ok. Then you are using it and it looks ok too. But the errors are a bit weird. :/

Oh. Did you do something like:

external void ( *GUIProc) (unsigned int Msg, unsigned int ID, unsigned int DATA);

In a header? Perhaps you forgot to define GUIProc (the line above is a declaration, not a definition).

This would make sense.

HTH,

Share this post


Link to post
Share on other sites
in my GUI.h file (for the dll project) i have


#define DLL_EXPORT __declspec(dllexport)
extern DLL_EXPORT void ( *GUIProc) (unsigned int, unsigned int, unsigned int);

the DLL_EXPORT i actually added just to see if that would help..which it didn't..same errors

and then in one of my .cpp files I have

void ( *GUIProc) (unsigned int, unsigned int, unsigned int);

and then that all compilies fine..

is it something to do with having something exported?

Share this post


Link to post
Share on other sites
Wow. Let's restart :) I don't understand your last post. Did you manage to get it to compile? If yes, was it by adding the DLL_EXPORT or by adding the definition of GUIproc in a cpp file? I'm somewhat confused...

Regards,

Share this post


Link to post
Share on other sites
oh sorry,
I have 2 projects..The DLL project...and then the acutal project that uses the DLL

The DLL project compiles fine..no errors..

when i load the dll and try to use it (by using the .lib and the GUI.h and GUI.dll files) thats when those linking errors occur..

hope that cleared it up a bit

Share this post


Link to post
Share on other sites
Then you have to export GUIProc from the DLL to be able to use in the DLL client (the host application). The later have to import the GUIProc symbol to use it.

Typical DLL export/import use the following code in the header file:

#ifdef I_AM_COMPILING_MY_DLL
# define MYDLLAPI __declspec(dllexport)
#else
# define MYDLLAPI __declspec(dllimport)
#endif

I_AM_COMPILING_MY_DLL is defined only when (you guess it) you are compiling your DLL :)

If you dont do that then your host application won't be able to use your symbol. Bu since the symbol is declared, it will compile fine - and will blow up during the link phase.

Hope that make sense,

Share this post


Link to post
Share on other sites
hmm..thank you very much for your help Emmanuel Deloget, but i'm afraid I don't really understand..

maybe i should read some more on DLLs?, I don't understand the whole importing thing

Share this post


Link to post
Share on other sites

This topic is 4690 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