Andy_Sponik
asked on
integrating outlook in C++
Hello everybody,
I'm trying to make a dll that I'm going to call from Java. The dll is supposed to fetch the outlook contacts and export them to java.
my cpp-program looks a bit like this:
#import<mso.dll> no_namespace rename("DocumentProperties ", "DocumentPropertiesVM")
#import<VBE6EXT.olb> no_namespace
#import <msoutl.olb> rename("ExitWindows","Exit WindowsVM" )
#include<tchar.h> //for strings
#include<jni.h> //java native interface
#include<myclass.h> //simply my class
even tried these imports in another version ...
#import "c:\Program Files\Common Files\Microsoft Shared\Office11\mso.dll" named_guids
#import "c:\Program Files\Microsoft Office\Office11\MSOUTL.OLB " \
no_namespace exclude("_IRecipientContro l", "_DRecipientControl")
...
JNIEXPORT void JNICALL Java_myclass_relaunch (JNIEnv *env, jobject obj)
{
//here the implementation of the code....
}
now my problem is... I can't seem to make a connection with outlook..
if I use ... _ApplicationPtr pApplic ... as a declaration of outlook (something I've found on the net)
it won't work.
Does anyone know how to make this connection work? And maybe if I could use a namespace, other imports ... I thought I've read something about MAPI....
thx, Andy
I'm trying to make a dll that I'm going to call from Java. The dll is supposed to fetch the outlook contacts and export them to java.
my cpp-program looks a bit like this:
#import<mso.dll> no_namespace rename("DocumentProperties
#import<VBE6EXT.olb> no_namespace
#import <msoutl.olb> rename("ExitWindows","Exit
#include<tchar.h> //for strings
#include<jni.h> //java native interface
#include<myclass.h> //simply my class
even tried these imports in another version ...
#import "c:\Program Files\Common Files\Microsoft Shared\Office11\mso.dll" named_guids
#import "c:\Program Files\Microsoft Office\Office11\MSOUTL.OLB
no_namespace exclude("_IRecipientContro
...
JNIEXPORT void JNICALL Java_myclass_relaunch (JNIEnv *env, jobject obj)
{
//here the implementation of the code....
}
now my problem is... I can't seem to make a connection with outlook..
if I use ... _ApplicationPtr pApplic ... as a declaration of outlook (something I've found on the net)
it won't work.
Does anyone know how to make this connection work? And maybe if I could use a namespace, other imports ... I thought I've read something about MAPI....
thx, Andy
Post some more code of what you to try and start/open outlook in your C++ dll
ASKER
ok,
JNIEXPORT jstring JNICALL Java_myclass_launch (JNIEnv *env, jobject obj, jstring txt)
{
_ApplicationPtr pApp;
_ItemsPtr pItems;
MAPIFolderPtr pFolder;
_ContactItemPtr pContact;
HRESULT hr;
printf("In contacts\n");
try
{
hr=pApp.CreateInstance(__u uidof(Appl ication));
if (FAILED(hr))
{
printf("Unable to instantiate Outlook.");
return env->NewStringUTF("0");
}
pFolder=pApp->GetNamespace (_bstr_t(" MAPI"))->G etDefaultF older(olFo lderContac ts);
if (pFolder==NULL)
{
printf("Could not find default contacts folder.");
return env->NewStringUTF("1");
}
pItems=pFolder->GetItems() ;
if (pItems==NULL)
{
printf("Unable to get Contact Items.");
return env->NewStringUTF("2");
}
pContact=pItems->GetFirst( );
while(1)
{
if (pContact==NULL)
break;
CString strTemp;
strTemp=(char *)pContact->GetFullName();
strTemp=strTemp + "<";
strTemp=strTemp + (char *)pContact->GetEmail1Addre ss();
strTemp=strTemp + ">";
printf(strTemp);
return env->NewStringUTF(strTemp) ;
pContact=pItems->GetNext() ;
}
}
catch(_com_error &e)
{
printf((char *)e.Description());
return env->NewStringUTF(e.Descri ption());
}
return env->NewStringUTF("Hier is wat misgegaan");
}
when I execute my java class, I get following output:
In outlook
Unable to instantiate Outlook
Thx
JNIEXPORT jstring JNICALL Java_myclass_launch (JNIEnv *env, jobject obj, jstring txt)
{
_ApplicationPtr pApp;
_ItemsPtr pItems;
MAPIFolderPtr pFolder;
_ContactItemPtr pContact;
HRESULT hr;
printf("In contacts\n");
try
{
hr=pApp.CreateInstance(__u
if (FAILED(hr))
{
printf("Unable to instantiate Outlook.");
return env->NewStringUTF("0");
}
pFolder=pApp->GetNamespace
if (pFolder==NULL)
{
printf("Could not find default contacts folder.");
return env->NewStringUTF("1");
}
pItems=pFolder->GetItems()
if (pItems==NULL)
{
printf("Unable to get Contact Items.");
return env->NewStringUTF("2");
}
pContact=pItems->GetFirst(
while(1)
{
if (pContact==NULL)
break;
CString strTemp;
strTemp=(char *)pContact->GetFullName();
strTemp=strTemp + "<";
strTemp=strTemp + (char *)pContact->GetEmail1Addre
strTemp=strTemp + ">";
printf(strTemp);
return env->NewStringUTF(strTemp)
pContact=pItems->GetNext()
}
}
catch(_com_error &e)
{
printf((char *)e.Description());
return env->NewStringUTF(e.Descri
}
return env->NewStringUTF("Hier is wat misgegaan");
}
when I execute my java class, I get following output:
In outlook
Unable to instantiate Outlook
Thx
hr=pApp.CreateInstance(__u uidof(Appl ication));
should that not be Outlook - what is Application?
should that not be Outlook - what is Application?
ASKER
well, I've tried all kinds of things there:
When using "Outlook" or "Outlook::Application", I get compilation errors... I've found a working example on the internet which uses Application, makes no sense to me, but it worked ... Guess Application references to Outlook in the imported dll mso.dll.
When I try to work with msWord, I can use the namespace Word, but I can't find any for Outlook
When using "Outlook" or "Outlook::Application", I get compilation errors... I've found a working example on the internet which uses Application, makes no sense to me, but it worked ... Guess Application references to Outlook in the imported dll mso.dll.
When I try to work with msWord, I can use the namespace Word, but I can't find any for Outlook
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.