3,882
社区成员




#include <stdio.h>
#include <atlbase.h>
#include <atlcom.h>
#import "D:\Users\V\Documents\VisualStudio2010\Projects\TestCom1\bin\TestCom1.dll" no_namespace
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
CLSID clsid;
//主要就是这一步出错,一直获取不到有效的clsid
//CLSIDFromProgID的参数试过TestCom1.ComInterface,TestCom1.ComInterfaceID,TestCom1.IComInterface等,
//均无法获得有效clsid
CLSIDFromProgID(OLESTR("IComInterface"), &clsid);
CComPtr<IComInterface> pGetRes;
pGetRes.CoCreateInstance(clsid);
CoUninitialize();
getchar();
return 0;
}
// Generated .IDL file (by the OLE/COM Object Viewer)
//
// typelib filename: TestCom1.dll
[
uuid(F6B199A9-6576-4923-8421-52505A2E85A4),
version(1.0)
]
library TestCom1Lib
{
// TLib : // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
importlib("stdole2.tlb");
// Forward declare all types defined in this typelib
interface IComInterface;
[
uuid(A0F40F1A-0545-4538-A4C2-F164AD9FBB5C)
]
coclass ComInterface {
[default] interface IComInterface;
};
[
odl,
uuid(453187A9-01AC-467E-8CD5-10C5B7E460C2),
dual,
nonextensible,
oleautomation
]
interface IComInterface : IDispatch {
[id(0x00000001)]
HRESULT Hello([out] long* result);
};
};