问题描述
我在我的C ++ COM服务器中使用一个C#COM DLL,它实现了IEnumerable来遍历集合。
-
我在我的本地代码中指定,我想从C#Dll的实例对象访问IEnumerable - > GetEnumerator()方法?为了在我的C ++项目中看到IEnumerable接口,我必须导入一些* .tlb吗?我可以进一步暴露一个IEnumerable接口给我的客户端(在我的C +项目中的IDL中定义)。一个示例是有帮助的
导出器,System.Collections.IEnumerable是[ComVisible],并转换为IEnumVARIANT。例如:
使用System;
using System.Collections;
using System.Runtime.InteropServices;
[ComVisible(true),InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IExample {
IEnumerator GetEnumerator();
}
[ComVisible(true),ClassInterface(ClassInterfaceType.None)]
public class示例:IExample {
public IEnumerator GetEnumerator(){
产量回报42;
}
}
已翻译为此类型库片段:
// TLib:// TLib:mscorlib.dll:{BED7F4EA-1A96-11D2-8F08-00A0C9A6186D}
importlib mscorlib.tlb);
// TLib:OLE自动化:{00020430-0000-0000-C000-000000000046}
importlib(stdole2.tlb);
//转发声明这个typelib中定义的所有类型
interface IExample;
[
odl,
uuid(9B046FDE-9234-3DE7-B055-DADE8F7B4A99),
版本(1.0),
dual,$ b $
custom
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9,IExample)
]
interface IExample:IDispatch {
[id(0xfffffffc) ]
HRESULT GetEnumerator([out,retval] IEnumVARIANT ** pRetVal);
};
注意mscorlib.tlb的importlib指令,出现在c:\windows\microsoft.net \framework\v2.0.50727,由编译器在没有帮助的情况下找到。
I use in my C++ COM server a C# COM DLL that implements IEnumerable for iterating over a collection.
How do I specify in my native code that I want to access IEnumerable -> GetEnumerator() method from the instance object of C# Dll ? Do I have to import some *.tlb in order to see IEnumerable interface in my C++ project ? Ienumerable interface I saw is defined by mscorelib.dll
Can I further expose an IEnumerable interface to my clients (defined in IDL in my C+ project). An example would be helpful
It is automatically translated by the type library exporter, System.Collections.IEnumerable is [ComVisible] and gets translated to IEnumVARIANT. For example:
using System;
using System.Collections;
using System.Runtime.InteropServices;
[ComVisible(true), InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IExample {
IEnumerator GetEnumerator();
}
[ComVisible(true), ClassInterface(ClassInterfaceType.None)]
public class Example : IExample {
public IEnumerator GetEnumerator() {
yield return 42;
}
}
Gets translated to this type library fragment:
// TLib : // TLib : mscorlib.dll : {BED7F4EA-1A96-11D2-8F08-00A0C9A6186D}
importlib("mscorlib.tlb");
// TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
importlib("stdole2.tlb");
// Forward declare all types defined in this typelib
interface IExample;
[
odl,
uuid(9B046FDE-9234-3DE7-B055-DADE8F7B4A99),
version(1.0),
dual,
oleautomation,
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "IExample")
]
interface IExample : IDispatch {
[id(0xfffffffc)]
HRESULT GetEnumerator([out, retval] IEnumVARIANT** pRetVal);
};
Note the importlib directive for mscorlib.tlb, present in c:\windows\microsoft.net\framework\v2.0.50727 and found by the compiler without help.
这篇关于COM - 在ATL C ++项目中使用IEnumerable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!