I have an in-process COM server FooObject.dll that I no longer have the source code for, but would like to write a new implementation in unmanaged C++ using the same interface. I'm using Visual Studio 2019 latest update.
How do I do this?
So far I set up a project like this:
- Extract
FooObject.tlb
using the instructions in https://stackoverflow.com/a/42074044/1505939 . - Create
FooObject.idl
fromFooObject.tlb
using OleView.exe. - Create a new project in Visual Studio of type: "ATL Project" using options "Allow merging of proxy/stub code" and "Support COM+ 1.0" , and "dll" type.
I have tried the following things (individually)
Under "Source Files", rightclick -> Add Existing Item ->
FooObject.idl
.- This caused
ATLProject1_i.c
and.h
to be regenerated containing only the definitions fromFooObject.idl
, and thendllmain.h
failed to compile since it referencedLIBID_ATLProject1Lib
which used to be inATLProject1_i.c
but wasn't now. So I guess this is not the intended approach. - Also tried adding
FoOObject.idl
and removingATLProject1.idl
, which again built successfully and even allows registering withregsvr32
which registers all the same classes (can see it via the type library browser in OleView); but there's still no implementation and creating an object in a test container gives 80040154 as if it were not registered.
- This caused
Add
#import "FooObject.dll
to the top ofATLProject1.cpp
, under theinclude
s . The project compiles without error but no import files are generated.Add
importlib "FooObject.idl"
to the ATLProject1.idl file. Again it compiles without error but doesn't generate any import files.Manually create import files with
midl /header FooObject.h /env win32 FooObject.idl
. This did create import files, and I can include them with#include "FooObject.h"
and get no errors.
In all the last 3 cases there are no errors but it's not clear how to generate the implementation code for the CoClasses in FooObject.idl
, like would appear if I went "Add New Item" and chose an ATL Simple Object to add. So I'm not sure how to get from here to the point where I can start writing code for the bodies of the functions in the objects I'm trying to create.
(My previous experience was with using a non-Microsoft vendor whose editor just let you add any CoClass from the registry and it'd generate the skeleton code).