I had registered a COM component.And I want to call it.
CLSID clsid;
RIID iid;
HRESULT hr = CLSIDFromProgID(OLESTR("se.mysoft"),&clsid);
LPVOID *pRet;
HRESULT hr1 = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, iid, pRet);
I can get the clsid successful, but where can I get the iid ?
I used OLE VIEWER find interface:
[
odl,
uuid(F3F54BC2-D6D1-4A85-B943-16287ECEA64C),
helpstring("Isesoft Interface"),
dual,
oleautomation
]
interface Isesoft : IDispatch {
Then I changed my code:
CLSID clsid;
RIID iid;
IDispatch* pDispatch;
HRESULT hr = CLSIDFromProgID(OLESTR("se.mysoft"),&clsid);
HRESULT hr1 = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, IID_IDispatch,(void **)&pDispatch);
But hr1 returned failed.
Your COM class implements some interfaces and each interface has its
IID
identifier. So you need to get it from your COM component implementation. It's your code and you are expected to provide the identifier which exactly specifies what interface you are requesting.Some COM classes implement well known interface, esp.
IDispatch
, the identifier for which isIID_IDispatch
, or__uuidof(IDispatch)
.UPD. Since you found that the interface of interest is
Isesoft
, your code will be:To get
Isesoft
andIID_Isesoft
,__uuidof(Isesoft)
available to C++ code, you will need to import the definitions, which is typically either of then two:#include "isesoft\sdk.h"
#import "libid:..."
with type library identifier (namespace and other attributes apply)When you have
HRESULT
codes indicating failures, make sure to post the values.You should know the interface you want on your object, let call it
IMyInterface
.