请如如何查找com组件dll的clsid

weichenggao 2009-07-02 04:04:23
我用VC工具ATL生成了一个空的com组件;(什么也不做)

然后注册这个testDll.dll

然后通过注册表查找testDll,找不到这个testDll对应的clsid属性!

请问各位应该怎么才能得到dll的clsid.

...全文
2468 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
丶云淡风轻丶 2011-09-07
  • 打赏
  • 举报
回复
学习学习
FreeBot 2009-07-15
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 Cat_Of_9Life 的回复:]
增加 ATL 对象类
  步骤1:菜单 Insert\New ATL Object...(或者用鼠标右键在 ClassView 卡片中弹出菜单)并选择Object 分类,选中 Simple Object 项目。
  步骤2:增加自定义类 CFun(接口 IFun)、输入类中的各项名称. 其实,我们只需要输入短名(Short Name),其它的项目会自动填写
[/Quote]

创建完成后,你可以到Resource Files 中找“工程名称.rgs”,在该文件中你可以找到
CLSID = s '{8D01D1D2-86DB-4A1A-B240-A968B61DBE9F}'
jannl 2009-07-13
  • 打赏
  • 举报
回复
你在注册表里查找你的DLL文件名就可以了,或者你记住了创建时的ProgID,查找ProgID也可以。一般默认ProgID是
项目名.实现接口类名.1
Cat_Of_9Life 2009-07-13
  • 打赏
  • 举报
回复
增加 ATL 对象类
  步骤1:菜单 Insert\New ATL Object...(或者用鼠标右键在 ClassView 卡片中弹出菜单)并选择Object 分类,选中 Simple Object 项目。
  步骤2:增加自定义类 CFun(接口 IFun)、输入类中的各项名称. 其实,我们只需要输入短名(Short Name),其它的项目会自动填写
sjdev 2009-07-12
  • 打赏
  • 举报
回复
插入atl object,默认是没有com类文件生成的.
做鸡真好吃 2009-07-12
  • 打赏
  • 举报
回复
polygon
cdpc0202 2009-07-07
  • 打赏
  • 举报
回复
MSDN上有例子 看polygon的例子。
oyljerry 2009-07-02
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 weichenggao 的回复:]
这个是我的源文件,封装了一下第三方的dll的几个方法,把他变成com组件模式的,希望在java中调用
// KDGTComm.cpp : Implementation of DLL Exports.


// Note: Proxy/Stub Information
//      To merge the proxy/stub code into the object DLL, add the file
//      dlldatax.c to the project.  Make sure precompiled headers
//      are turned off for this file, and add _MERGE_PROXYSTUB to the
//      d…
[/Quote]
你看你工程的中idl文件,里面有对应的clsid信息
十豆三 2009-07-02
  • 打赏
  • 举报
回复
将此 DLL 注册后,在注册表中查找此 DLL 的文件名,一般会在 InProcServer32 项中找到(打开注册表查找即可)
找到后,InProcServer32 的父层及同层的 ProgID 就要我们要的。
Kudeet 2009-07-02
  • 打赏
  • 举报
回复
用向导建立一个简单的ATL对象应该就是了。
weichenggao 2009-07-02
  • 打赏
  • 举报
回复
这个是我的源文件,封装了一下第三方的dll的几个方法,把他变成com组件模式的,希望在java中调用
// KDGTComm.cpp : Implementation of DLL Exports.


// Note: Proxy/Stub Information
// To merge the proxy/stub code into the object DLL, add the file
// dlldatax.c to the project. Make sure precompiled headers
// are turned off for this file, and add _MERGE_PROXYSTUB to the
// defines for the project.
//
// If you are not running WinNT4.0 or Win95 with DCOM, then you
// need to remove the following define from dlldatax.c
// #define _WIN32_WINNT 0x0400
//
// Further, if you are running MIDL without /Oicf switch, you also
// need to remove the following define from dlldatax.c.
// #define USE_STUBLESS_PROXY
//
// Modify the custom build rule for KDGTComm.idl by adding the following
// files to the Outputs.
// KDGTComm_p.c
// dlldata.c
// To build a separate proxy/stub DLL,
// run nmake -f KDGTCommps.mk in the project directory.

