Building an in-process COM that uses out-of-process COM 
Author Message
 Building an in-process COM that uses out-of-process COM

I made an out-of-process COM server called MySingleton in a similarly named
project folder.  In a parallel folder, I have an in-process COM object
called MyHandler (its a name-space handler).

When I try to build the handler, which creates an instance of the singleton,
I get a link error stating that the external symbol "_IID_IMySingleton" is
not defined.  If I then add the .obj to the list of libraries and modules
for the handler project, I get "LINK : warning LNK4098: defaultlib "LIBCMTD"
conflicts with use of other libs; use /NODEFAULTLIB:library" along with some
further errors.

How can I build the handler that uses the singleton?

--
-----------------------------------------------------
Brian J. Sayatovic



Sat, 03 May 2003 03:00:00 GMT  
 Building an in-process COM that uses out-of-process COM

import his tlb


Quote:
> I made an out-of-process COM server called MySingleton in a similarly
named
> project folder.  In a parallel folder, I have an in-process COM object
> called MyHandler (its a name-space handler).

> When I try to build the handler, which creates an instance of the
singleton,
> I get a link error stating that the external symbol "_IID_IMySingleton" is
> not defined.  If I then add the .obj to the list of libraries and modules
> for the handler project, I get "LINK : warning LNK4098: defaultlib
"LIBCMTD"
> conflicts with use of other libs; use /NODEFAULTLIB:library" along with
some
> further errors.

> How can I build the handler that uses the singleton?

> --
> -----------------------------------------------------
> Brian J. Sayatovic




Sat, 03 May 2003 03:00:00 GMT  
 Building an in-process COM that uses out-of-process COM

What is a "tlb"?

If you mean to import one IDL inside the other, I tried that with still
undesired results.  My projects look like this:

Projects
  |__MySingleton // Out-of-process, contains MySingletonObj
  |__MyHandler // In-process (name-space handler), contians MyHandlerObj

Inside MyHandler, I use CoCreateInstance to get an interface to the
singleton.  However, the MyHandler project won't build because the linker
complains that the _IID_MySingleton is not found:

MyHandlerObj.obj : error LNK2001: unresolved external symbol
_IID_IMySingletonObj

I've tried:
-    Including MySingleton.h in the source and/or header of MyHandler
-    Including MySingletonObj.h "..."
-    Including both
-    Doing  'import "../MySingleton/MySingleton.idl";' in the MyHandler.idl.
This changed the MyHandler.h file and I had to add the relative path to the
include line it added for MySingleton.h.

At this point, I'm still getting unresolved externals.  When I add the
.obj's from MySingleton to the link line for MyHandler, a whole new class of
errors occur during the build (differing library types, etc.)

Does that info provide a clearer picture of my problem?

--
-----------------------------------------------------
Brian J. Sayatovic


Quote:
> import his tlb


> > I made an out-of-process COM server called MySingleton in a similarly
> named
> > project folder.  In a parallel folder, I have an in-process COM object
> > called MyHandler (its a name-space handler).

> > When I try to build the handler, which creates an instance of the
> singleton,
> > I get a link error stating that the external symbol "_IID_IMySingleton"
is
> > not defined.  If I then add the .obj to the list of libraries and
modules
> > for the handler project, I get "LINK : warning LNK4098: defaultlib
> "LIBCMTD"
> > conflicts with use of other libs; use /NODEFAULTLIB:library" along with
> some
> > further errors.

> > How can I build the handler that uses the singleton?

> > --
> > -----------------------------------------------------
> > Brian J. Sayatovic




Sat, 03 May 2003 03:00:00 GMT  
 Building an in-process COM that uses out-of-process COM

Quote:
> What is a "tlb"?

.tlb is compiled interfaces definition file - one of results of compilation
of idl file.
Put reference to it at the top of the source .cpp file you are going to put
references to MySingletonObj:

#import "MySingletonObj.tlb"

B.



Sat, 03 May 2003 03:00:00 GMT  
 Building an in-process COM that uses out-of-process COM
When I add the following import line...

#import "../MySingleton/MySingleton.tlb"

I get the following errors:

D:\Project\MyHandler\MyHandlerObj.cpp(214) : error C2065: 'IMySingletonObj'
: undeclared identifier
D:\Project\MyHandler\MyHandlerObj.cpp(214) : error C2065:
'singletonInterface' : undeclared identifier
D:\Project\MyHandler\MyHandlerObj.cpp(214) : error C2106: '=' : left operand
must be l-value
D:\Project\MyHandler\MyHandlerObj.cpp(215) : error C2065:
'IID_IMySingletonObj' : undeclared identifier

