Click to See Complete Forum and Search --> : How to share a pointer to a callback fucntion in DLL?


Jaba_z
July 5th, 2002, 10:36 PM
How to store a pointer to the callback function in the shared block of data in the DLL?

I'm tring to write a C DLL that will call a function in VB when certain conditions are met. I need to store that pointer to the callback function somewhere in the DLL, and that pointer must be accessible to all the instances of the DLL. Since the DLL is accessed by both an exe and VB application (they are actually plug-ins in exe the host aplication), there can be quote a few of them running at the same time.

Thanx in advance for all your help.

Alexey B
July 5th, 2002, 11:21 PM
You can not make a pointer to a function available to several processes, because it will probably be stored in different places in different processes. Win32 pointers are process relative. You can use GetProcAddress to find the address of the function in each process. It is defined asFARPROC GetProcAddress(
HMODULE hModule, // handle to DLL module
LPCSTR lpProcName // name of function
);

Jaba_z
July 6th, 2002, 12:00 AM
hmm... let me try to keep it as simple as possible. How could I make 1 VB application register it's callback function with a DLL, and then another (VB) application retrieve that 1st app's function address? For example, if the 1st app's callback function displays a message box, how could I (using DLL) make the message appear in app #1 by pressing a button in application #2?

If I can get an answer to that question, I'll be more than happy :)

Jaba

arunkumar_gona
July 8th, 2002, 04:29 PM
Even though same DLL is being used by 2 different applications, their heap and stack memory are not shared between the DLL's and hence one application cannot retrieve another applications pointer.

Here , what you are talking is Inter Process Communication. There are couple of ways to achieve this.

1. Windows Messaging System
2. Memory Mapped Files.

You can dig into these and try to find a solution for your case.

Neerad
July 8th, 2002, 10:46 PM
Actually COM Interface just does that. A COM dll is able to keep track of functions in different executables for notifying as and when required. So there must be a way without using interprocess communication i.e. COM interface implementation. I am in the process of digging it out.

arunkumar_gona
July 9th, 2002, 10:51 AM
I don't think you can achieve this with COM DLL, but you can with COM EXE's.