A
Andy Sponik
Hi everyone,
I'm trying to make a dll that fetches my contacts from outlook 2003...
but whatever I try I don't seem to find a way to instantiate outlook..
the following code is code that works in a executable, so the code
must be correct ?
JNIEXPORT jstring JNICALL Java_myclass_launch (JNIEnv * env, jobject
obj)
{
printf("in c- test\n");
CString test = "jklj\n";
//return env->NewStringUTF(test);
_ApplicationPtr pApp;
_ItemsPtr pItems;
MAPIFolderPtr pFolder;
_ContactItemPtr pContact;
HRESULT hr;
try
{
printf("test");
hr=pApp.CreateInstance(__uuidof(Application));
// similar to:hr = pApp.CreateInstance("Outlook.Application");
if (FAILED(hr))
{
MessageBox(NULL,"Unable to instantiate Outlook.","Outlook
Error",MB_OK);
return env->NewStringUTF("instantiate failure");
printf("test");
}
//if (m_Option.GetCheck()) //default outlook contacts folder
//{
pFolder=pApp->GetNamespace(_bstr_t("MAPI"))->GetDefaultFolder(olFolderContacts);
if (pFolder==NULL)
{
MessageBox(NULL,"Could not find default contacts folder.","Outlook
Error", MB_OK);
return env->NewStringUTF("folder not found");
}
//}
/*else //display folder selection window
{
pFolder=pApp->GetNamespace(_bstr_t("MAPI"))->PickFolder();
if (pFolder==NULL)
return;
if (pFolder->GetDefaultItemType()!=olContactItem)
{
MessageBox(NULL,"Select folder is not a Contact folder.","Outlook
Contacts",MB_OK);
return;
}
}*/
pItems=pFolder->GetItems();
if (pItems==NULL)
{
MessageBox(NULL,"Unabel to get Contact Items.","Outlook
Error",MB_OK);
return env->NewStringUTF("no contacts");
}
pContact=pItems->GetFirst();
// m_ContactList.ResetContent();
while(1)
{
if (pContact==NULL)
break;
CString strTemp;
strTemp=(char *)pContact->GetFullName();
strTemp=strTemp + "<";
strTemp=strTemp + (char *)pContact->GetEmail1Address();
strTemp=strTemp + ">";
//m_ContactList.AddString(strTemp);
CString strTemp2;
//strTemp2 = (char *)pContact->GetJobTitle();
//strTemp2 = (char *)pContact->GetHomeAddressCountry();
//strTemp2 = strTemp2 + "-" && (char
*)pContact->GetHomeAddressCountry();
//MessageBox(strTemp2, "jobTitel", MB_OK);
//MessageBox(strTemp,"titel", MB_OK);
pContact=pItems->GetNext();
}
}
catch(_com_error &e)
{
MessageBox(NULL, (char *)e.Description(),"titel", MB_OK);
}
return env->NewStringUTF("eind");
}
so it always fails ...
the purpose of this dll is that i call it (the dll) from java (working
with JNI) en returning some of the properties of a contactitem ...
Is there anything special about dll's that i haven't considered.
which dll is best to use?
a regular DLL with mfc statically linked
a regular dll using shared mfc dll
a mfc extension dll
if i'm correct it's a dll with automation right.
I know this is a big question, but I'm not really that familiar with
VC++. But there is no way to connect with outlook via java, right?
thx
Andy
I'm trying to make a dll that fetches my contacts from outlook 2003...
but whatever I try I don't seem to find a way to instantiate outlook..
the following code is code that works in a executable, so the code
must be correct ?
JNIEXPORT jstring JNICALL Java_myclass_launch (JNIEnv * env, jobject
obj)
{
printf("in c- test\n");
CString test = "jklj\n";
//return env->NewStringUTF(test);
_ApplicationPtr pApp;
_ItemsPtr pItems;
MAPIFolderPtr pFolder;
_ContactItemPtr pContact;
HRESULT hr;
try
{
printf("test");
hr=pApp.CreateInstance(__uuidof(Application));
// similar to:hr = pApp.CreateInstance("Outlook.Application");
if (FAILED(hr))
{
MessageBox(NULL,"Unable to instantiate Outlook.","Outlook
Error",MB_OK);
return env->NewStringUTF("instantiate failure");
printf("test");
}
//if (m_Option.GetCheck()) //default outlook contacts folder
//{
pFolder=pApp->GetNamespace(_bstr_t("MAPI"))->GetDefaultFolder(olFolderContacts);
if (pFolder==NULL)
{
MessageBox(NULL,"Could not find default contacts folder.","Outlook
Error", MB_OK);
return env->NewStringUTF("folder not found");
}
//}
/*else //display folder selection window
{
pFolder=pApp->GetNamespace(_bstr_t("MAPI"))->PickFolder();
if (pFolder==NULL)
return;
if (pFolder->GetDefaultItemType()!=olContactItem)
{
MessageBox(NULL,"Select folder is not a Contact folder.","Outlook
Contacts",MB_OK);
return;
}
}*/
pItems=pFolder->GetItems();
if (pItems==NULL)
{
MessageBox(NULL,"Unabel to get Contact Items.","Outlook
Error",MB_OK);
return env->NewStringUTF("no contacts");
}
pContact=pItems->GetFirst();
// m_ContactList.ResetContent();
while(1)
{
if (pContact==NULL)
break;
CString strTemp;
strTemp=(char *)pContact->GetFullName();
strTemp=strTemp + "<";
strTemp=strTemp + (char *)pContact->GetEmail1Address();
strTemp=strTemp + ">";
//m_ContactList.AddString(strTemp);
CString strTemp2;
//strTemp2 = (char *)pContact->GetJobTitle();
//strTemp2 = (char *)pContact->GetHomeAddressCountry();
//strTemp2 = strTemp2 + "-" && (char
*)pContact->GetHomeAddressCountry();
//MessageBox(strTemp2, "jobTitel", MB_OK);
//MessageBox(strTemp,"titel", MB_OK);
pContact=pItems->GetNext();
}
}
catch(_com_error &e)
{
MessageBox(NULL, (char *)e.Description(),"titel", MB_OK);
}
return env->NewStringUTF("eind");
}
so it always fails ...
the purpose of this dll is that i call it (the dll) from java (working
with JNI) en returning some of the properties of a contactitem ...
Is there anything special about dll's that i haven't considered.
which dll is best to use?
a regular DLL with mfc statically linked
a regular dll using shared mfc dll
a mfc extension dll
if i'm correct it's a dll with automation right.
I know this is a big question, but I'm not really that familiar with
VC++. But there is no way to connect with outlook via java, right?
thx
Andy