Re: Using same interfaces for in-proc vs. out-proc
 
"Igor Tandetnik" <itandetnik@mvps.org> wrote in message 
news:%23pWIcfJZKHA.5144@TK2MSFTNGP05.phx.gbl...
Drew <dam@dam.com> wrote:
I registered the shared.tlb but in order to use the interfaces
described there I *do* have to reference it in VB.
It looks like approach #1 (one IDL file with two coclass statements, one 
for each server) might work better after all. This way, there's only one 
TLB (used by both servers), >you reference it in VB and gain access to all 
interfaces, coclasses and types.
OK, this part I understand. One IDL, 2 coclasses with unique IDs. My problem 
is how this looks in source. I'll try and restate my requirements. First, 
both EXE and DLL versions must use the same source code; .cpp and .h files. 
They have the same IDL. Use as few preprocessor macros as possible. The EXE 
will compile the COM part of the solution as a static LIB and link to that. 
The DLL, using the exact same source, will be in a seperate solution 
compiled (obviously) as a DLL.
I've set up a minimal example, minus the static LIB for the EXE. IOW, source 
for the COM part is in the same project as the rest of the EXE code. The DLL 
points to the same source as the EXE project for the COM portion of the 
project. I can compile and link both projects but I'm unable to register the 
DLL. When I run it through Dependency Walker and profile it with regsvr32 I 
get Error 0x80070716 "The specified resource name cannot be found in the 
image file". The EXE registers fine and I'm able to use it from a VB 
project. Short of posting the code for both solutions I'm unsure how to 
proceed. Can you give me any more guidance? I've really appreciated your 
help.
Thanks,
Drew
P.S. Here's the header of the shared source file. The DLL has the 
preprocessor symbol SERVER_B defined:
// ApplicationA.h : Declaration of the CApplicationA
#pragma once
#include <resource.h>       // main symbols
#include <COMServerA_i.h>
#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && 
!defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
#error "Single-threaded COM objects are not properly supported on Windows CE 
platform, such as the Windows Mobile platforms that do not include full DCOM 
support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to 
support creating single-thread COM object's and allow use of it's 
single-threaded COM object implementations. The threading model in your rgs 
file was set to 'Free' as that is the only threading model supported in non 
DCOM Windows CE platforms."
#endif
// CApplicationA
class ATL_NO_VTABLE CApplicationA :
 public CComObjectRootEx<CComSingleThreadModel>,
#ifdef SERVER_B
 public CComCoClass<CApplicationA, &CLSID_ApplicationX>,
#else
   public CComCoClass<CApplicationA, &CLSID_Application>,
#endif
 public IDispatchImpl<IApplicationA, &IID_IApplicationA, 
&LIBID_COMServerALib, /*wMajor =*/ 1, /*wMinor =*/ 0>
{
public:
 CApplicationA()
 {
 }
   DECLARE_REGISTRY_RESOURCEID(IDR_APPLICATIONA)
BEGIN_COM_MAP(CApplicationA)
 COM_INTERFACE_ENTRY(IApplicationA)
 COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()
STDMETHOD (get_Application)
(/*[out, retval]*/ IApplicationA** Application);
STDMETHOD (get_ApplicationX)
(/*[out, retval]*/ IApplicationA** Application);
STDMETHOD (get_Name)
(/*[out, retval]*/ BSTR* name);
 DECLARE_PROTECT_FINAL_CONSTRUCT()
 HRESULT FinalConstruct()
 {
  return S_OK;
 }
 void FinalRelease()
 {
 }
public:
};
#ifdef SERVER_B
OBJECT_ENTRY_AUTO(__uuidof(ApplicationX), CApplicationA)
#else
OBJECT_ENTRY_AUTO(__uuidof(Application), CApplicationA)
#endif