#include "stdafx.h"
#include "resource.h"
#include <initguid.h>
#include "KDGTComm.h"
#include "dlldatax.h"
#include "KCBPCli.h"
#include "KDGTComm_i.c"
#include <stdio.h>
#include <windows.h>

extern "C" int __declspec(dllexport)ConnectServer(char *, char *, char *);
extern "C" int __declspec(dllexport)BeginWrite();
extern "C" int __declspec(dllexport)CallProgramAndCommit(char *);
extern "C" int __declspec(dllexport)RsMore();
extern "C" int __declspec(dllexport)RsGetCursorName(char *, int);
extern "C" int __declspec(dllexport)RsFetchRow();
extern "C" int __declspec(dllexport)RsGetCol(int, char *);
extern "C" int __declspec(dllexport)DisConnect();


#ifdef _MERGE_PROXYSTUB
extern "C" HINSTANCE hProxyDll;
#endif

CComModule _Module;
typedef int(*lpConnectServer)(char *, char *, char *);
typedef int(*lpBeginWrite)();
typedef int(*lpCallProgramAndCommit)(char *);
typedef int(*lpRsMore)();
typedef int(*lpRsGetCursorName)(char *, int);
typedef int(*lpRsFetchRow)();
typedef int(*lpRsGetCol)(int, char *);
typedef int(*lpDisConnect)();

BEGIN_OBJECT_MAP(ObjectMap)
END_OBJECT_MAP()

/////////////////////////////////////////////////////////////////////////////
// DLL Entry Point

extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
lpReserved;
#ifdef _MERGE_PROXYSTUB
if (!PrxDllMain(hInstance, dwReason, lpReserved))
return FALSE;
#endif
if (dwReason == DLL_PROCESS_ATTACH)
{
_Module.Init(ObjectMap, hInstance, &LIBID_KDGTCOMMLib);
DisableThreadLibraryCalls(hInstance);
}
else if (dwReason == DLL_PROCESS_DETACH)
_Module.Term();

return TRUE; // ok
}

/////////////////////////////////////////////////////////////////////////////
// Used to determine whether the DLL can be unloaded by OLE

STDAPI DllCanUnloadNow(void)
{
#ifdef _MERGE_PROXYSTUB
if (PrxDllCanUnloadNow() != S_OK)
return S_FALSE;
#endif
return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
}

/////////////////////////////////////////////////////////////////////////////
// Returns a class factory to create an object of the requested type

STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
#ifdef _MERGE_PROXYSTUB
if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
return S_OK;
#endif
return _Module.GetClassObject(rclsid, riid, ppv);
}

/////////////////////////////////////////////////////////////////////////////
// DllRegisterServer - Adds entries to the system registry

STDAPI DllRegisterServer(void)
{
#ifdef _MERGE_PROXYSTUB
HRESULT hRes = PrxDllRegisterServer();
if (FAILED(hRes))
return hRes;
#endif
// registers object, typelib and all interfaces in typelib
return _Module.RegisterServer(TRUE);
}

/////////////////////////////////////////////////////////////////////////////
// DllUnregisterServer - Removes entries from the system registry

STDAPI DllUnregisterServer(void)
{
#ifdef _MERGE_PROXYSTUB
PrxDllUnregisterServer();
#endif
return _Module.UnregisterServer(TRUE);
}

//write by 高纪 ConnectServer
int KCBPCLI_ConnectServer(char *ServerName, char *UserName, char *Password)
{
HINSTANCE hDll = LoadLibrary("d:\\windows_v5.2\\KCBPCli.dll");
int result = 0;
lpConnectServer connect;

if(hDll!=NULL)
{
connect = (lpConnectServer)GetProcAddress(hDll, "ConnectServer");
if(connect!=NULL)
{
result = connect(ServerName,UserName,Password);
}
FreeLibrary(hDll);
}
return result;
}


//write by 高纪 BeginWrite
int KCBPCLI_BeginWrite()
{
HINSTANCE hDll = LoadLibrary("d:\\windows_v5.2\\KCBPCli.dll");
int result = 0;
lpBeginWrite beginwrite;

if(hDll!=NULL)
{
beginwrite = (lpBeginWrite)GetProcAddress(hDll, "BeginWrite");
if(beginwrite!=NULL)
{
result = beginwrite();
}
FreeLibrary(hDll);
}
return result;
}

