问个初级问题关于CoCreateInstance

iamwjp 2003-06-30 07:17:50
STDAPI CoCreateInstance(
REFCLSID rclsid, //Class identifier (CLSID) of the object
LPUNKNOWN pUnkOuter, //Pointer to controlling IUnknown
DWORD dwClsContext, //Context for running executable code
REFIID riid, //Reference to the identifier of the interface
LPVOID * ppv //Address of output variable that receives
// the interface pointer requested in riid
);

它的第一个参数和第四个参数应该怎么写
...全文
59 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
iamwjp 2003-07-02
  • 打赏
  • 举报
回复
那个test的com就是我自己写的,问题是我在调用时不清楚应该怎么调用,恳请指正
iamwjp 2003-07-02
  • 打赏
  • 举报
回复
自己up
iamwjp 2003-07-01
  • 打赏
  • 举报
回复
能否针对test写一个正确的让我参考一下?
zhjackal 2003-07-01
  • 打赏
  • 举报
回复
你得include ATL的头文件才能用CComPtr呀。
iamwjp 2003-07-01
  • 打赏
  • 举报
回复
#include <windows.h>
#import "D:\\winnt\\system32\\test.dll"

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, int nCmdShow)
{
HRESULT hInit = S_OK;
HRESULT hres = S_OK;

CComPtr<ISave> save;

try
{
hInit = CoInitialize(NULL);

if(FAILED(Init))
throw "CoInitialize Error!";

hres = CoCreateInstance(CLSID_Test, NULL, CLSCTX_ALL, IID_ISave, (void **)&save);

if (FAILED(hres))
throw "CoCreateInstance Error!";
}
catch(const char* error)
{
MessageBox(NULL, error, "ERROR", MB_OK);
}

if(!FAIlED(hInit))
CoUninitialize();

return 0;
}

这样为什么编译不过?应该注意那些问题?
zhjackal 2003-07-01
  • 打赏
  • 举报
回复
ProgID一般来说相当于CLSID的一个别名,形式基本是COMPONANT_NAME.CLASS_NAME.VERSION_NO
iamwjp 2003-07-01
  • 打赏
  • 举报
回复
// Generated .IDL file (by the OLE/COM Object Viewer)
//
// typelib filename: test.dll

[
uuid(4580E441-C0EF-11D6-B342-5254AB1DD8F5),
version(1.0),
helpstring("Test 1.0 Type Library")
]
library TESTLib
{
// TLib : // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
importlib("stdole2.tlb");

// Forward declare all types defined in this typelib
interface ISave;
interface IOpen;

[
uuid(4580E44E-C0EF-11D6-B342-5254AB1DD8F5),
helpstring("Save Class")
]
coclass Save {
[default] interface ISave;
};

[
odl,
uuid(4580E44D-C0EF-11D6-B342-5254AB1DD8F5),
helpstring("ISave Interface"),
dual,
oleautomation
]
interface ISave : IDispatch {
[id(0x00000001), helpstring("method ShowSave")]
HRESULT ShowSave([out, retval] BSTR* fname);
[id(0x00000002), helpstring("method Create")]
HRESULT Create(BSTR fname);
[id(0x00000003), helpstring("method Write")]
HRESULT Write(BSTR str);
[id(0x00000004), helpstring("method WriteLine")]
HRESULT WriteLine(BSTR str);
[id(0x00000005), helpstring("method WriteBlankLines")]
HRESULT WriteBlankLines(int num);
[id(0x00000006), helpstring("method Close")]
HRESULT Close();
};

[
uuid(0C09A962-C1A6-11D6-B342-5254AB1DD8F5),
helpstring("Open Class")
]
coclass Open {
[default] interface IOpen;
};

[
odl,
uuid(0C09A961-C1A6-11D6-B342-5254AB1DD8F5),
helpstring("IOpen Interface"),
dual,
oleautomation
]
interface IOpen : IDispatch {
[id(0x00000001), helpstring("method ShowOpen")]
HRESULT ShowOpen([out, retval] BSTR* fname);
[id(0x00000002), helpstring("method Open")]
HRESULT Open(BSTR filename);
[id(0x00000003), helpstring("method Read")]
HRESULT Read(
int num,
[out, retval] BSTR* ret);
[id(0x00000004), helpstring("method ReadAll")]
HRESULT ReadAll([out, retval] BSTR* ret);
[id(0x00000005), helpstring("method Close")]
HRESULT Close();
};
};


在这里面 test 的com, 那么它的ProgID是什么?test.dll?
WQ 2003-07-01
  • 打赏
  • 举报
回复
程序名
比如Application.1之类
在有,这些可以通过OLEVIEW看到
iamwjp 2003-07-01
  • 打赏
  • 举报
回复
那么,lpszProgID是什么
WQ 2003-07-01
  • 打赏
  • 举报
回复
lpszProgID事先一般都知道
就像你考文件,考那个文件你事先知道
iamwjp 2003-07-01
  • 打赏
  • 举报
回复
那么

HRESULT CLSIDFromProgID(
LPCOLESTR lpszProgID, //Pointer to the ProgID
LPCLSID pclsid //Pointer to the CLSID
);

lpszProgID又从哪里来的


HRESULT CLSIDFromString(
LPOLESTR lpsz, //Pointer to the string representation of the CLSID
LPCLSID pclsid //Pointer to the CLSID
);

lpsz又从哪里来的


又比如现在我机器上有flash 的com,那么我应该怎么用到我的工程里面呢

今天非要打破沙锅问到底不可
iamwjp 2003-07-01
  • 打赏
  • 举报
回复
谁给个例子
wenn 2003-07-01
  • 打赏
  • 举报
回复
那几个ID已经是被微软弄得够复杂的了,你为什么不用它的ATL来处理呢,用起来十分的简单方便。你自己来ATL来做个例子就明白了。
luohualiushui 2003-06-30
  • 打赏
  • 举报
回复
这个问题还真不好回答
也许是用GetClsidFromProgID,也许是头文件,类型库也可以
如果还不明白,就看书去吧
iamwjp 2003-06-30
  • 打赏
  • 举报
回复
如:

CoCreateInstance((REFCLSID)CLSID_CutListGraphBuilder,
NULL,
CLSCTX_INPROC,
(REFIID)IID_ICutListGraphBuilder,
(void**)&pGraphBuilder);

它的CLSID_CutListGraphBuilder, IID_ICutListGraphBuilder从哪里得到的

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