The wonderful world of MAPI [modified]
-
Ok so I'll start by declaring my undying love for C# :P it's my primary language and I try to stick to the managed world where ever possible. This time though I need to use some stuff where pInvoke just wont cut it so I'm using my lacking and very dodgy C++/Cli skills :P so please forgive me if I say anything stupid ;) I'm currently working with this MAPI function: OpenIMsgOnIStg[^] Due to the wonderful fact that it requires Memory Management Functions to be passed to it: lpAllocateBuffer [in] Pointer to the MAPIAllocateBuffer function, to be used where required by MAPI to allocate memory. lpAllocateMore [in] Pointer to the MAPIAllocateMore function, to be used where required by MAPI to allocate additional memory. lpFreeBuffer [in] Pointer to the MAPIFreeBuffer function, to be used where required by MAPI to free memory. I'm not even going to go near it with pInvoke. I've translated this article: INFO: Save Message to MSG Compound File[^] into a standalone native method and I'm now trying to put together the C++/Cli code to act as the go between. The biggest problem I'm currently facing is trying to convert a System::Object into a LPMESSAGE. None of the casts seem to want to work and I'm not sure of the next direction to try :S does anyone have any suggestions on how to cast/convert? -- modified at 6:23 Wednesday 11th July, 2007 EDIT: Realised I hadn't acctually asked a question :doh:
-
Ok so I'll start by declaring my undying love for C# :P it's my primary language and I try to stick to the managed world where ever possible. This time though I need to use some stuff where pInvoke just wont cut it so I'm using my lacking and very dodgy C++/Cli skills :P so please forgive me if I say anything stupid ;) I'm currently working with this MAPI function: OpenIMsgOnIStg[^] Due to the wonderful fact that it requires Memory Management Functions to be passed to it: lpAllocateBuffer [in] Pointer to the MAPIAllocateBuffer function, to be used where required by MAPI to allocate memory. lpAllocateMore [in] Pointer to the MAPIAllocateMore function, to be used where required by MAPI to allocate additional memory. lpFreeBuffer [in] Pointer to the MAPIFreeBuffer function, to be used where required by MAPI to free memory. I'm not even going to go near it with pInvoke. I've translated this article: INFO: Save Message to MSG Compound File[^] into a standalone native method and I'm now trying to put together the C++/Cli code to act as the go between. The biggest problem I'm currently facing is trying to convert a System::Object into a LPMESSAGE. None of the casts seem to want to work and I'm not sure of the next direction to try :S does anyone have any suggestions on how to cast/convert? -- modified at 6:23 Wednesday 11th July, 2007 EDIT: Realised I hadn't acctually asked a question :doh:
Well I'm not sure if this is the cleanest way of doing it but it works :D System::IntPtr ipMsg = System::Runtime::InteropServices::Marshal::GetIUnknownForObject(iMessage); LPMESSAGE iMessageToSave = (LPMESSAGE)(ipMsg.ToPointer()); Obviously it was the right underlying native type otherwise the way I use it later would have bombed. I'm quite chuffed with how relativly easy and painless this was :)