My C++ isn't so good, so excuse the terminology mixups.
I have a C# COM application. Following examples and documentation, I
can get the application so that it's callable from C++ if I embed
something like this in my C++ program:
#import "\ComServer\obj\Debug\ComServer.tlb" no_namespace named_guids
and then use:
CoInitialize(NULL);
HRESULT hr = CoCreateInstance(
CLSID_InterfaceImplementation,
NULL, CLSCTX_INPROC_SERVER,
IID_IManagedInterface, reinterpret_cast<void**>
&cpi));
// Etc..
To call it. The problem is that I need to build this C++ application
WITHOUT HAVING THE .TLB FILE HANDY. I have the C# using a fixed GUID,
so I would think there'd be a reasonable way to have the C++ code find
the DLL using that? Or be able to extract out the correct headers for
the C# interface so that I could just paste them into the C++?
If you really mean late binding, then it's IDispatch you should be using.
Assuming a registered ProgID, class registration, IDispatch-capable server
etc, it's something like this to call a method named GetMyString, no
parameters, with late binding COM (and this is what VBScript does under the
covers too):
CoInitialize(0);
HRESULT hr = 0;
CLSID cls;
IDispatch* getit=NULL;
hr = CLSIDFromProgID (L"my.progid", &cls);
hr = CoCreateInstance (cls, NULL, CLSCTX_INPROC_SERVER,
__uuidof(IDispatch), (void**)&getit);
if (SUCCEEDED(hr))
{
VARIANT VarResult = {0};
DISPID dispid;
DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
LPOLESTR szMember = OLESTR("GetMyString");
hr = getit->GetIDsOfNames(IID_NULL, &szMember, 1, LOCALE_USER_DEFAULT,
&dispid);
hr = getit->Invoke(dispid, IID_NULL,
LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dispparamsNoArgs, &VarResult,
NULL, NULL);
getit->Release();
}

Signature
Phil Wilson [MVP Windows Installer]
----
> My C++ isn't so good, so excuse the terminology mixups.
>
[quoted text clipped - 19 lines]
> the DLL using that? Or be able to extract out the correct headers for
> the C# interface so that I could just paste them into the C++?
clintp@gmail.com - 07 Jun 2005 14:23 GMT
This is *exactly* what I was looking for. Hunting around on the 'Net
without that keyword "IDispatch" was getting me lots and lots of
useless answers.
Thanks!