My WPF appl need to call methods in a COM object (VC++) to do some work. It works perfectly when I call those methods from the UI thread. As those calls take a very long time to finish, so I decided to move the interaction with COM to a BackgroundWorker.
But I got an exception in one COM methods (Other methods still working fine). The error reads:
Unhandled exception at 0x62a7be37 (msvcr100d.dll) in TestApp.exe: 0xC0000005: Access violation writing location 0x0ab0f000.
The signature of the COM method is:
STDMETHODIMP CMyCOM::GetBytes(BSTR key, BYTE *pData)
DWORD size = some func get the size;
BYTE* pSrcData = the src data address;
memcpy((void*) pData, pSrcData, size); //Error occured on this line
How the C# calls the method:
View Complete Post