
Calling a VB function/procedure from Visual C++ DLL
Hello,
I have a {*filter*} problem and I really could not solve it myselfe.
What I wanted to try is calling a Visual Basic (v 5.0) function/
procedure from within a Windows DLL written in Visual C++
(v 4.2). For instance the dll could then message an event to
the VB programm.
I do not want to use OLE or something like this because it
would be a little bit too much overhead for this programm.
So I thougt I would call a dll-function and provide it the
adress of the VB function to call back. If a certain event
occurs, the dll should then call this VB function.
I tried it with the little test program attached to this posting
but what happens is excatly nothing - not even a crash.
(I know, with my method I will run into some other troubles
like the VB function gets sorted to another place in memory,
but this are things I wanted to deal with later.)
Could anyone help me with this?
Thanks in advance very much,
Anton Engel
------ VB part begin ------
Declare Sub initme Lib "testdll" (ByVal theCallBackFunct As Long)
Declare Sub thecallback Lib "testdll" ()
Private Sub Command1_Click()
initme AddressOf CallBackMe
thecallback
End Sub
Public Sub CallBackMe()
MsgBox "got it :-)"
End Sub
------ VB part end ------
------ VC++ testdll.c begin ------
#include "windows.h"
FARPROC lpfnForgProc;
void APIENTRY initme(FARPROC theProc)
{
lpfnForgProc = theProc;
Quote:
}
void APIENTRY thecallback(void)
{
(*lpfnForgProc);
Quote:
}
------ VC++ testdll.c end ------
------ VC++ testdll.def begin ------
NAME testdll.dll
DESCRIPTION 'testing VB callback'
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE MULTIPLE
HEAPSIZE 1024
STACKSIZE 5120
EXPORTS
------ VC++ testdll.def end ------