Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Extended MAPI in C, not C++ or C#

Extended MAPI in C, not C++ or C#

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++securityquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    panther82
    wrote on last edited by
    #1

    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 ??

    M 1 Reply Last reply
    0
    • P panther82

      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 ??

      M Offline
      M Offline
      Member 754960
      wrote on last edited by
      #2

      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" {
      #endif

      int 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.

      M 1 Reply Last reply
      0
      • M Member 754960

        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" {
        #endif

        int 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.

        M Offline
        M Offline
        Member 754960
        wrote on last edited by
        #3

        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);

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups