Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I would apreciate if you could help

Status
Not open for further replies.

akpr1

Technical User
Nov 12, 2003
2
US

Hi
I am developing a component [dynamic link library] using eVC++4.0. The main objective for this component is costomizing the PocketOutlook. After that I am using this componennt in eVB / C#.

for developing the components

First I created a eVC++ 4.0 project
project->WCE Dynamic-Link Library->A DLL that exports some symbols.
project is created with 3 files as follows
(a) PocketOutlookObject.h - Interface for PocketOutlookObject class
(b) PocketOutlookObject.cpp - Implementation for PocketOutlookObject class
(c) PocketOutlookObject.def - exporting the functions

right now in this class has only one function called ComposeMessage. I should be able to call this function from eVB/eVC++

after the implementation of this calss. I created another calss called clsPocketOutlook.
a clsPocketMapi.h - Interface for clsPocketMapi class
b clsPocketMapi.cpp - Implementation for clsPocketMapi class

This is the main class for customizing the pocketoutlook. In this class I have Implemented the necessary interface for cemapi. In this a function called SendMessage. Basically this will push the composed message to OUTBOX.
Now when I called this API function from vb.net, it always return false.

I would apreciate if you could help me to solve this problem



**************************************************
*****************
PocketOutlookObject.h interface Files
**************************************************
*****************

// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the POCKETOUTLOOKOBJECT_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// POCKETOUTLOOKOBJECT_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#ifdef POCKETOUTLOOKOBJECT_EXPORTS
#define POCKETOUTLOOKOBJECT_API __declspec(dllexport)
#else
#define POCKETOUTLOOKOBJECT_API __declspec(dllimport)
#endif


#include "resource.h" // main symbols
#include "clsPocketMapi.h" // Added by ClassView


// This class is exported from the PocketOutlookObject.dll
class POCKETOUTLOOKOBJECT_API CPocketOutlookObject {
public:
CPocketOutlookObject(void);
// TODO: add your methods here.


};

extern POCKETOUTLOOKOBJECT_API int nPocketOutlookObject;

POCKETOUTLOOKOBJECT_API int fnPocketOutlookObject(void);

**************************************************
******************************************
PocketOutlookObject.cpp: implementation of the PocketOutlookObject class.

**************************************************
******************************************
// PocketOutlookObject.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include "PocketOutlookObject.h"
#include "Aclass.h"
#include "clsTest.h"

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}


// This is an example of an exported variable
POCKETOUTLOOKOBJECT_API int nPocketOutlookObject=0;

// This is an example of an exported function.
POCKETOUTLOOKOBJECT_API int fnPocketOutlookObject(void)
{
return 42;
}

// This is the constructor of a class that has been exported.
// see PocketOutlookObject.h for the class definition
CPocketOutlookObject::CPocketOutlookObject()
{
return;
}

POCKETOUTLOOKOBJECT_API BOOL ComposeMessage(LPCTSTR pcszTo, LPCTSTR pcszSubject, LPCTSTR pcszBody)
{

HRESULT hr;
clsPocketMapi m_MAPI;


hr = m_MAPI.SendMessage(pcszTo, pcszSubject,pcszBody);

if(FAILED(hr))
return(FALSE);
else
return(TRUE);

PostQuitMessage(0);

}

**************************************************
**************************
POCKETOUTLOOKOBJECT.def :
**************************************************
**************************
LIBRARY POCKETOUTLOOKOBJECT

EXPORTS
DllMain
SendMessage



2 . I created a class called clsPocketMapi. in this class the necessary Interface has been implemented.

**************************************************
*********************************
clsPocketMapi.cpp : implementation of the clsPocketMapi class.

**************************************************
*********************************
// clsPocketMapi.cpp: implementation of the clsPocketMapi class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "clsPocketMapi.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//CVOMAPIGlobal clsPocketMapi::g_MAPI;

#define EXIT_ON_FAILED(_hr) \
if (FAILED(_hr)) \
{ \
RETAILMSG(1, (_T("CEMAPI: FAILED(%x) at %hs:%d\n"), \
_hr, __FILE__, __LINE__)); \
goto FuncExit; \
}

#ifndef RELEASE_OBJ
#define RELEASE_OBJ(s) \
if (s != NULL) \
{ \
s->Release(); \
s = NULL; \
}
#endif //RELEASE_OBJ

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
/*
clsPocketMapiGlobal::clsPocketMapiGlobal()
{
if(FAILED(m_hr = CoInitializeEx(NULL, COINIT_MULTITHREADED)))
return;

m_hr = MAPIInitialize(NULL);
}

clsPocketMapiGlobal::~clsPocketMapiGlobal()
{
MAPIUninitialize();

CoUninitialize();
}
*/
clsPocketMapi::clsPocketMapi() :
m_fInitialized(FALSE),
m_pSession(NULL),
m_pAddressBook(NULL),
m_pMsgStoresTable(NULL),
m_pMsgStore(NULL),
m_pMessage(NULL),
m_pOutBoxFolder(NULL)
{
}

clsPocketMapi::~clsPocketMapi()
{
RELEASE_OBJ(m_pOutBoxFolder);
RELEASE_OBJ(m_pMessage);
RELEASE_OBJ(m_pMsgStore);
RELEASE_OBJ(m_pMsgStoresTable);
RELEASE_OBJ(m_pAddressBook);
RELEASE_OBJ(m_pSession);
}

HRESULT clsPocketMapi::Logon(LPCTSTR pcszProfileName, LPCTSTR pcszPassword, FLAGS flags, HWND hwndParent)
{
HRESULT hr;

hr = MAPILogonEx((ULONG)hwndParent, (LPTSTR)pcszProfileName, (LPTSTR)pcszPassword, flags, &m_pSession);
EXIT_ON_FAILED(hr);

hr = m_pSession->OpenAddressBook(0, NULL, AB_NO_DIALOG, &m_pAddressBook);
// EXIT_ON_FAILED(hr); // As of 10/06/2001 the IAddressBook interface was not implemented in Pocket PC 2002 MAPI.

hr = m_pSession->GetMsgStoresTable(0, &m_pMsgStoresTable);
EXIT_ON_FAILED(hr);

m_fInitialized = TRUE;

FuncExit:
RELEASE_OBJ(m_pOutBoxFolder);
return hr;
}

HRESULT clsPocketMapi::SendMessage(LPCTSTR pcszTo, LPCTSTR pcszSubject, LPCTSTR pcszBody)
{
HRESULT hr;

if(!IsInitialized())
EXIT_ON_FAILED(hr = E_FAIL);

if((pcszTo == NULL) || (pcszSubject == NULL) || (pcszBody == NULL))
EXIT_ON_FAILED(hr = E_INVALIDARG);

hr = GetOutBoxFolder();
EXIT_ON_FAILED(hr);

hr = m_pOutBoxFolder->CreateMessage(NULL, 0, &m_pMessage);
EXIT_ON_FAILED(hr);

hr = SetRecipients(pcszTo);
EXIT_ON_FAILED(hr);

hr = SetProperties(pcszSubject, pcszBody);
EXIT_ON_FAILED(hr);

hr = m_pMessage->SubmitMessage(0);

FuncExit:
RELEASE_OBJ(m_pMessage);
return hr;
}
**************************************************
**************************************************
********
clsPocketMapi.h: interface for the clsPocketMapi class.
**************************************************
**************************************************
********

#if !defined(AFX_CLSPOCKETMAPI_H__E851E9AE_604B_4422_8
C97_547C98582A15__INCLUDED_)
#define AFX_CLSPOCKETMAPI_H__E851E9AE_604B_4422_8C97_547C9
8582A15__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "cemapi.h"

/*
class CVOMAPIGlobal
{
public:
CVOMAPIGlobal();
~CVOMAPIGlobal();

public:
HRESULT m_hr;
};

*/

class clsPocketMapi
{
public:
HRESULT SetMessageStore(LPCTSTR pcszName);
HRESULT SendMessage(LPCTSTR pcszTo, LPCTSTR pcszSubject, LPCTSTR pcszBody);
clsPocketMapi();
virtual ~clsPocketMapi();

HRESULT Logon(LPCTSTR pcszProfileName = NULL, LPCTSTR pcszPassword = NULL, FLAGS flags = 0, HWND hwndParent = 0);
BOOL IsInitialized() { return m_fInitialized; }
void Test(int* j);

protected:
HRESULT SetProperties(LPCTSTR pcszSubject, LPCTSTR pcszBody);
HRESULT SetRecipients(LPCTSTR pcszTo);
HRESULT GetOutBoxFolder();
// static CVOMAPIGlobal g_MAPI;

BOOL m_fInitialized;

// Interface Pointers
IMAPISession* m_pSession;
IMAPITable* m_pMsgStoresTable;
LPMDB m_pMsgStore;
LPMESSAGE m_pMessage;
LPMAPIFOLDER m_pOutBoxFolder;
LPADRBOOK m_pAddressBook;


};
#endif // !defined(AFX_CLSPOCKETMAPI_H__E851E9AE_604B_4422_8
C97_547C98582A15__INCLUDED_)



**************************************************
********************************
Calling from vb.net
**************************************************
***********************************
sub Compose()
Dim sTO As String
Dim sSubject As String
Dim SBody As Integer

sTO = "akpr@yahoo.com"
sSubject = "test message"
sBody = "This is a test message"

MsgBox("About to call")
MsgBox(ComposeMessage(sTO,sSubject,sBody))
end sub

 
Sorry that i forogot to include one more function

HRESULT clsPocketMapi::GetOutBoxFolder()
{
if(m_pOutBoxFolder)
return S_OK;

HRESULT hr;
LPSPropValue rgprops = NULL;
ULONG cValues = 0;
ULONG rgTags[] = { 1, PR_CE_IPM_DRAFTS_ENTRYID };

if(m_pMsgStore == NULL)
{
// Get the default message store (ActiveSync)
hr = m_pSession->OpenMsgStore(NULL, 0, NULL, NULL, 0, &m_pMsgStore);
EXIT_ON_FAILED(hr);
}

// Now get the Drafts folder.
hr = m_pMsgStore->GetProps((LPSPropTagArray) rgTags, MAPI_UNICODE, &cValues, &rgprops);
EXIT_ON_FAILED(hr);

if(rgprops[0].ulPropTag != PR_CE_IPM_DRAFTS_ENTRYID)
EXIT_ON_FAILED(hr = E_FAIL);

hr = m_pMsgStore->OpenEntry(rgprops[0].Value.bin.cb,
(LPENTRYID)rgprops[0].Value.bin.lpb, NULL, MAPI_MODIFY,
NULL, (LPUNKNOWN*)&m_pOutBoxFolder);
EXIT_ON_FAILED(hr);

MAPIFreeBuffer(rgprops);
return (HRESULT) 0;

FuncExit:
RELEASE_OBJ(m_pOutBoxFolder);
MAPIFreeBuffer(rgprops);
return hr;
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top