Results 1 to 3 of 3

Thread: [2.0] Vb's GetObject in C#

  1. #1

    Thread Starter
    Fanatic Member Bombdrop's Avatar
    Join Date
    Apr 2001
    Location
    St Helens, England, UK
    Posts
    667

    [2.0] Vb's GetObject in C#

    Hi all i wish my app to assign task to users via Outlook, been having huge problems with the 8007007e error having a certain reg key that stops outlook being instantiated so thinking back to my VB6 days i know you can get hold of instance that is open via the following

    Code:
            'Use Getobject method incase outlook is already open
            Set objApp = GetObject(, "Outlook.Application")
    does anyone know how I could achieve this in C#

    Thanks

  2. #2
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    Re: [2.0] Vb's GetObject in C#

    I upgraded it to VB.NET and added a few examples of accessing the late-bound object:
    VB.NET:
    Dim objApp As Object = GetObject(, "Outlook.Application")
    objApp.FooMethod()
    x = objApp.FooProperty
    x = objApp.FooFunction(i, j)

    The C# equivalent is:
    System.Type objAppType = System.Type.GetTypeFromProgID("Outlook.Application");
    object objApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Outlook.Application");
    objAppType.InvokeMember("FooMethod", System.Reflection.BindingFlags.InvokeMethod, null, objApp, null);
    x = objAppType.InvokeMember("FooProperty", System.Reflection.BindingFlags.GetProperty, null, objApp, null);
    x = objAppType.InvokeMember("FooFunction", System.Reflection.BindingFlags.InvokeMethod, null, objApp, new object[] {i, j});

    I know this looks complicated, but the VB GetObject and CreateObject (and the subsequent calls to the late-bound object) do a lot behind the scenes.
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

  3. #3

    Thread Starter
    Fanatic Member Bombdrop's Avatar
    Join Date
    Apr 2001
    Location
    St Helens, England, UK
    Posts
    667

    Re: [2.0] Vb's GetObject in C#

    Thanks David played about with what you posted i came up with a slightly different approach. Just wanting know would just suggest using yours or the one i have used ? please see the attached files.

    Many thanks
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width