Like Tree1Likes
  • 1 Post By jps1x2

Creating Custom Simple Mapi DLL, throws error exception when executing

This is a discussion on Creating Custom Simple Mapi DLL, throws error exception when executing within the Windows Programming forums, part of the Platform Specific Boards category; Hi all, i am new here in forum. i am creating small dll to intercept simple mapi calls and send ...

  1. #1
    Registered User
    Join Date
    May 2013
    Posts
    2

    Question Creating Custom Simple Mapi DLL, throws error exception when executing

    Hi all,

    i am new here in forum.

    i am creating small dll to intercept simple mapi calls and send files via:

    file->Send to as attachment (in excel, word, acrobat reader...) or via explorer->rightclickmenu->Send to->Mail recipient

    to attach to gmail via imap-ssl to a draft.

    after reading this links about simple mapi and its registry configuration:

    Mapi32.dll Stub Registry Settings (Windows)
    Mapi32 Stub Library (Windows)

    and searching very much i did not found more information about this. There is information about creating clients for using simple mapi functions, but i did not found information about creating an stub library like has Affixa, thunderbird or other applications.

    Using Code::Blocks programmed a very simple dll and installed correctly on win registry like indicated in previos links on:

    HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail\SimpMapi

    I have selected on my win xp pro in control panel->Internet options my SimpMapi client for default mail client.

    when i open excel write some cells and go to File->Send like attachment dll interception works, showing me that first calls MapiLogon, second calls MapiSendMail and third when i close excel it calls MapiLogoff, but then it throws an error and closes excel.exe, suggesting typical send an error report to Microsoft.

    If i try it from explorer window right clicking one file and SendTo->Mail recipient it works, calling directly MapiSendMail and when i click on ok in MsgBox of dll, it throws an error and closes explorer.exe, suggesting typical send an error report to Microsoft.

    Could you help me to find out what is wrong?

    This is the main.h file:

    Code:
    #ifndef __MAIN_H__
    #define __MAIN_H__
    
    #include <windows.h>
    
    // All neeeded info copied from por mapi.h
    #define SUCCESS_SUCCESS            0
    #define MAPI_E_USER_ABORT        1
    #define MAPI_E_LOGIN_FAILURE    3
    
    typedef unsigned long FLAGS;
    typedef unsigned long LHANDLE;
    typedef unsigned long FAR *LPLHANDLE, FAR *LPULONG;
    
    typedef struct {
      ULONG ulReserved;
      ULONG ulRecipClass;
      LPSTR lpszName;
      LPSTR lpszAddress;
      ULONG ulEIDSize;
      LPVOID lpEntryID;
    } MapiRecipDesc, *lpMapiRecipDesc;
    
    typedef struct {
      ULONG ulReserved;
      ULONG flFlags;
      ULONG nPosition;
      LPSTR lpszPathName;
      LPSTR lpszFileName;
      LPVOID lpFileType;
    } MapiFileDesc, *lpMapiFileDesc;
    
    typedef struct {
      ULONG ulReserved;
      LPSTR lpszSubject;
      LPSTR lpszNoteText;
      LPSTR lpszMessageType;
      LPSTR lpszDateReceived;
      LPSTR lpszConversationID;
      FLAGS flFlags;
      lpMapiRecipDesc lpOriginator;
      ULONG nRecipCount;
      lpMapiRecipDesc lpRecips;
      ULONG nFileCount;
      lpMapiFileDesc lpFiles;
    } MapiMessage, *lpMapiMessage;
    
    #ifdef BUILD_DLL
        #define DLL_EXPORT __declspec(dllexport)
    #else
        #define DLL_EXPORT __declspec(dllimport)
    #endif
    
    extern "C" void DLL_EXPORT SomeFunction(const LPCSTR sometext);
    extern "C" ULONG DLL_EXPORT MAPILogon(ULONG_PTR ulUIParam,LPSTR lpszProfileName,LPSTR lpszPassword,FLAGS flFlags,ULONG ulReserved,LPLHANDLE lplhSession);
    extern "C" ULONG DLL_EXPORT MAPILogoff(LHANDLE lhSession,ULONG_PTR ulUIParam,FLAGS flFlags,ULONG ulReserved);
    extern "C" ULONG DLL_EXPORT MAPISendDocuments(ULONG_PTR ulUIParam,LPSTR lpszDelimChar,LPSTR lpszFilePaths,LPSTR lpszFileNames,ULONG ulReserved);
    extern "C" ULONG DLL_EXPORT MAPISendMail(LHANDLE lhSession,ULONG_PTR ulUIParam,lpMapiMessage lpMessage,FLAGS flFlags,ULONG ulReserved);
    
    #endif // __MAIN_H__
    And this is the main.cpp file:

    Code:
    #include "main.h"
    // a sample exported function
    void DLL_EXPORT SomeFunction(const LPCSTR sometext)
    {
        MessageBoxA(0, sometext, "DLL Message", MB_OK | MB_ICONINFORMATION);
    }
    ULONG DLL_EXPORT MAPILogon(ULONG_PTR ulUIParam,LPSTR lpszProfileName,LPSTR lpszPassword,FLAGS flFlags,ULONG ulReserved,LPLHANDLE lplhSession)
    {
        MessageBoxA(0, "MAPILogon", "Info", MB_OK | MB_ICONINFORMATION);
        return SUCCESS_SUCCESS;
    }
    ULONG DLL_EXPORT MAPILogoff(LHANDLE lhSession,ULONG_PTR ulUIParam,FLAGS flFlags,ULONG ulReserved)
    {
        MessageBoxA(0, "MAPILogoff", "Info", MB_OK | MB_ICONINFORMATION);
        return SUCCESS_SUCCESS;
    }
    ULONG DLL_EXPORT MAPISendDocuments(ULONG_PTR ulUIParam,LPSTR lpszDelimChar,LPSTR lpszFilePaths,LPSTR lpszFileNames,ULONG ulReserved)
    {
        MessageBoxA(0, "MAPISendDocuments", "Info", MB_OK | MB_ICONINFORMATION);
        return SUCCESS_SUCCESS;
    }
    ULONG DLL_EXPORT MAPISendMail(LHANDLE lhSession,ULONG_PTR ulUIParam,lpMapiMessage lpMessage,FLAGS flFlags,ULONG ulReserved)
    {
        MessageBoxA(0, "MAPISendMail", "Info", MB_OK | MB_ICONINFORMATION);
        return SUCCESS_SUCCESS;
    }
    
    extern "C" DLL_EXPORT BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
    {
        switch (fdwReason)
        {
            case DLL_PROCESS_ATTACH:
                // attach to process
                break;
            case DLL_PROCESS_DETACH:
                // detach from process
                break;
            case DLL_THREAD_ATTACH:
                // attach to thread
                break;
            case DLL_THREAD_DETACH:
                // detach from thread
                break;
        }
        return TRUE; // succesful
    }
    Installed Affixa software and investigated its mapi2xml.dll library and registry settings. Modifying registry settings and copying only this file i could use this mapi2xml.dll to do what i need but it is not legal.

    I would like to create one very small simple mapi dll to redirect to my own exe information about selected file to be sent by the user.

    Sorry about long post, but i need to explain it well.

    Thanks in advance

    Jorge

  2. #2
    Registered User
    Join Date
    May 2013
    Posts
    2
    Problem solved.

    Link: Creating Custom Simple Mapi DLL, throws - C++ Forum

    Andy helped me to solve the problem that was incorrect calling convention.
    Adding WINAPI to all my Simple MAPI function declarations and definitions it worked, example:

    Code:
    extern "C" ULONG DLL_EXPORT WINAPI MAPILogon( // etc


    Then the problem was that my exported functions were exported with declarations.

    To correct this in code::blocks you have to add in:
    Main menu: Project -> Build options -> GNU GCC Compiler -> Linker settings -> Other linker options:

    -Wl,--kill-at


    Thanks!
    Last edited by jps1x2; 05-26-2013 at 09:41 AM. Reason: CODE block bad formatted
    laserlight likes this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating a custom library
    By officedog in forum C Programming
    Replies: 3
    Last Post: 11-11-2008, 09:33 AM
  2. Creating a custom USB driver
    By bennyandthejets in forum Networking/Device Communication
    Replies: 2
    Last Post: 01-01-2004, 05:59 AM
  3. Creating Custom Controls
    By Grayson_Peddie in forum C# Programming
    Replies: 1
    Last Post: 12-29-2003, 12:41 PM
  4. Creating terminal windows and executing . . .
    By LinuxPLC in forum Game Programming
    Replies: 1
    Last Post: 02-19-2003, 12:18 PM
  5. Developing Custom Exception Handler :: C++
    By kuphryn in forum C++ Programming
    Replies: 4
    Last Post: 02-20-2002, 03:21 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21