Hello everybody, I'm new in this forum. I don't know where to place this thread, because it's about VB6 and C, but I think the problem is in the C code so here I am. I'm working with C with no special focus, so the solution can be in C++ too :)
Well, this is the problem. I have a VB6 program that simply calls a function when the Command1 is pressed. This one:
Public Function SampleSub(ByVal x As Integer, ByVal y As Integer) As Boolean
MsgBox "Hello world!"
SampleSub = True
End Function
I'm trying to call it from C like this:
#include "main.h"
typedef BOOL (__stdcall *SampleSubPtr)(WORD, WORD);
static SampleSubPtr SampleSub;
DLL_EXPORT BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
BOOL ret;
if (fdwReason == DLL_PROCESS_ATTACH)
{
SampleSub = (SampleSubPtr)(0x00401B90);
if (SampleSub == NULL)
MessageBox(0, "SampleSub is NULL.", "M", 0);
ret = SampleSub(5, 5);
}
return TRUE;
}
0x00401B90
is the pointer to the VB6 function. Then I place this DLL into the VB6 program memory space and the function is called. But it simply doesn't work. Debugging this with OllyDbg gives me this error when calling the function:
Access violation when reading [00000076]
I'm 100% sure that the function is at the address 0x00401B90
. VB6 uses __stdcall
and I use __stdcall
from C. VB6 uses 16-bit integers and I use 16-bit integers (WORD
) from C.
I can't solve this. Any ideas?
Thanks in advance! :)