Platform SDK: Exchange 2000 Server

Using CDO and MAPI in the Same Modules

[This is preliminary documentation and subject to change.]

The C programming language does not support a namespace mechanism. As such, all linkage symbols for a particular executable or dynamic link library must be unique or the linker will raise an error at link time. As such, you must be diligent in making sure that type names used in various headers are not the same, and if they are, you must perform a little compiler magic to make things work.

One such name class will occur if you attempt to write a C program that uses both MAPI and CDO for Exchange 2000 Server. The MAPI header file mapidefs.h contains a definition for an interface called IMessage and so does the CDO for Exchange header file cdoex.h. Of course, the MAPI IMessage interface is quite different than the definition for CDO. If you need to write C code that uses both MAPI and CDO for Exchange in the same module, you will need to re-map names something like the following:

#define IMessage ICDOMessage 
#define IMessageVtbl ICDOMessageVtbl 
#define IID_IMessage IID_ICDOMessage 
#include "cdoex.h" 
#include "cdoex_i.c" 

#undef IID_IMessage 
#undef IMessageVtbl 
#undef IMessage 

#include "mapidefs.h" 
#include "mapiguid.h" 

Then, when referring to the CDO IMessage interface, you must refer to it as ICDOMessage, and refer to its IID as IID_ICDOMessage:

#pragma comment(lib,"uuid.lib")
#pragma comment(lib,"ole32.lib")
#pragma comment(lib,"oleaut32.lib")

int main() {

  MAPIInitialize(...);

 ICDOMessage* pMsg = NULL;
 HRESULT hr = CoCreateInstance(
     CLSID_Message,
     NULL,
     CLSCTX_INPROC_SERVER,
     IID_ICDOMessage,
     (void**)&pMsg
     );

 MAPILogonEx(...); // for brevity
 // ...
 MAPIUninitialize();
}