These errors come from the following chunk of (not-very-pretty) code:

 // Get the AFbSingleton object
 CComVariant clsidVariant("{F0B6AECD-BA52-11D4-875F-0050DA68AAB2}");
 CLSID clsid;
 HRESULT clsidResult = CLSIDFromString(clsidVariant.bstrVal, &clsid);
 IMySingletonObj *singletonInterface = NULL;
 HRESULT singletonResult = CoCreateInstance(clsid, NULL,
CLSCTX_LOCAL_SERVER, IID_IMySingletonObj, (LPVOID *)(&singletonInterface));

Is there something more to #import?

--
-----------------------------------------------------
Brian J. Sayatovic


Quote:

> > What is a "tlb"?

> .tlb is compiled interfaces definition file - one of results of
compilation
> of idl file.
> Put reference to it at the top of the source .cpp file you are going to
put
> references to MySingletonObj:

> #import "MySingletonObj.tlb"

> B.



Sat, 03 May 2003 03:00:00 GMT  
 Building an in-process COM that uses out-of-process COM
Look at tli/tlh files which created by #import - there is namespace around
the class definition.
Also you can simply write
#import "../MySingleton/MySingleton.tlb" no_namespace
and you can try to use IMySingletonObjPtr - it's smart pointer wrapper



Quote:
> When I add the following import line...

> #import "../MySingleton/MySingleton.tlb"

> I get the following errors:

> D:\Project\MyHandler\MyHandlerObj.cpp(214) : error C2065:
'IMySingletonObj'
> : undeclared identifier
> D:\Project\MyHandler\MyHandlerObj.cpp(214) : error C2065:
> 'singletonInterface' : undeclared identifier
> D:\Project\MyHandler\MyHandlerObj.cpp(214) : error C2106: '=' : left
operand
> must be l-value
> D:\Project\MyHandler\MyHandlerObj.cpp(215) : error C2065:
> 'IID_IMySingletonObj' : undeclared identifier

> These errors come from the following chunk of (not-very-pretty) code:

>  // Get the AFbSingleton object
>  CComVariant clsidVariant("{F0B6AECD-BA52-11D4-875F-0050DA68AAB2}");
>  CLSID clsid;
>  HRESULT clsidResult = CLSIDFromString(clsidVariant.bstrVal, &clsid);
>  IMySingletonObj *singletonInterface = NULL;
>  HRESULT singletonResult = CoCreateInstance(clsid, NULL,
> CLSCTX_LOCAL_SERVER, IID_IMySingletonObj, (LPVOID

*)(&singletonInterface));

- Show quoted text -

Quote:

> Is there something more to #import?

> --
> -----------------------------------------------------
> Brian J. Sayatovic




> > > What is a "tlb"?

> > .tlb is compiled interfaces definition file - one of results of
> compilation
> > of idl file.
> > Put reference to it at the top of the source .cpp file you are going to
> put
> > references to MySingletonObj:

> > #import "MySingletonObj.tlb"

> > B.



Sat, 03 May 2003 03:00:00 GMT  
 Building an in-process COM that uses out-of-process COM
Two questions now:

1. What do I do with the smart pointer?  I've looked throough the MSDN help,
but all of the info is very syntactical and dispersed.  I've tried...

IMySingletonObjPtr x;
IMySingletonObj *y = x.GetInterface();

...but that won't even compile.  What about CreateInstance?  But it asks for
various CLSID parameters which doesn't make sense since 'x' is of the type I
want (sort of).

2. I'm beginning to doubt my slight COM knowledge when I encounter these
sorts of gotchas.  Where can I go for a tutorial that actually covers topics
such as out-of-process Singletons?

--
-----------------------------------------------------
Brian J. Sayatovic


Quote:
> Look at tli/tlh files which created by #import - there is namespace around
> the class definition.
> Also you can simply write
> #import "../MySingleton/MySingleton.tlb" no_namespace
> and you can try to use IMySingletonObjPtr - it's smart pointer wrapper



> > When I add the following import line...

> > #import "../MySingleton/MySingleton.tlb"

> > I get the following errors:

