Click here to Skip to main content
15,895,142 members
Home / Discussions / COM
   

COM

 
GeneralRe: COM dll failed to register in debug mode Pin
Sara1237-Aug-08 0:35
Sara1237-Aug-08 0:35 
QuestionSubscribe to HTMLInputTextElementEvents??? [modified] Pin
Romiks4-Aug-08 1:28
Romiks4-Aug-08 1:28 
AnswerRe: Subscribe to HTMLInputTextElementEvents??? Pin
Romiks4-Aug-08 9:24
Romiks4-Aug-08 9:24 
QuestionInterop leak BSTR to System.STring Pin
Karthikeyan Mahadevan3-Aug-08 3:17
Karthikeyan Mahadevan3-Aug-08 3:17 
QuestionCOM Partition Pin
Member 476363031-Jul-08 21:11
Member 476363031-Jul-08 21:11 
QuestionCoCreateInstance returns E_INVALIDARG randomly Pin
Neckli Etel31-Jul-08 2:46
Neckli Etel31-Jul-08 2:46 
QuestionHow to determine the calling application of a dcom server Pin
h. schneider30-Jul-08 23:45
h. schneider30-Jul-08 23:45 
QuestionSome beginning COM linking and IID questions Pin
jeffb4230-Jul-08 5:47
jeffb4230-Jul-08 5:47 
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> 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<imyclass> 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 <initguid.h> 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 <initguid.h>
#include "MyComComponent.h"
.
.
.


...and correctly in the app. In the app there's:

#include "stdafx.h"
#include <initguid.h>
#include "MyTestApp.h"
#include "MainFrm.h"
#include <atlbase.h>
#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 DLL (IMyClass)
3. Added a method to the class
4. Built the DLL
5. Created a MFC application w/VS's project wizard
6. Added MyComComponent.lib to the link step
7. Added code to call my COM component
8. Built (or try to build) the app.

Thanks for any help in clearing up what's going on. I have the feeling that what I'm missing is really simple but I can't see it.


Jeff
AnswerRe: Some beginning COM linking and IID questions Pin
ekklesia30-Jul-08 16:12
ekklesia30-Jul-08 16:12 
AnswerRe: Some beginning COM linking and IID questions Pin
Vi21-Aug-08 1:17
Vi21-Aug-08 1:17 
GeneralRe: Some beginning COM linking and IID questions Pin
jeffb421-Aug-08 8:24
jeffb421-Aug-08 8:24 
QuestionDebug TYhe COM Pin
nhss30-Jul-08 0:53
nhss30-Jul-08 0:53 
Questioncom question Pin
caradri28-Jul-08 6:05
caradri28-Jul-08 6:05 
AnswerRe: com question Pin
CPallini30-Jul-08 2:09
mveCPallini30-Jul-08 2:09 
QuestionWindows Service (Exception: CreateDispatch returning scode = CO_E_SERVER_EXEC_FAILURE ($80080005) ) Pin
xuesyuan25-Jul-08 2:25
xuesyuan25-Jul-08 2:25 
QuestionCross platform development with object inheritance from compiled DLLs. Pin
KernelTintin24-Jul-08 15:43
KernelTintin24-Jul-08 15:43 
QuestionHow to pass Array of objects from com TO C# Pin
sivasankar anumula22-Jul-08 22:06
sivasankar anumula22-Jul-08 22:06 
QuestionHow to find reference count Pin
Ramu.e21-Jul-08 19:58
Ramu.e21-Jul-08 19:58 
AnswerRe: How to find reference count Pin
CPallini21-Jul-08 21:43
mveCPallini21-Jul-08 21:43 
QuestionCompilation error: Cannot convert char to LPWSTR Pin
V K 220-Jul-08 19:43
V K 220-Jul-08 19:43 
QuestionRe: Compilation error: Cannot convert char to LPWSTR Pin
CPallini20-Jul-08 22:46
mveCPallini20-Jul-08 22:46 
AnswerRe: Compilation error: Cannot convert char to LPWSTR Pin
Member 37611484-Aug-08 19:14
Member 37611484-Aug-08 19:14 
QuestionInstantiating COM objects Pin
Member 465324617-Jul-08 10:47
Member 465324617-Jul-08 10:47 
AnswerRe: Instantiating COM objects Pin
Member 69787017-Jul-08 11:20
Member 69787017-Jul-08 11:20 
AnswerRe: Instantiating COM objects Pin
ekklesia30-Jul-08 16:05
ekklesia30-Jul-08 16:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.