简体   繁体   English

COM对象c ++ / cli

[英]COM object c++/cli

I am trying to use the the maged c++/cli assembly as an object within html. 我正在尝试使用maged c ++ / cli程序集作为html中的对象。

<object classid="http://127.0.0.1/xxx/yyy_CLI.dll#FooClass" id="dummy" ></object>

The class seems like that 上课好像

#pragma once

using namespace System;
using namespace System::Runtime::InteropServices;

[Guid("D81FDD51-ABB0-480b-A5F9-0DE209C8456E")]
[ComVisibleAttribute(true)]
public interface class IFooClass
{
    virtual void Initialize() = 0;
};

[Guid("D0556663-B16C-403f-B6E1-C5154BE54EF9")]
[ComVisibleAttribute(true)]
public ref class FooClass: public IFooClass
{
public:
    FooClass(void);
    virtual ~FooClass(void);

    virtual void Initialize();

};

However when javascript is trying to call the Initialize method it says "...Error: Object doesn't support this property or method..." 但是,当javascript尝试调用Initialize方法时,它会显示“ ...错误:对象不支持此属性或方法...”。

What am I doing wrong? 我究竟做错了什么?

I might be way off here, it's been ages since I touched COM, but here it goes: 我可能离这里很远,自从接触COM以来已经有很多年了,但是在这里:

I think you need to set the Interface type via the InterfaceType attribute. 我认为您需要通过InterfaceType属性设置接口类型。 something like: 就像是:

[InterfaceType(ComInterfaceType::InterfaceIsDual)]
[Guid("D81FDD51-ABB0-480b-A5F9-0DE209C8456E")]
[ComVisibleAttribute(true)]
public interface class IFooClass
{
...
}

Also, you need to export the managed classes to COM with the Tlbexp.exe (Type Library Exporter). 另外, 您需要使用Tlbexp.exe (类型库导出器) 将托管类导出到COM

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM