I am new to the com technology but what I am trying to do is to create a basic wrapper for a com , specifically the audio com (mmdevapi). It should work like this: my program calls a com(also created by me) that in the end will load and return a pointer to the audio interfaces. I tried to make everything as transparent as I could but I need more info about the calls made when loading a com. From my understanding:
CoInitialize is called
CoCreateInstance:
a. Searches the dll in the registry
b. Loads the library
c. Get address on DllGetClassObject(I guess it doesn't check for the other function DllCanUnloadNow)
d. Jumps to the function passing the clsid requested by the program(one clsid for very object-so there are more than one objects in one dll? Every "object" containing multiple classes?) and the interface's id.
e. DllGetClassObject return a void pointer to the interface.
- Because the dll is loaded in the same memory as the program it can use this pointer to access the methods from the interface.
If everything I wrote is correct then this should suit my needs(this is part of the wrapper com,used by the main program):
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID * ppvObj) {
//main();
//print iid from here..
LPOLESTR s;
StringFromCLSID(rclsid, &s);
OutputDebugStringW(s);
CoTaskMemFree(s);
StringFromCLSID(riid, &s);
OutputDebugStringW(s);
CoTaskMemFree(s);
//prints: {BCDE0395-E52F-467C-8E3D-C4579291692E} -the audio clsid
// {00000001-0000-0000-C000-000000000046} -the requested interface
// {D3C5025B-3634-4F74-9404-942ECEFC1152} -contains the dll for audio
static const GUID custom_Audio_GUID =
{ 0xd3c5025b, 0x3634, 0x4f74,{ 0x94, 0x4, 0x94, 0x2e, 0xce, 0xfc, 0x11, 0x52 } };
CoInitialize(NULL);
CoCreateInstance(custom_Audio_GUID, NULL, CLSCTX_INPROC_SERVER, riid, ppvObj); //The program wants to access an interface from the audio com so I have to bypass this com,load the audio and request the interface and pass it to the program
return S_OK;
}
So,for the program there's nothing else it should do (it can take rest of the interfaces using QueryInterface using the ppvObj returned by my com,etc.). But ,of course,it doesn't work. It loads the audio dll,spawns a surrogate but the audio doesn't work. Any ideas?
(the custom clsid is defined in CURRENT_USER in CLSID. It only contains InprocServer32/Default -no apartment config; I haven't defined the DLLCanUnload but I don't think it's a problem).
CoInitializecall, and replace the lastCoCreateInstancecall withCoGetClassObject(and return what it returns - don't hard-codeS_OK). I think your wrapper would work with that; though the purpose of it escapes me. - Igor Tandetnik