Finding the IID of the interface is not enough, you also need the LIBID for typelib, as Roman pointed out. Since you know the interface IID, open regedit and type Computer \ HKEY_CLSSES_ROOT \ Interface {F3F54BC2-D6D1-4A85-B943-16287ECEA64C} \ TypeLib, use a backslash. You will get a LIBID, suppose the value is {6F88B941-D87E-4B5E-BAE2-01cc21900dd8}. In your program, add the #import "libid:6F88B941-D87E-4B5E-BAE2-01cc21900dd8"
operator #import "libid:6F88B941-D87E-4B5E-BAE2-01cc21900dd8"
, there are no curly braces. Create a project, then, usually in the x64 \ Release or x64 \ Debug folder, you will find the se.tlh file, named after the server side of ProgID. This file contains announcements and IIDs of all open interfaces, and, hopefully, IceSoft interface (by the way, a funny name). You also looked in the regedit or oleview Imysoft interface because this would be the common name of the default CoClass dispatch interface with ProgID se.mysoft.
Now change your code:
#import "libid:6F88B941-D87E-4B5E-BAE2-01cc21900dd8"//replace correct LIBID … later: CLSID clsid; RIID iid; CComPtr<IceSoft> pIceSoft; // no * HRESULT hr = CLSIDFromProgID(OLESTR("se.mysoft"),&clsid); hr = IIDFromString(OLESTR("{F3F54BC2-D6D1-4A85-B943-16287ECEA64C}"), &iid); HRESULT hr1 = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, iid, (void **)&pIceSoft);
One final note: since your hr1
returns an error that it should not do, I assume that something is wrong with the CLSID. The error code for hr1
will be 800401F3 (CO_E_CLASSSTRING: invalid class string). Get the value from the CLSIDFromProgID(OLESTR("se.mysoft"),&clsid);
and in regedit type Computer \ HKEY_CLASSES_ROOT \ se.mysoft to compare it with the CLSID subkey value.
However, with your code you only get a useless IDispatch
pointer, because that is what you are asking for.
source share