//write by 高纪 CallProgramAndCommit(servername)
int KCBPCLI_CallProgramAndCommit(char *ServerName)
{
HINSTANCE hDll = LoadLibrary("d:\\windows_v5.2\\KCBPCli.dll");
int result = 0;
lpCallProgramAndCommit commit;

if(hDll!=NULL)
{
commit = (lpCallProgramAndCommit)GetProcAddress(hDll, "CallProgramAndCommit");
if(commit!=NULL)
{
result = commit(ServerName);
}
FreeLibrary(hDll);
}
return result;
}

//write by 高纪 RsMore()
int KCBPCLI_RsMore()
{
HINSTANCE hDll = LoadLibrary("d:\\windows_v5.2\\KCBPCli.dll");
int result = 0;
lpRsMore rsmore;

if(hDll!=NULL)
{
rsmore = (lpRsMore)GetProcAddress(hDll, "RsMore");
if(rsmore!=NULL)
{
result = rsmore();
}
FreeLibrary(hDll);
}
return result;
}


//write by 高纪 RsGetCursorName()
int KCBPCLI_RsGetCursorName(char *pszCursorName, int nLen)
{
HINSTANCE hDll = LoadLibrary("d:\\windows_v5.2\\KCBPCli.dll");
int result = 0;
lpRsGetCursorName getcursorname;

if(hDll!=NULL)
{
getcursorname = (lpRsGetCursorName)GetProcAddress(hDll, "RsGetCursorName");
if(getcursorname!=NULL)
{
result = getcursorname(pszCursorName, nLen);
}

FreeLibrary(hDll);
}
return result;
}

//lpRsFetchRow
//write by 高纪 RsFetchRow()
int KCBPCLI_RsFetchRow()
{
HINSTANCE hDll = LoadLibrary("d:\\windows_v5.2\\KCBPCli.dll");
int result = 0;
lpRsFetchRow fetchrow;

if(hDll!=NULL)
{
fetchrow = (lpRsFetchRow)GetProcAddress(hDll, "RsFetchRow");
if(fetchrow!=NULL)
{
result = fetchrow();
}
FreeLibrary(hDll);
}
return result;
}

//write by 高纪 RsGetCol()
int KCBPCLI_RsGetCol(int nLen, char *pszCursorName)
{
HINSTANCE hDll = LoadLibrary("d:\\windows_v5.2\\KCBPCli.dll");
int result = 0;
lpRsGetCol getcol;

if(hDll!=NULL)
{
getcol = (lpRsGetCol)GetProcAddress(hDll, "RsGetCol");
if(getcol!=NULL)
{
result = getcol(nLen,pszCursorName);
}
FreeLibrary(hDll);
}
return result;
}


//write by 高纪 RsGetCol()
int KCBPCLI_DisConnect()
{
HINSTANCE hDll = LoadLibrary("d:\\windows_v5.2\\KCBPCli.dll");
int result = 0;
lpDisConnect disconnect;

if(hDll!=NULL)
{
disconnect = (lpDisConnect)GetProcAddress(hDll, "DisConnect");
if(disconnect!=NULL)
{
result = disconnect();
}
FreeLibrary(hDll);
}
return result;
}






oyljerry 2009-07-02
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 weichenggao 的回复:]
应该怎么建立对象啊!

没有搞过C呀,头痛...

希望C板块的大哥大姐说详细点,谢谢!

[/Quote]
修改IDL,生成一个com对象,clsid,通过guidgen.exe来产生,这个工具在编译器的安装目录下有
当你用“VC工具ATL生成了一个空的com组件”之后,生成了一个名为“testDll.dll”的组件文件。
此时,你可能误以为“自己已经创建了一个组件”,其实,此时你创建的“testDll.dll”叫做“组件库”,你可以把这个“组件库”当作一个容器,它是用来存放组件的。
此时,你可以在testDll.idl文件中找到类似如下的代码:

[
uuid(8B595556-DEC6-446E-B933-C910DF869CD8),// 这个uuid是我的组件的,我只是为了给你说明一下。
version(1.0),
helpstring("testDll 1.0 类型库")
]
library testDll
{
importlib("stdole2.tlb");
};
以上代码表示,你创建了一个组件库,它的uuid是这些,“组件库”本身也有标识它的GUID的。

