Question: Calling COM Methods in a DLL

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
hgm
Posts: 28353
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Question: Calling COM Methods in a DLL

Post by hgm »

I barely know how to call a function that resides in a DLL. But now it seems there can be other things in DLLs as well. Who can help me with this?

I want to do from C what the following example does in VBScript (which I nver heard of before...):

Code: Select all

Sub StartSpeaking()
     Set myobject = CreateObject("GWSpeak.Speak")
     myobject.SpeakString ("This is the text you want to speak")
End Sub
I have located the file GWSpeak.dll, and to access a routine in it I would normally do something like hApi = LoadLibrary("GWSpeak.dll"); and then try to get the function through Say = GetProcAddress(hApi, "SpeakString");.

But SpeakString is not an Exported Function in this DLL. When I run DLL Export Viewer on GWSPeak.dll, I getthe following list:

Code: Select all

DllCanUnloadNow	0x10001067	0x00001067	1 (0x1)	GWSpeak.dll	C:\Program Files\GW Micro\Window-Eyes\GWSpeak.dll	Exported Function	
DllGetClassObject	0x10001073	0x00001073	2 (0x2)	GWSpeak.dll	C:\Program Files\GW Micro\Window-Eyes\GWSpeak.dll	Exported Function	
DllRegisterServer	0x10001583	0x00001583	3 (0x3)	GWSpeak.dll	C:\Program Files\GW Micro\Window-Eyes\GWSpeak.dll	Exported Function	
DllUnregisterServer	0x1000158b	0x0000158b	4 (0x4)	GWSpeak.dll	C:\Program Files\GW Micro\Window-Eyes\GWSpeak.dll	Exported Function	
ISpeak::IsRunning			3 (0x3)	GWSpeak.dll	C:\Program Files\GW Micro\Window-Eyes\GWSpeak.dll	COM Property	
ISpeak::Silence			2 (0x2)	GWSpeak.dll	C:\Program Files\GW Micro\Window-Eyes\GWSpeak.dll	COM Method	
ISpeak::SpeakString			1 (0x1)	GWSpeak.dll	C:\Program Files\GW Micro\Window-Eyes\GWSpeak.dll	COM Method	
The SpeakString is there, but it is listed as a COM Method rather than an Exported function. What would I have to do to call this "COM Method"?
User avatar
hgm
Posts: 28353
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Question: Calling COM Methods in a DLL

Post by hgm »

I have got as far as retrieving the exported DllRegisterServer from the DLL and calling it. This makes GWSpeak.Speak appear in the registry, and I succeeded in converting that to a CLSID with the function CLSIDFromString (using L"GWSpeak.Speak" as wide-char string argument).

But there I get stuck. It seems I would have to call the export DllGetClassObject now. I have no difficulty extracting that entry point from the DLL, (with GetProcAddress), but it needs to be called with 2 input arguments (and one pointer to an output, but that is no problem). The first input argument is the CLSID, which I think I have obtained. But the second should be an "Interface ID", and I have no idea at all what that means. I tried a routine IIDFromString, but that turns out useless, as it is merely converts 32-digit hex numbers into a corresponding 128-bit int representation.

I had expected that this second parameter of DllGetClassObject would somehow specify what method I wanted to retrieve (in this case "SpeakString"), but there seems no way to convert that info into an IID. So apparently DllGetClassObject will not be able to return me a pointer to that. So what will it return, once I am successful? A pointer to a struct in which SpeakString is a member? How will I be able to address that member? I guess the structure must be declared somehow, to tell the compiler the offset of the member compared to the returned pointer. Can the necessary declaration be derived from the info I get with the DLL Export Viewer?
plattyaj

Re: Question: Calling COM Methods in a DLL

Post by plattyaj »

Learned about COM about 10 years ago and promptly forgot it. I think you'll need to dig up a basic primer and work through that. You usually have to use some sort of interface factory to load the reference, add a count to it and then you get to call it.

Perhaps this will help:

http://www.codeproject.com/KB/COM/comintro.aspx

Forgive me if you already know all this.

Andy.
User avatar
stegemma
Posts: 859
Joined: Mon Aug 10, 2009 10:05 pm
Location: Italy
Full name: Stefano Gemma

Re: Question: Calling COM Methods in a DLL

Post by stegemma »

hgm wrote:...
The SpeakString is there, but it is listed as a COM Method rather than an Exported function. What would I have to do to call this "COM Method"?
In many C++ compiler IDE you can create an object from an Activex that encapsulate all the COM methods. In C++ Builder, for sample, you can use Component->Import Activex control. In this way, you can easly call the COM methods and use any property of the object.