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 ); Parameters rclsid [in] CLSID associated with the data and code that will be used to create the object. pUnkOuter [in] If NULL, indicates that the object is not being created as part of an aggregate. If non-NULL, pointer to the aggregate object's IUnknown interface (the controlling IUnknown). dwClsContext [in] Context in which the code that manages the newly created object will run. The values are taken from the enumeration CLSCTX. riid [in] Reference to the identifier of the interface to be used to communicate with the object. ppv [out] Address of pointer variable that receives the interface pointer requested in riid. Upon successful return, *ppv contains the requested interface pointer. Return Values S_OK An instance of the specified object class was successfully created. REGDB_E_CLASSNOTREG A specified class is not registered in the registration database. Also can indicate that the type of server you requested in the CLSCTX enumeration is not registered or the values for the server types in the registry are corrupt. CLASS_E_NOAGGREGATION This class cannot be created as part of an aggregate. E_NOINTERFACE The specified class does not implement the requested interface, or the controlling IUnknown does not expose the requested interface. 不会用,rclsid找不着,能否做个例子? 另外,我发现多次注册一个控件也无什么错误,但总归是心里不太舒服!
运行:
regsvr32 ****.ocx
运行:
regsvr32 ****.ocx这样会出现一个已经注册的对话框!俺不想要!
->Registered ActiveX Controls
如返回REGDB_E_CLASSNOTREG 说明控件没有注册。
如返回S_OK 说明注册了
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
);
Parameters
rclsid
[in] CLSID associated with the data and code that will be used to create the object.
pUnkOuter
[in] If NULL, indicates that the object is not being created as part of an aggregate. If non-NULL, pointer to the aggregate object's IUnknown interface (the controlling IUnknown).
dwClsContext
[in] Context in which the code that manages the newly created object will run. The values are taken from the enumeration CLSCTX.
riid
[in] Reference to the identifier of the interface to be used to communicate with the object.
ppv
[out] Address of pointer variable that receives the interface pointer requested in riid. Upon successful return, *ppv contains the requested interface pointer.
Return Values
S_OK
An instance of the specified object class was successfully created.
REGDB_E_CLASSNOTREG
A specified class is not registered in the registration database. Also can indicate that the type of server you requested in the CLSCTX enumeration is not registered or the values for the server types in the registry are corrupt.
CLASS_E_NOAGGREGATION
This class cannot be created as part of an aggregate.
E_NOINTERFACE
The specified class does not implement the requested interface, or the controlling IUnknown does not expose the requested interface.
不会用,rclsid找不着,能否做个例子?
另外,我发现多次注册一个控件也无什么错误,但总归是心里不太舒服!
ppv 返回一个IUnknown接口
注册一个控件只是向注册表中写一些数据,当然多次注册没问题啦!
//Grid32.ocx是否注册判断
//-----------------------------------
HKEY hkey;
LPCTSTR data_Set="SOFTWARE\\Classes\\CLSID\\{A8C3B720-0B5A-101B-B22E-00AA0037B2FC}\\InprocServer32\\";
long ret=::RegOpenKeyEx(HKEY_LOCAL_MACHINE,
data_Set,
0,
KEY_READ,
&hkey);
if(ret!=ERROR_SUCCESS)
MessageBox("Grid32.ocx没有注册,将有部分功能无法正常运行","安装错误",MB_ICONERROR);
else
::RegCloseKey(hkey);
NULL,
CLX_LOCAL_SERVER,//记不清了,查MSDN
IID_MyOcx,
(void*)&ppv);
其中MyOcx为你生成的Ocx的名字,可以在项目的MyOcx_Lib.cpp中找到如果hre == REGDB_E_CLASSNOTREG,则是没有注册