I have an application in VC++ which needs to execute a function provided to it (function name entered in a text box) from a COM DLL (file name provided in another text box).
I have seen code for loading a Win32 library using LoadLibrary and GetProcAddress.
How can this be done for a COM DLL file (created in Visual Basic 6.0)? Is there a link where I can get more information?
If the component that you’re calling supports
IDispatch(which is quite likely if it was created in VB), you can use late binding to call COM interface methods dynamically.For example:
This example fetches the
DISPIDof the named method fromIDispatch::GetIDsOfNames(), then calls that method by passing theDISPIDtoIDispatch::Invoke().For the sake of clarity, I’ve assumed that there are no arguments to the method you want to call, but you can modify the
DISPPARAMSstructure that is passed toInvoke()if there are.