Extended MAPI in C, not C++ or C#
-
I need to modify a few C applications that are about 10 years old and are currently using CMC to send and receive email from Exchange. I tried using Simple MAPI but am encountering the Outlook security prompts, so I am now looking at using Extended MAPI. I have found examples here using C++, but nothing written in C. Microsoft does not seem to offer much in the way of examples and rewriting the applications in C++ is not an option because there are several custom libraries that would also need to be converted. One of the applications is loaded on about 15,000 workstations, so a third party product or a loading a custom dll is not an option either. The only functionality I need is to be able to logon, logoff, send email and read email (in plain text). Any ideas ??
-
I need to modify a few C applications that are about 10 years old and are currently using CMC to send and receive email from Exchange. I tried using Simple MAPI but am encountering the Outlook security prompts, so I am now looking at using Extended MAPI. I have found examples here using C++, but nothing written in C. Microsoft does not seem to offer much in the way of examples and rewriting the applications in C++ is not an option because there are several custom libraries that would also need to be converted. One of the applications is loaded on about 15,000 workstations, so a third party product or a loading a custom dll is not an option either. The only functionality I need is to be able to logon, logoff, send email and read email (in plain text). Any ideas ??
This doesn't add up. You don't need to rewrite the whole application in C++. You should be able to interface the legacy C code with any C++ changes. Write a C interface to the C++ code:
// legacy C code
#include "NewCppAPI.h"
void legacy_Code()
{
// doing things with stable code
// call the new code
int iResult = NewCppAPI();
// check return code
}// NewCppAPI.h
#ifdef __cplusplus
extern "C" {
#endifint NewCppAPI();
#ifdef __cplusplus
}
#endif// NewCppAPI.cpp
#include "NewCppAPI.h"
int NewCppAPI()
{
int iResult = 0;// do the new stuff return iResult;
}
I have to guess that there must be some other constraints you are not mentioning.
-
This doesn't add up. You don't need to rewrite the whole application in C++. You should be able to interface the legacy C code with any C++ changes. Write a C interface to the C++ code:
// legacy C code
#include "NewCppAPI.h"
void legacy_Code()
{
// doing things with stable code
// call the new code
int iResult = NewCppAPI();
// check return code
}// NewCppAPI.h
#ifdef __cplusplus
extern "C" {
#endifint NewCppAPI();
#ifdef __cplusplus
}
#endif// NewCppAPI.cpp
#include "NewCppAPI.h"
int NewCppAPI()
{
int iResult = 0;// do the new stuff return iResult;
}
I have to guess that there must be some other constraints you are not mentioning.
further...I would anticipate that you might need to interface to the legacy C code from the C++ code. In the C++ code mark the legacy C headers as C code:
// legacycode.h
extern int stableAPI(int icount);
// NewCppAPI.cpp
extern "C" {
#include "legacycode.h"
}void CppFunction()
{
// do new things
std::vector <int> vNumbers;
vNumbers.push(1);
vNumbers.push(2);
vNumbers.push(3);// call the stable code int iResult = stableAPI(vNumbers.size());
}
When you have to pass information to the legacy code, it can only pass C types; don't pass pointers to C++ types. Be sure you know who owns what memory. A simple solution is to write copy API's in the C++ code that are called by the legacy C code in the same way that windows API's do. You pass in a pointer to a buffer with a pointer to a length that is the size of the buffer. If the buffer is too small the function returns an error and set the length to the size needed:
int CopyCppData(char * pszBuffer, int * ilength);