Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
hi,
my application has a GUI developed in MFC. A Win32 DLL is also there, which does some file operations. The stage of each file operation, like, opened file, reading the file etc has to be displayed in the GUI.
How these messages can be posted from DLL to GUI for displaying, during the file operations?
Posted
Updated 22-Jun-10 23:02pm
v2

For instance, you may pass the GUI window handle to a DLL function, so that the library may store it and then use it to post messages.
:)
 
Share this answer
 
Comments
CPallini 23-Jun-10 5:05am    
ok. i used a function to pass the windows handle from the MFC app. After that i post message using this handle.
What are the steps for Posting the message?
Suppose i put "PostMessage(hWnd, WM_MY_MESSAGE,0,0)" from the dll, i am getting "unresolved external symbol __imp__PostMessageW@16 referenced in function....".
Am i missing something in DLL/MFC?
-- reshmi2000
CPallini 23-Jun-10 5:07am    
It looks like you missed to link with User32.lib. Check the Linker options for your DLL.
It seems a missing library on the linking step: try add user32.lib in the linker options, or add the following line somewhere in your DLL source files:

C++
#pragma comment(lib, "user32.lib")
 
Share this answer
 
yes. u are right. now my that problem is solved. Successfully linked. Thanks..
Now the problem occurred while running the app. i called a dll function to pass the windows handle, from MFC. see the code part below...


 /* get handle to dll */ <br />
   HINSTANCE hGetProcIDDLL = AfxLoadLibrary(_T("Logic.dll")); <br />
<br />
   /* get pointer to the function  in the dll HERE AN EXCEPTION OCCURING*/ <br />
   FARPROC lpfnGetProcessID = GetProcAddress(HMODULE (hGetProcIDDLL),"StartUpdate"); <br />
	<br />
   /* <br />
      Define the Function in the DLL for reuse. This is just prototyping the dll's function. <br />
      A mock of it. Use "stdcall" for maximum compatibility. <br />
   */ <br />
   typedef void (__stdcall * pICFUNC)(HWND); <br />
   pICFUNC StartUpdate;  /* passes handle, function defined in DLL*/<br />
   StartUpdate= pICFUNC(lpfnGetProcessID); <br />
<br />
   /* The actual call to the function contained in the dll PASSING HANDLE*/ <br />
      StartUpdate(CMyAppDlg::GetSafeHwnd());<br />
<br />
   /* Release the Dll */ <br />
   FreeLibrary(hGetProcIDDLL); 


What can be ths exception? lpfnGetProcessID was having 0x0000000 in it..
 
Share this answer
 
Did you mark your exported function with extern "C"?
For instance
extern "C"
{
// here function declaration 
}

Otherwise the function name would be mangled.
:)
 
Share this answer
 
From your code snippet seems that you declared your exported function as __stdcall; as you can see in the MSDN (__stdcall (C++)[^]), functions that use this calling conventions get their names decorated as follow:


  • an underscore is prefixed to the function name
  • the function name is followed by the sign @ followed by the number of bytes in decimal required by the arguments


Then you must write something like:

C++
// On 32 bit systems sizeof(HWND) is 4 bytes
FARPROC pFunc = GetProcAddress((HMODULE)hDllInstance, "_StartUpdate@4");


The solution that Cpallini suggested you is the easiest one because functions exported with C linkage (i.e. using extern "C") doesn't get their names decorated (see __cdecl (C++)[^]).
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900