wxAutomationObject Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
arkief
Knows some wx things
Knows some wx things
Posts: 41
Joined: Tue Jan 15, 2008 9:13 am

wxAutomationObject

Post by arkief » Tue Jun 10, 2008 11:06 am

Hi there
I've a VBA-Code which works fine with Outloo-VBA. When I "convert" it to C++ with the wxAutomationObject it doesn't work. Here is the VBA-Code:

Code: Select all

    Dim objMailItem As Outlook.MailItem
    Set objMailItem = Application.CreateItem(olMailItem)
   
    With objMailItem
        .SentOnBehalfOfName = "behalf"
        .Display
    End With
    Exit Sub
And that's the "converted code:"

Code: Select all

        wxAutomationObject *objOutlook=new wxAutomationObject;
        wxAutomationObject MailItem;
        wxVariant rng[4];

        if ( objOutlook->GetInstance("Outlook.Application") )
        {
                rng[0] = "olMailItem";
                if(objOutlook->GetObject(MailItem, "Application.CreateItem", 1, rng))
                    wxMessageBox("MailItem created");
                else
                    wxMessageBox("MailItem not created");

                objOutlook->PutProperty("SentOnBehalfOfName", "behalf");
                objOutlook->CallMethod("Display");
        }
I ever get the message "MailItem not created". What's wrong with the code?

Thanks for helping!
arkief

User avatar
xaviou
Super wx Problem Solver
Super wx Problem Solver
Posts: 429
Joined: Mon Aug 21, 2006 3:18 pm
Location: Annecy - France
Contact:

Post by xaviou » Tue Jun 10, 2008 2:09 pm

Hi arkief

I don't have the whole solution, but here are some errors you made :

First : olMailItem must not be used as a string, but as an integer value (and after a few search, I can tell you its value is 0).

Second : You try to get the MailItem object with the "GetObject" method, witch is (as said in the official doc) for getting properties of an other object.
In VBA, for the "Outlook Application", "CreateItem" isn't a property, but a method.
So, you must call the "CreateItem" method from your objOutlook, passing the "0" value as a parameter (for the type of item you want to create) and getting the result in a wxVariant.

Here is the test I made :

Code: Select all

    wxAutomationObject outlookApp, mailItem;

    if (!outlookApp.GetInstance(_T("Outlook.Application")))
    {
        if (!outlookApp.CreateInstance(_T("Outlook.Application")))
        {
            wxMessageBox(_T("Could not get a valid Outlook object !"));
            return;
        }
    }
    // Object type to create : olMailItem=0
    wxVariant param=0;
    wxVariant res=outlookApp.CallMethod(_T("CreateItem"),param);
    wxMessageBox(_T("Returned type= ") + res.GetType());
The resulting wxMessageBox says : Returned type= void* (every other tests I made said Returned type = null, so I think this one is correct)

After a few search, I think the wxVariant named res contains the IDispatch pointer of the created MailItem object.
You will then have to create a wxAutomationObject with this pointer (but I still don't know how to do this).

Hope It will help you.
Regards
Xav'
My wxWidgets stuff web page : [email protected]'s wxStuff

timg
Earned some good credits
Earned some good credits
Posts: 148
Joined: Mon Jan 23, 2006 6:52 pm

Post by timg » Tue Jun 10, 2008 4:37 pm

You can create an AutomationObject from a IDispatch pointer like this:

Code: Select all


wxVariant dpntr;
dpntr = presentation.CallMethod("Slides.Add");
wxAutomationObject slide;
slide.SetDispatchPtr(dpntr);

User avatar
xaviou
Super wx Problem Solver
Super wx Problem Solver
Posts: 429
Joined: Mon Aug 21, 2006 3:18 pm
Location: Annecy - France
Contact:

Post by xaviou » Wed Jun 11, 2008 6:37 am

Hi
timg wrote:You can create an AutomationObject from a IDispatch pointer like this:

Code: Select all

wxVariant dpntr;
dpntr = presentation.CallMethod("Slides.Add");
wxAutomationObject slide;
slide.SetDispatchPtr(dpntr);
It works !

@arkief : You can, with this, call methods and play with properties of the mailItem object (and not those of the Outlook Object, as you did in the last lines of your code) :

Code: Select all

    wxAutomationObject outlookApp, mailItem;

    if (!outlookApp.GetInstance(_T("Outlook.Application")))
    {
        if (!outlookApp.CreateInstance(_T("Outlook.Application")))
        {
            wxMessageBox(_T("Could not get a valid Outlook object !"));
            return;
        }
    }
    // Object type to create : olMailItem=0
    wxVariant param=0;
    wxVariant res=outlookApp.CallMethod(_T("CreateItem"),param);
    if (res.IsNull())
    {
        wxMessageBox(_T("Unable to create MailIem !"));
        return;
    }
    mailItem.SetDispatchPtr(res);
    mailItem.PutProperty(_T("SentOnBehalfOfName"), _T("behalf"));
    mailItem.CallMethod(_T("Display"));
Regards
Xav'
My wxWidgets stuff web page : [email protected]'s wxStuff

Post Reply