Results 1 to 8 of 8

Thread: CreateObject

  1. #1

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    CreateObject

    Dear All,
    In vb.net we can give like this for getting illustrator application
    appRef = CreateObject("Illustrator.Application")

    in C#.net what we can give for getting illustrator application

    Thanks in Advance
    Please mark you thread resolved using the Thread Tools as shown

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: CreateObject

    I would guess Activator.CreateInstance, although I'm not 100% sure how that behaves with COM components.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Fanatic Member Bombdrop's Avatar
    Join Date
    Apr 2001
    Location
    St Helens, England, UK
    Posts
    667

    Re: CreateObject

    Have a look at the following this shows how i hook up to Outlook in my apps.

    Code:
                //Make sure outlook is on the machine;
                Type outLookType = Type.GetTypeFromProgID("Outlook.Application" , false);
    
                if (outLookType != null) {
    
                    //see if outlook open and assign that instance to outApp.
                    try {
                        this.outApp = Marshal.GetActiveObject("Outlook.Application") as ol._Application;
                    } catch {
                    }
    
                    if (this.outApp != null) {
                        this.CanQuitOutLook = false;
                    } else {
                        this.outApp = Activator.CreateInstance(outLookType) as ol._Application;
    
                    }//(this.outApp!=null)
    Hope this helps!!


  4. #4

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: CreateObject

    Dear BP,
    Thanks for your reply.I got this error when i compiled this code.
    I have set reference to Microsoft outlook Library.

    Code:
    Error	1	'WindowsApplication13.Form1' does not contain a definition for 'outApp'
    Please mark you thread resolved using the Thread Tools as shown

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: CreateObject

    When people post code you should assume that it is an example only and probably cannot be just copied and pasted into your app without some adjustment.

    The fact that it's referred to as:
    this.outApp
    means that it is obviously a member variable. Have you declared a member variable with that name?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    New Member
    Join Date
    Sep 2006
    Posts
    11

    Re: CreateObject

    Dear JMC,

    I cannot get you. this.outApp is a member variable its ok. but what type it must be declared.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: CreateObject

    Quote Originally Posted by siva_boss2003
    Dear JMC,

    I cannot get you. this.outApp is a member variable its ok. but what type it must be declared.
    What is the point of this whole exercise? To create an instance of the Outlook application. That's what outApp is and should be declared as, exactly as Bombdrop's example code shows:
    Code:
    Type outLookType = Type.GetTypeFromProgID("Outlook.Application" , false);
    Code:
    this.outApp = Marshal.GetActiveObject("Outlook.Application") as ol._Application;
    Code:
    this.outApp = Activator.CreateInstance(outLookType) as ol._Application;
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: CreateObject

    Note also that Bombdrop would have imported and aliased the namespace that the _Application class (or interface, which ever it is in that silly COM world ) is a member of. That would look like this, if I remember correctly:
    C# Code:
    1. using ol = Microsoft.Office.Interop.Outlook;
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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