Click here to Skip to main content
15,913,186 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generalchat window BG Pin
ANDYFA20-Jul-04 14:19
ANDYFA20-Jul-04 14:19 
GeneralRe: chat window BG Pin
Antti Keskinen20-Jul-04 23:07
Antti Keskinen20-Jul-04 23:07 
GeneralDlls, callbacks and function pointers Pin
Irenepower20-Jul-04 10:51
Irenepower20-Jul-04 10:51 
GeneralRe: Dlls, callbacks and function pointers Pin
Antti Keskinen20-Jul-04 11:43
Antti Keskinen20-Jul-04 11:43 
GeneralRe: Dlls, callbacks and function pointers Pin
Member 124998021-Jul-04 3:37
Member 124998021-Jul-04 3:37 
GeneralRe: Dlls, callbacks and function pointers Pin
Antti Keskinen21-Jul-04 3:54
Antti Keskinen21-Jul-04 3:54 
GeneralRe: Dlls, callbacks and function pointers Pin
Member 124998021-Jul-04 4:59
Member 124998021-Jul-04 4:59 
GeneralRe: Dlls, callbacks and function pointers Pin
Antti Keskinen21-Jul-04 7:21
Antti Keskinen21-Jul-04 7:21 
IrenePwr wrote:
- but as CListener is also defined inside the DLL and an object instanstiated; instead of executing the MyFunction from the object outside the DLL, it was the MyFunction from the object inside the DLL the one that was executed... Strange, I know.

This is correct. The DLL has it's own memory space, and the run-time interpreted the pointer you passed. Because a similar object was found in this local space, the run-time thought that it must be this one.

I also doubt that you did not use GetProcAddress to get either the address or the function to return the address. Try doing it so that you export a function from the main module, and use GetProcAddress to get this function. The function just returns the address of the local CListener object. This ensures that the function executes in the address space of the main module, and thus the address returned points into the main module's memory area instead of the DLL's.

One more option would be to try to use __declspec(dllexport) on the class in the main module. This WILL limit the number of the objects instantated to a single one, because you can't export multiple objects with same signatures. This wouldn't be safe. Then using __declspec(dllimport) to create a pointer-to-class in the DLL, and it "should" discover the correct class, as it looks for it across the DLL boundaries.

Greatest problems arise due to the CListener class found inside the DLL. Could it be a viable option to create a copy of CListener class and rename it as CDLLListener, for example ?
This would change the signatures of the objects, and might thus allow us to use the pointers you mentioned without the danger that it'd point to the local object instead of the remote one.

-Antti Keskinen

----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
GeneralRe: Dlls, callbacks and function pointers Pin
Antti Keskinen21-Jul-04 8:21
Antti Keskinen21-Jul-04 8:21 
GeneralRe: Dlls, callbacks and function pointers Pin
Member 124998021-Jul-04 10:11
Member 124998021-Jul-04 10:11 
GeneralRe: Dlls, callbacks and function pointers Pin
-Irenepower22-Jul-04 2:41
suss-Irenepower22-Jul-04 2:41 
GeneralCopyFile Error on XP Pin
Timothy Grabrian20-Jul-04 10:15
professionalTimothy Grabrian20-Jul-04 10:15 
GeneralRe: CopyFile Error on XP Pin
gamitech20-Jul-04 11:13
gamitech20-Jul-04 11:13 
GeneralRe: CopyFile Error on XP Pin
P-Rex20-Jul-04 20:15
P-Rex20-Jul-04 20:15 
GeneralRe: CopyFile Error on XP Pin
Timothy Grabrian21-Jul-04 11:15
professionalTimothy Grabrian21-Jul-04 11:15 
GeneralI need Help on Database Programming!!! Pin
Member 123981320-Jul-04 10:03
Member 123981320-Jul-04 10:03 
GeneralRe: I need Help on Database Programming!!! Pin
David Crow20-Jul-04 10:33
David Crow20-Jul-04 10:33 
GeneralCreating ActiveX control (variable types) Pin
BlackDice20-Jul-04 9:26
BlackDice20-Jul-04 9:26 
Generalwindow message Pin
Anonymous20-Jul-04 9:10
Anonymous20-Jul-04 9:10 
GeneralRe: window message Pin
Alexander Wiseman20-Jul-04 9:21
Alexander Wiseman20-Jul-04 9:21 
GeneralRe: window message Pin
Anonymous20-Jul-04 9:35
Anonymous20-Jul-04 9:35 
GeneralRe: window message Pin
Alexander Wiseman20-Jul-04 11:29
Alexander Wiseman20-Jul-04 11:29 
GeneralRe: window message Pin
Bob Stanneveld20-Jul-04 12:58
Bob Stanneveld20-Jul-04 12:58 
GeneralCOM programming Pin
Tropicana20-Jul-04 8:48
Tropicana20-Jul-04 8:48 
GeneralRe: COM programming Pin
Antti Keskinen20-Jul-04 11:58
Antti Keskinen20-Jul-04 11:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.