如何从c#返回列表,并使用它在vc ++通过com
如何从c#方法返回列表并使用c ++中的列表返回值可以指导如何做?
我将按照以下方式完成整个场景:
How to return List from c# method and Use the List return values in c++ can u give guidance how to do it??
I going like following way my complete scenario:
在c#DemoLib.cs
in c# DemoLib.cs
usng System;using System.Collections.Generic;
public interface IDiscover
{
void GetList1();
String GetList2();
List<string> GetList3();
};
namespace DemoLibrary
{
class DemoLib
{
public void GetList1()
{
Console.WriteLine(" I am from Void GetList()");
}
public string GetList2()
{
Console.WriteLine(" I am from string GetList()");
return "Stack OverFlow";
}
public List<string> GetList3()
{
List<string> li=new List<string>();
li.Add("India");
li.Add("America");
li.Add("London");
Console.WriteLine(" I am from List<string> GetList()");
return li;
}
已成功构建并创建DemoLib.dll
Build successfully and created DemoLib.dll
我将DemoLib.dll复制到c:\DemoLib.dll,并使用regasm在c:\
I copy the DemoLib.dll to c:\DemoLib.dll and using regasm created Demolib.tlb in c:\
i Hav main()
Now in Vc++ i Hav main()
DemoLibMain.vc ++
DemoLibMain.vc++
#include<list>
#include<stdio.h>
void main()
{
HRESULT Hr=CoInitialize(NULL);
IDiscoverPtr Iptr(__uuidof(DemoLib));
Iptr->GetList1();
std::string str=Iptr->GetList2();
printf("%s",str); //dispalys "null" insted of "stack overflow" but when i debugging it
shows the value "stack overflow" at str.
Iptr - >(Afraid,因为它没有给GetList3())
Iptr->(Afraid since it doesnot give GetList3() )
当我强制写Iptr-> GetList3()它显示错误为
when i forced to write Iptr->GetList3() it Display the error as
GetList3不是成员of IDiscover;
GetList3 is not a member of IDiscover;
昨天同样的问题:
(简短答案:列表不会包含在COM接口中,因为它使用通用类型)。
(Short answer: List won't be included in the COM interface because it uses a generic type).