Calling to a pointer from a c++ thread


I'm trying to call from a thread to a pointer. Here is my code:

myDll.dll c++ :

long cbAddrAsync;
void _asyncer(void* data)
        typedef void (__stdcall *FUNCPTR)();
    FUNCPTR vbFunc;
    vbFunc = (FUNCPTR)cbAddrAsync;
extern "C" __declspec(dllexport) void async(long addr)
    cbAddrAsync = addr;
    HANDLE hHandle = (HANDLE)_beginthread(_asyncer,0,NULL);

calling to this extern with vb6: In Module1:

Declare Sub async Lib "myDll.dll" (ByVal addr As Long)
Sub onAsync()
MsgBox "ASYNC"
End Sub

In Form1:

Private Sub Command_Click()
Call async(AddressOf Module1.onAsync)
End Sub

when i click at command button , The problem occurs in

Unhandled exception at 0x734f9232 in Project1.exe: 0xC0000005: Access violation reading location 0x00000076.
in vbFunc();

How can I fix it? Thanks.

asked on Stack Overflow Sep 20, 2014 by Mohammad Drk • edited Sep 20, 2014 by ne1410s

1 Answer


0x00000076 is an invalid memory address. All addresses under 0x0000ffff are invalid. This catches a whole class of errors (failed memory allocations or object creation) along the lines of 0x0 and 0x0 + 2 (or 0x0 + 0x76) etc. The errors are errors that programmers are supposed to check for but often don't.

My guess is you are accessing the 0x76th byte of a structure that wasn't initialised.

VB6 is designed to be a COM server not a dynamic load dll.

AddressOf has rules because you are actually calling VB6 runtime not your program.

You can also start in a debugger.

windbg or ntsd (ntsd is a console program and maybe installed). Both are also from Debugging Tools For Windows.

Download and install Debugging Tools for Windows

Install the Windows SDK but just choose the debugging tools.

Create a folder called Symbols in C:\

Start Windbg. File menu - Symbol File Path and enter



windbg -o -g -G c:\windows\system32\cmd.exe /k batfile.bat

You can press F12 to stop it and kb will show the call stack (g continues the program). If there's errors it will also stop and show them.

Type lm to list loaded modules, x *!* to list the symbols and bp symbolname to set a breakpoint

If programming in VB6 then this environmental variable link=/pdb:none stores the symbols in the dll rather than seperate files. Make sure you compile the program with No Optimisations and tick the box for Create Symbolic Debug Info. Both on the Compile tab in the Project's Properties.

Also CoClassSyms ( can make symbols from type libraries.

answered on Stack Overflow Sep 20, 2014 by Noodles

User contributions licensed under CC BY-SA 3.0