C#中使用COM组件的问题

yingjohnway 2009-11-29 08:19:47
我在C#中使用别人用C++写的一个COM组件,注册后,添加引用以及在对象浏览器内看不到这个组件。但我在C++中使用调用接口的方法可以使用,小弟对COM的细节了解不深,请求各位大侠能够指点一二,谢了!

那个COM组件用C++调用时tlh文件内的内容是这样的

#pragma once
#pragma pack(push, 8)

#include <comdef.h>

//
// Forward references and typedefs
//

struct __declspec(uuid("a6d6dc95-e289-47ce-b3fa-bff7ddf24eb1"))
/* LIBID */ __IMYPlugInLib;
struct /* coclass */ IMYPlugIn;
struct __declspec(uuid("8c0cee76-706b-4de9-85e3-977d967e0925"))
/* dual interface */ IMYComPlugIn;

//
// Smart pointer typedef declarations
//

_COM_SMARTPTR_TYPEDEF(IMYComPlugIn, __uuidof(IMYComPlugIn));

//
// Type library items
//

struct __declspec(uuid("5ee60022-1270-4fcb-b53d-a2a6fbaaa3b5"))
IMYPlugIn;
// [ default ] interface IMYComPlugIn

struct __declspec(uuid("8c0cee76-706b-4de9-85e3-977d967e0925"))
IMYComPlugIn : IDispatch
{
//
// Raw methods provided by interface
//

接口方法不列出了~~~~

};

//
// Named GUID constants initializations
//

extern "C" const GUID __declspec(selectany) LIBID_IMYPlugInLib =
{0xa6d6dc95,0xe289,0x47ce,{0xb3,0xfa,0xbf,0xf7,0xdd,0xf2,0x4e,0xb1}};
extern "C" const GUID __declspec(selectany) CLSID_IMYPlugIn =
{0x5ee60022,0x1270,0x4fcb,{0xb5,0x3d,0xa2,0xa6,0xfb,0xaa,0xa3,0xb5}};
extern "C" const GUID __declspec(selectany) IID_IMYComPlugIn =
{0x8c0cee76,0x706b,0x4de9,{0x85,0xe3,0x97,0x7d,0x96,0x7e,0x09,0x25}};

#pragma pack(pop)
...全文
172 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
CCppMfc 2009-11-30
  • 打赏
  • 举报
回复
try again?
feifeiyiwen 2009-11-30
  • 打赏
  • 举报
回复
yingjohnway 2009-11-30
  • 打赏
  • 举报
回复
添加引用 浏览文件,会报:未能添加的错误。

现猜测是COM的注册信息不全的原因,但也不确定。还有试了一下利用Javascript中ActiveXObject调用接口也不能实例化,但是提供COM的人直接在HTML中加载组件却可以正确加载。在C++中可以正常加载此COM组件。
足球中国 2009-11-30
  • 打赏
  • 举报
回复
添加引用 浏览文件
yingjohnway 2009-11-29
  • 打赏
  • 举报
回复
注册成功了,但是添加引用->COM里面找不到,对象浏览器也找不到,但是用C++的调用方式可以调用
hansuzhi 2009-11-29
  • 打赏
  • 举报
回复
如果注册了,添加引用也成功了,应该可以看到啊
帮你顶~~

111,123

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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