你要找的是clsid属性,clsid的意思是ClassId的缩写,也就是说是“组件类的ID”。

你“什么也不做”,说明你还没有创建一个组件,而没有组件哪里来的“组件类的ID”?而clsid也就不会被你找到。
理解了吗?
weichenggao 2009-07-02
  • 打赏
  • 举报
回复
应该怎么建立对象啊!

没有搞过C呀,头痛...

希望C板块的大哥大姐说详细点,谢谢!
fengrx 2009-07-02
  • 打赏
  • 举报
回复
使用向导刚建立的ATL控件没有clsid。

库library有uuid
事件dispinterface有uuid
接口interface有uuid
类coclass有uuid

其中类的uuid叫做clsid。在没有建立对象前是没有类的。
weichenggao 2009-07-02
  • 打赏
  • 举报
回复
我是按照默认向导做的,需要手动创建一个对象吗?应该怎么写呢?

VC默认生成的代码如下:
// tDll.cpp : Implementation of DLL Exports.


// Note: Proxy/Stub Information
// To merge the proxy/stub code into the object DLL, add the file
// dlldatax.c to the project. Make sure precompiled headers
// are turned off for this file, and add _MERGE_PROXYSTUB to the
// defines for the project.
//
// If you are not running WinNT4.0 or Win95 with DCOM, then you
// need to remove the following define from dlldatax.c
// #define _WIN32_WINNT 0x0400
//
// Further, if you are running MIDL without /Oicf switch, you also
// need to remove the following define from dlldatax.c.
// #define USE_STUBLESS_PROXY
//
// Modify the custom build rule for tDll.idl by adding the following
// files to the Outputs.
// tDll_p.c
// dlldata.c
// To build a separate proxy/stub DLL,
// run nmake -f tDllps.mk in the project directory.

#include "stdafx.h"
#include "resource.h"
#include <initguid.h>
#include "tDll.h"
#include "dlldatax.h"

#include "tDll_i.c"

#ifdef _MERGE_PROXYSTUB
extern "C" HINSTANCE hProxyDll;
#endif

CComModule _Module;

BEGIN_OBJECT_MAP(ObjectMap)
END_OBJECT_MAP()

/////////////////////////////////////////////////////////////////////////////
// DLL Entry Point

extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
lpReserved;
#ifdef _MERGE_PROXYSTUB
if (!PrxDllMain(hInstance, dwReason, lpReserved))
return FALSE;
#endif
if (dwReason == DLL_PROCESS_ATTACH)
{
_Module.Init(ObjectMap, hInstance, &LIBID_TDLLLib);
DisableThreadLibraryCalls(hInstance);
}
else if (dwReason == DLL_PROCESS_DETACH)
_Module.Term();
return TRUE; // ok
}

/////////////////////////////////////////////////////////////////////////////
// Used to determine whether the DLL can be unloaded by OLE

STDAPI DllCanUnloadNow(void)
{
#ifdef _MERGE_PROXYSTUB
if (PrxDllCanUnloadNow() != S_OK)
return S_FALSE;
#endif
return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
}

/////////////////////////////////////////////////////////////////////////////
// Returns a class factory to create an object of the requested type

STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
#ifdef _MERGE_PROXYSTUB
if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
return S_OK;
#endif
return _Module.GetClassObject(rclsid, riid, ppv);
}

/////////////////////////////////////////////////////////////////////////////
// DllRegisterServer - Adds entries to the system registry

STDAPI DllRegisterServer(void)
{
#ifdef _MERGE_PROXYSTUB
HRESULT hRes = PrxDllRegisterServer();
if (FAILED(hRes))
return hRes;
#endif
// registers object, typelib and all interfaces in typelib
return _Module.RegisterServer(TRUE);
}

/////////////////////////////////////////////////////////////////////////////
// DllUnregisterServer - Removes entries from the system registry

STDAPI DllUnregisterServer(void)
{
#ifdef _MERGE_PROXYSTUB
PrxDllUnregisterServer();
#endif
return _Module.UnregisterServer(TRUE);
}


  • 打赏
  • 举报
回复
你创建com对象了没有?
得创建一个对象才有
oyljerry 2009-07-02
  • 打赏
  • 举报
回复
com组件注册上的时候,注册表HKEY_CLASSES_ROOT\CLSID 下面有..

3,245

社区成员

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

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