Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

integrating outlook in C++

Posted on 2004-04-26
7
263 Views
Last Modified: 2013-11-20
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","ExitWindowsVM")
#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("_IRecipientControl", "_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
0
Comment
Question by:Andy_Sponik
  • 3
  • 2
7 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 10919049
Post some more code of what you to try and start/open outlook in your C++ dll
0
 

Author Comment

by:Andy_Sponik
ID: 10926480
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(__uuidof(Application));
            if (FAILED(hr))
            {
                  printf("Unable to instantiate Outlook.");
                  return env->NewStringUTF("0");
            }

            pFolder=pApp->GetNamespace(_bstr_t("MAPI"))->GetDefaultFolder(olFolderContacts);
            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->GetEmail1Address();
                  strTemp=strTemp + ">";
                  printf(strTemp);
                  return env->NewStringUTF(strTemp);
                  pContact=pItems->GetNext();
            }

      }
      catch(_com_error &e)
      {
            printf((char *)e.Description());
            return env->NewStringUTF(e.Description());
      }
  return env->NewStringUTF("Hier is wat misgegaan");
}

when I execute my java class, I get following output:
In outlook
Unable to instantiate Outlook

Thx
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 10926521
         hr=pApp.CreateInstance(__uuidof(Application));


should that not be Outlook - what is Application?
0
 

Author Comment

by:Andy_Sponik
ID: 10926677
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
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 125 total points
ID: 10926795
This works with word

      LPDISPATCH pDisp;
      LPUNKNOWN pUnk;
      CLSID clsid;

      ::CLSIDFromProgID(L"Word.Application", &clsid); // from registry
      if(::GetActiveObject(clsid, NULL, &pUnk) == S_OK)
      {
            TRACE0("attaching\n");
            VERIFY(pUnk->QueryInterface(IID_IDispatch, (void**) &pDisp) == S_OK);
            app.AttachDispatch(pDisp);
            pUnk->Release();
      }
      else
      {

            TRACE0("creating\n");
            if(!app.CreateDispatch(clsid))
            {
                  TRACE0("Attatching after create\n");
                  if(::GetActiveObject(clsid, NULL, &pUnk) == S_OK)
                  {
                        TRACE0("attaching after create - with the prog\n");
                        VERIFY(pUnk->QueryInterface(IID_IDispatch, (void**) &pDisp) == S_OK);
                        app.AttachDispatch(pDisp);
                        pUnk->Release();
                  }
                  else
                  {
                        AfxMessageBox(IDS_5_ERR_UNK, MB_OK | MB_ICONSTOP);
                        return false;
                  }
            }
//            VERIFY(app.CreateDispatch(clsid) == TRUE);
      }


try replacing Word.Application with Outlook.Application
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Folder Comparison 12 54
NotAlone Challenge 20 84
Unix Command -- Challenging  question 7 95
SQUD PROXY SERVER, UNIX, SLL/HTTPS 5 102
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question