> > D:\Project\MyHandler\MyHandlerObj.cpp(214) : error C2065:
> 'IMySingletonObj'
> > : undeclared identifier
> > D:\Project\MyHandler\MyHandlerObj.cpp(214) : error C2065:
> > 'singletonInterface' : undeclared identifier
> > D:\Project\MyHandler\MyHandlerObj.cpp(214) : error C2106: '=' : left
> operand
> > must be l-value
> > D:\Project\MyHandler\MyHandlerObj.cpp(215) : error C2065:
> > 'IID_IMySingletonObj' : undeclared identifier

> > These errors come from the following chunk of (not-very-pretty) code:

> >  // Get the AFbSingleton object
> >  CComVariant clsidVariant("{F0B6AECD-BA52-11D4-875F-0050DA68AAB2}");
> >  CLSID clsid;
> >  HRESULT clsidResult = CLSIDFromString(clsidVariant.bstrVal, &clsid);
> >  IMySingletonObj *singletonInterface = NULL;
> >  HRESULT singletonResult = CoCreateInstance(clsid, NULL,
> > CLSCTX_LOCAL_SERVER, IID_IMySingletonObj, (LPVOID
> *)(&singletonInterface));

> > Is there something more to #import?

> > --
> > -----------------------------------------------------
> > Brian J. Sayatovic




> > > > What is a "tlb"?

> > > .tlb is compiled interfaces definition file - one of results of
> > compilation
> > > of idl file.
> > > Put reference to it at the top of the source .cpp file you are going
to
> > put
> > > references to MySingletonObj:

> > > #import "MySingletonObj.tlb"

> > > B.



Sat, 03 May 2003 03:00:00 GMT  
 Building an in-process COM that uses out-of-process COM
smart pointer is a wrapper which may help you to deal with com object as
almost normal C++ objects.
There are some problems with this method - something about copy
constructors.Never got this problems.
Consider the following example:

Test is a class with interface ITest

#import "test.tlb" / / it will make some namespace for ex. TestLib
using namespace TestLib
int main(int argv char *argc[]){
    ITestPtr spTest;
  CoInit...
  hr=spTest.CreateInstance(__uuidof(Test)); / /Test is coclass
  if (FAILED(hr)) ...
  spTest->TestFunc();
  spTest.Release(); / /
 CoUnini...

Quote:
}



Sat, 03 May 2003 03:00:00 GMT  
 Building an in-process COM that uses out-of-process COM
I've tried using the code idea you have below, but I keep getting
E_NOINTERFACE as the return code.

I've searched the registry for MySingleton's CLSID and have not found it.
Is there anything special to do with it since it is an out-of-process COM
server?

--
-----------------------------------------------------
Brian J. Sayatovic


Quote:
> smart pointer is a wrapper which may help you to deal with com object as
> almost normal C++ objects.
> There are some problems with this method - something about copy
> constructors.Never got this problems.
> Consider the following example:

> Test is a class with interface ITest

> #import "test.tlb" / / it will make some namespace for ex. TestLib
> using namespace TestLib
> int main(int argv char *argc[]){
>     ITestPtr spTest;
>   CoInit...
>   hr=spTest.CreateInstance(__uuidof(Test)); / /Test is coclass
>   if (FAILED(hr)) ...
>   spTest->TestFunc();
>   spTest.Release(); / /
>  CoUnini...
> }



Sat, 03 May 2003 03:00:00 GMT  
 Building an in-process COM that uses out-of-process COM


Quote:
> I've tried using the code idea you have below, but I keep getting
> E_NOINTERFACE as the return code.

your out-of-process COM server has some custom interface, I guess. You must
build and register it's proxy/stub code. Just run in your project directory
this command:

nmake (your project name)ps.mk

.. it will build (your project name)ps.dll , which you should register using
regsvr32

Rgds

B.



Mon, 05 May 2003 03:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. out-of-process COM server using MFC

2. Critical problem when using COM dlls in surrogate processes

3. Using COM objects for Inter Process Communications

4. Using COM and Inter Process Communications

5. How to pass MFC Classes between two process using COM

6. Works ok as Inprocess Server but not as Out process

7. WM_COPYDATA works inprocess and fails outside the process

8. InProcess COM broken -- what could be the problem?

9. Problems with a com inprocess component project

10. Problem with a com inprocess component project

11. Child process com

12. How to debug out process COM server.

 

 
Powered by phpBB® Forum Software