COM

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Duncan Winn

    #1

    COM

    Does anyone know how to access a COM component from VC++ 7???

    Thanks for any help, and sorry if this is an inappropriate place to post
    this question, but I did not know which user group to post it on.


  • Carl Daniel [VC++ MVP]

    #2
    Re: COM

    Duncan Winn wrote:[color=blue]
    > Does anyone know how to access a COM component from VC++ 7???[/color]

    For starters, try looking up

    #import
    CoInitialize
    CoCreateInstanc e

    in your VC/MSDN documentation. There are myriad COM samples, including 136
    samples in the Windows Platform SDK (which you can download from
    http://www.microsoft.com/msdownload/...dk/sdkupdate/).

    -cd


    Comment

    • chris

      #3
      COM

      If the component includes a type library, you can import
      the type library and use an interface pointer to access
      methods. Something like this:
      #import "MyComponent.dl l" named_guids //import the dll

      #include "MyComponent.tl h" //include the type library

      Declare an interface pointer to the class:
      MyCom::IComCls pMyCom;

      Use the pointer to create an instance of the object
      pMyCom.CreateIn stance(MyCom::C LSID_CMyCom);

      Use the pointer:
      pMyCom->SomeWork(param 1, param2);


      If no type library, you can do the following:
      #include "MyComponent_i. c"

      IComClasPtr pMyCom; //define an interface pointer
      HRESULT hr;

      Use the pointer to create an instance of the object
      hr = pMyCom.CreateIn stance(CLSID_CM yCom);
      //some code here to check if succeeded

      Use the pointer:
      hr = pMyCom->SomeWork(param 1, param2);
      [color=blue]
      >-----Original Message-----
      >Does anyone know how to access a COM component from VC++[/color]
      7???[color=blue]
      >
      >Thanks for any help, and sorry if this is an[/color]
      inappropriate place to post[color=blue]
      >this question, but I did not know which user group to[/color]
      post it on.[color=blue]
      >
      >
      >.
      >[/color]

      Comment

      • Carl Daniel [VC++ MVP]

        #4
        Re: COM

        chris wrote:[color=blue]
        > If the component includes a type library, you can import
        > the type library and use an interface pointer to access
        > methods. Something like this:
        > #import "MyComponent.dl l" named_guids //import the dll
        >
        > #include "MyComponent.tl h" //include the type library[/color]

        You should never directly #include a .tlh file - the #import directive
        already includes the file for you.

        -cd



        Comment

        Working...