Platform SDK: CDO for Windows 2000

Using CDO and MAPI in the Same Modules

The C programming language does not support a namespace mechanism. All linkage symbols for a particular executable or dynamic link library must be unique or the linker will raise an error at link time. Make sure that type names used in various headers are not the same.

One such name class will occur if you attempt to write a C program that uses both MAPI and CDO for Windows 2000. The MAPI header file mapidefs.h contains a definition for an interface called IMessage as does the CDO for Windows 2000 header file cdosys.h. Note that the MAPI IMessage interface is different from the definition for CDO. If you need to write C code that uses both MAPI and CDO for Windows 2000 in the same module, you will need to re-map names as shown in the following example:

#define IMessage ICDOMessage 
#define IMessageVtbl ICDOMessageVtbl 
#define IID_IMessage IID_ICDOMessage 
#include "cdosys.h" 
#include "cdosys_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();
}