The wonderful world of MAPI Part II.
-
So after much jubulation and sacrifices to the gods of managed/native code I continued on with my Outlook Addin. The native code I have is working fine untill I introduce a thread to take the workload away from the GUI thread. Now the exact same code is throwing: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Once I have created the thread I grab a list of the items I'm interested in from Outlook (which is the main thread). I then take each of these managed object and retrive the native object (still reprisented as a System.Object) and pass them over to my C++/Cli. In the managed C++/Cli I use System::Runtime::InteropServices::Marshal::GetIUnknownForObject(iMessage); to retrive and IntPtr and then LPMESSAGE iMessageToSave = (LPMESSAGE)(ipMsg.ToPointer()); to convert it into a native object. The native object is passed to the native C++ method which dies as soon as I try to pIMessageToSave->CopyTo(), where pIMessageToSave is the same native object. As I said ... it works fine without threading but dies with it :S Any suggestions?