Click here to Skip to main content
15,888,108 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to call from a thread to a pointer.
Here is my code:

myDll.dll c++ :
C++
long cbAddrAsync;
void _asyncer(void* data)
{
        typedef void (__stdcall *FUNCPTR)();
    FUNCPTR vbFunc;
    vbFunc = (FUNCPTR)cbAddrAsync;
    vbFunc();
}
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:
VB
Declare Sub async Lib "myDll.dll" (ByVal addr As Long)
Sub onAsync()
MsgBox "ASYNC"
End Sub

In Form1:

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


when i click at command button , The problem occurs in dll:
Unhandled exception at 0x734f9232 in Project1.exe: 0xC0000005: Access violation reading location 0x00000076.
in vbFunc();

How can I fix it?
Thanks.
Posted

1 solution

your problem is that you start a new thread which accesses the existing UI-Thread. Only change data with another thread and signal it another way to the GUI.

I am not so fit in sync in vb.net but some Thread Synchronization should resolve that.

Please provide your solution in a comment.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900