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. Some beginning COM linking and IID questions

Some beginning COM linking and IID questions

Scheduled Pinned Locked Moved COM
c++comhelpquestionvisual-studio
4 Posts 3 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.
  • J Offline
    J Offline
    jeffb42
    wrote on last edited by
    #1

    I'm doing some COM work in C++ and I'm finding that my COM knowledge is a bit rusty (I used to use it somewhat frequently several years ago but not that much these days). I've built a simple COM DLL, and a simple MFC app that uses the COM DLL (and both were created by the VS Wizard), and both projects compile and work, but I had to do some tweaking in order to get the app to compile, and some things that I thought would have worked, didn't, so I have several COM related questions: 1. In my Test app (where I'm calling my COM component), I had started out of with: #import "MyComComponent.tlb" . . . CComPtr myClass; hr = myClass.CoCreateInstance(CLSID_MyClass); ...but I got errors saying that IMyClass, CLSID_MyClass, and IID_IMyClass were all undeclared. I thought importing the .TBL file brought those definitions in (what's going on here?). In the end, I ended up with: //#import "MyComComponent.tlb" // not needed at all #include "MyComComponent.h" // needed for IMyClass #include "MyComComponent_i.c" // needed for CLSID_MyClass and IID_IMyClass . . . CComPtr myClass; hr = myClass.CoCreateInstance(CLSID_MyClass); So what's going on? 2. If I just had: //#import "MyComComponent.tlb" #include "MyComComponent.h" ...I got a compile error saying: MainFrm.obj : error LNK2001: unresolved external symbol _CLSID_MyClass MainFrm.obj : error LNK2001: unresolved external symbol _IID_IMyClass I looked into this and several sources on the web said that it was an issue of #include needing to be included before a DEFINE_GUID(......) call, but I checked and initguid.h seems to be included correctly in both the DLL (in MyComComponent.cpp there's: #include "stdafx.h" #include "resource.h" #include #include "MyComComponent.h" . . . ...and correctly in the app. In the app there's: #include "stdafx.h" #include #include "MyTestApp.h" #include "MainFrm.h" #include #import "MyComComponent.tlb" #include "MyComComponent.h" So what is the correct way to include the COM component's definitions? This: #include "MyComComponent.h" #include "MyComComponent_i.c" ...looks odd (I don't recall seeing other COM code like this), and I thought all one had to do was add: #import "MyComComponent.tlb" Oh, and for the record, I am correctly linking in MyComComponent.lib. To repro, these are the steps I did: 1. Created a COM DLL (MyComComponent) w/VS's project wizard 2. Added a Class to the DL

    E V 2 Replies Last reply
    0
    • J jeffb42

      I'm doing some COM work in C++ and I'm finding that my COM knowledge is a bit rusty (I used to use it somewhat frequently several years ago but not that much these days). I've built a simple COM DLL, and a simple MFC app that uses the COM DLL (and both were created by the VS Wizard), and both projects compile and work, but I had to do some tweaking in order to get the app to compile, and some things that I thought would have worked, didn't, so I have several COM related questions: 1. In my Test app (where I'm calling my COM component), I had started out of with: #import "MyComComponent.tlb" . . . CComPtr myClass; hr = myClass.CoCreateInstance(CLSID_MyClass); ...but I got errors saying that IMyClass, CLSID_MyClass, and IID_IMyClass were all undeclared. I thought importing the .TBL file brought those definitions in (what's going on here?). In the end, I ended up with: //#import "MyComComponent.tlb" // not needed at all #include "MyComComponent.h" // needed for IMyClass #include "MyComComponent_i.c" // needed for CLSID_MyClass and IID_IMyClass . . . CComPtr myClass; hr = myClass.CoCreateInstance(CLSID_MyClass); So what's going on? 2. If I just had: //#import "MyComComponent.tlb" #include "MyComComponent.h" ...I got a compile error saying: MainFrm.obj : error LNK2001: unresolved external symbol _CLSID_MyClass MainFrm.obj : error LNK2001: unresolved external symbol _IID_IMyClass I looked into this and several sources on the web said that it was an issue of #include needing to be included before a DEFINE_GUID(......) call, but I checked and initguid.h seems to be included correctly in both the DLL (in MyComComponent.cpp there's: #include "stdafx.h" #include "resource.h" #include #include "MyComComponent.h" . . . ...and correctly in the app. In the app there's: #include "stdafx.h" #include #include "MyTestApp.h" #include "MainFrm.h" #include #import "MyComComponent.tlb" #include "MyComComponent.h" So what is the correct way to include the COM component's definitions? This: #include "MyComComponent.h" #include "MyComComponent_i.c" ...looks odd (I don't recall seeing other COM code like this), and I thought all one had to do was add: #import "MyComComponent.tlb" Oh, and for the record, I am correctly linking in MyComComponent.lib. To repro, these are the steps I did: 1. Created a COM DLL (MyComComponent) w/VS's project wizard 2. Added a Class to the DL

      E Offline
      E Offline
      ekklesia
      wrote on last edited by
      #2

      i hope that you will send me the test code. my email: ekklesia77@naver.com

      nice to meet u

      1 Reply Last reply
      0
      • J jeffb42

        I'm doing some COM work in C++ and I'm finding that my COM knowledge is a bit rusty (I used to use it somewhat frequently several years ago but not that much these days). I've built a simple COM DLL, and a simple MFC app that uses the COM DLL (and both were created by the VS Wizard), and both projects compile and work, but I had to do some tweaking in order to get the app to compile, and some things that I thought would have worked, didn't, so I have several COM related questions: 1. In my Test app (where I'm calling my COM component), I had started out of with: #import "MyComComponent.tlb" . . . CComPtr myClass; hr = myClass.CoCreateInstance(CLSID_MyClass); ...but I got errors saying that IMyClass, CLSID_MyClass, and IID_IMyClass were all undeclared. I thought importing the .TBL file brought those definitions in (what's going on here?). In the end, I ended up with: //#import "MyComComponent.tlb" // not needed at all #include "MyComComponent.h" // needed for IMyClass #include "MyComComponent_i.c" // needed for CLSID_MyClass and IID_IMyClass . . . CComPtr myClass; hr = myClass.CoCreateInstance(CLSID_MyClass); So what's going on? 2. If I just had: //#import "MyComComponent.tlb" #include "MyComComponent.h" ...I got a compile error saying: MainFrm.obj : error LNK2001: unresolved external symbol _CLSID_MyClass MainFrm.obj : error LNK2001: unresolved external symbol _IID_IMyClass I looked into this and several sources on the web said that it was an issue of #include needing to be included before a DEFINE_GUID(......) call, but I checked and initguid.h seems to be included correctly in both the DLL (in MyComComponent.cpp there's: #include "stdafx.h" #include "resource.h" #include #include "MyComComponent.h" . . . ...and correctly in the app. In the app there's: #include "stdafx.h" #include #include "MyTestApp.h" #include "MainFrm.h" #include #import "MyComComponent.tlb" #include "MyComComponent.h" So what is the correct way to include the COM component's definitions? This: #include "MyComComponent.h" #include "MyComComponent_i.c" ...looks odd (I don't recall seeing other COM code like this), and I thought all one had to do was add: #import "MyComComponent.tlb" Oh, and for the record, I am correctly linking in MyComComponent.lib. To repro, these are the steps I did: 1. Created a COM DLL (MyComComponent) w/VS's project wizard 2. Added a Class to the DL

        V Offline
        V Offline
        Vi2
        wrote on last edited by
        #3

        1. In my Test app (where I'm calling my COM component), I had started out of with: #import "MyComComponent.tlb" named_guids

        With best wishes, Vita

        J 1 Reply Last reply
        0
        • V Vi2

          1. In my Test app (where I'm calling my COM component), I had started out of with: #import "MyComComponent.tlb" named_guids

          With best wishes, Vita

          J Offline
          J Offline
          jeffb42
          wrote on last edited by
          #4

          Thanks Vita! That was exactly what I was missing. Jeff

          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