Some beginning COM linking and IID questions
-
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
-
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
i hope that you will send me the test code. my email: ekklesia77@naver.com
nice to meet u
-
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
-
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