Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. About Com:I need help with the following code(simplified)?

About Com:I need help with the following code(simplified)?

Scheduled Pinned Locked Moved COM
helpcsharpc++visual-studiocom
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    star_see
    wrote on last edited by
    #1

    The following is the simplified code: #include interface ix:IUnknown { virtual void __stdcall fx()=0; }; class Try:public ix { public: HRESULT __stdcall QueryInterface(IID& iid,void** ppv){return S_OK;} virtual ULONG __stdcall AddRef(){return 0;} virtual ULONG __stdcall Release(){return 0;} virtual void __stdcall fx(){} Try(){} }; void f() { Try ptry; } --------------------Configuration: try - Win32 Debug------- d:\files\vc\com\try\try.cpp(23) : error C2259: 'Try' : cannot instantiate abstract class due to following members: d:\files\vc\com\try\try.cpp(7) : see declaration of 'Try' d:\files\vc\com\try\try.cpp(23) : warning C4259: 'long __stdcall IUnknown::QueryInterface(const struct _GUID &,void ** )' : pure virtual function was not defined d:\microsoft visual studio\vc98\include\unknwn.h(109) : see declaration of 'QueryInterface' d:\files\vc\com\try\try.cpp(23) : error C2259: 'Try' : cannot instantiate abstract class due to following members: d:\files\vc\com\try\try.cpp(7) : see declaration of 'Try' d:\files\vc\com\try\try.cpp(23) : warning C4259: 'long __stdcall IUnknown::QueryInterface(const struct _GUID &,void ** )' : pure virtual function was not defined d:\microsoft visual studio\vc98\include\unknwn.h(109) : see declaration of 'QueryInterface' ********************************************************** I really don't know what's wrong with the code. :confused: :confused: :confused:

    S 1 Reply Last reply
    0
    • S star_see

      The following is the simplified code: #include interface ix:IUnknown { virtual void __stdcall fx()=0; }; class Try:public ix { public: HRESULT __stdcall QueryInterface(IID& iid,void** ppv){return S_OK;} virtual ULONG __stdcall AddRef(){return 0;} virtual ULONG __stdcall Release(){return 0;} virtual void __stdcall fx(){} Try(){} }; void f() { Try ptry; } --------------------Configuration: try - Win32 Debug------- d:\files\vc\com\try\try.cpp(23) : error C2259: 'Try' : cannot instantiate abstract class due to following members: d:\files\vc\com\try\try.cpp(7) : see declaration of 'Try' d:\files\vc\com\try\try.cpp(23) : warning C4259: 'long __stdcall IUnknown::QueryInterface(const struct _GUID &,void ** )' : pure virtual function was not defined d:\microsoft visual studio\vc98\include\unknwn.h(109) : see declaration of 'QueryInterface' d:\files\vc\com\try\try.cpp(23) : error C2259: 'Try' : cannot instantiate abstract class due to following members: d:\files\vc\com\try\try.cpp(7) : see declaration of 'Try' d:\files\vc\com\try\try.cpp(23) : warning C4259: 'long __stdcall IUnknown::QueryInterface(const struct _GUID &,void ** )' : pure virtual function was not defined d:\microsoft visual studio\vc98\include\unknwn.h(109) : see declaration of 'QueryInterface' ********************************************************** I really don't know what's wrong with the code. :confused: :confused: :confused:

      S Offline
      S Offline
      Shadi Al Kahwaji
      wrote on last edited by
      #2

      Hi, The thing that you didn't get about COM technology is that "you will not deal with classes any more, what you have to care about is interfaces". Here you are trying to create an instance of Try class, which is wrong in COM world. You have to ask the component for a certain interface, and the component itself will create the class instance for you, and it will cast it to the required interface. To access your component you have to make a call like this one: { IX *pX; //See, you are defining the interface instead of the class HRESULT hr = CoCreateinstance(CLSID_Try, NULL, CLSCTX_SERVER, IID_IX,(void**) &pX); pX->fx(); pX->Release(); } Regards, ShadiK. Shadi Al-Kahwaji

      S 1 Reply Last reply
      0
      • S Shadi Al Kahwaji

        Hi, The thing that you didn't get about COM technology is that "you will not deal with classes any more, what you have to care about is interfaces". Here you are trying to create an instance of Try class, which is wrong in COM world. You have to ask the component for a certain interface, and the component itself will create the class instance for you, and it will cast it to the required interface. To access your component you have to make a call like this one: { IX *pX; //See, you are defining the interface instead of the class HRESULT hr = CoCreateinstance(CLSID_Try, NULL, CLSCTX_SERVER, IID_IX,(void**) &pX); pX->fx(); pX->Release(); } Regards, ShadiK. Shadi Al-Kahwaji

        S Offline
        S Offline
        star_see
        wrote on last edited by
        #3

        Thank you for your reply.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups