0

I am creating default mail application like thunderbird and outlook but with some of the features only. So now problem is only with the word 2007 and excel 2007 while sending file from fileMenu -> send -> E-mail and application gets crashed after clicking on E-mail, but same thing is working in Powerpoint 2007 and one note 2007.

With office 2007, MapiLogon(...) is getting first call and here is my MAPILogOn(...),

// I have used ofstream for the log purpose.
#include <MAPIX.h>

extern "C" ULONG MAPILogon(ULONG_PTR ulUIParam, LPSTR lpszProfileName, LPSTR lpszPassword, FLAGS flFlags, ULONG ulReserved, LPLHANDLE lplhSession)
{
    ofstream outfile;
    outfile.open("e:\\temp\\MAPILogon.txt");

    HRESULT hrs = NULL;

    MAPIINIT_0  MAPIINIT = { MAPI_INIT_VERSION, MAPI_NO_COINIT };
    hrs = MAPIInitialize(NULL);
    lplhSession = nullptr;
    if (hrs != S_OK)
    {
        outfile << "\n MAPI uniititalized";
    }
    else
    {
        outfile << "\n MAPI initialized";

        LPMAPISESSION FAR spSession = NULL;
        outfile << "\n lplhsession - " << spSession;
        hrs = MAPILogonEx(NULL, "Outlook", NULL, MAPI_EXTENDED | MAPI_NEW_SESSION, &spSession);
        if (hrs == NULL)
        {
            outfile << "\n MAPI problem while log in." << spSession;
        }
        else if (hrs == S_OK)
        {
            outfile << "\n MAPI log in successful.";
            return SUCCESS_SUCCESS;
        }

        outfile << "\n Last Error - " << GetLastError();
    }
    return MAPI_E_FAILURE;
}

Here, I am able to initialize MAPI successfully, but MAPILogOnEx(...) returns null, so are there any other things that are required here?

GetLastError() gives 0. "Outlook" is the default profile.

I have looked all the tutorials of stackoverflow and Microsoft but unable to get solution.

Ujjaval Moradiya
  • 222
  • 1
  • 12

2 Answers2

0

MAPILogonEx returns HRESULT, not a pointer. The lines if (hrs == NULL) and if (hrs == S_OK) are the same since NULL is converted to 0 by the compiler. S_OK is also 0.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
0

I changed function definition to this - And with the following solution I don't need the MAPIInitialize and MAPILogOnEx.

#define WINAPI      __stdcall
#define SUCCESS_SUCCESS         0

extern "C" ULONG WINAPI MAPILogon(ULONG_PTR ulUIParam, LPSTR lpszProfileName, LPSTR lpszPassword, FLAGS flFlags, ULONG ulReserved, LPLHANDLE lplhSession)
{
    return Success_Success;
}

I added .def file with the following lines -

; file_name.def
LIBRARY file_name
EXPORTS
    MAPILogoff
    MAPILogon
    MAPISendDocuments
    MAPISendMail
    MAPISendMailW

This are the only functions I needed. So office 2007 is calling decorated names of this functions and without this, office 2007 is unable to find functions so without giving a message, office 2007 apps are crashing. Now it is working. Now I have to test the same code with all the office versions and all os. Let's hope it work.

Ujjaval Moradiya
  • 222
  • 1
  • 12