本文介绍了管理与非管理之间的传递结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将一个结构包含另一个结构指针,该结构从C#传递到非托管C ++/COM.将数组分配给结构内的结构指针时出现错误.我不确定,这是否受支持,或者我做错了什么? 这将是很大的帮助,有人可以为我指明正确的方向.
I'm trying to pass a structure that has another structure pointer inside to unmanaged C++/COM from C#. I'm getting an error when assigning array to structure pointer inside a structure. I'm not sure, is this something supported or I'm doing something wrong? It would be great help, somebody could point me to right direction.
C++/MFC - win32-----------------[export]typedef struct Person{ BSTR personName; BSTR city;}[export]typedef struct Persons{ Person *pPersonList; //I have other information in structure that I need receive as a group of information.}BOOL GetPersons(Person *pPerson);BOOL GetPersonList(Persons *pPersonList); c#---Person[10] personList = new Person[10];for(iint i=0;i<10;i++){ Person person = new Person(); person.personName = "Name " + i; personList[i] = person;}GetPersons(ref personList); //worksPersons persons = new Persons();persons.pPersonList = personList; //ErrorGetPersonList(ref persons);Error:-----Cannont implicitly convert type Person[] to 'System.IntPtr'
when I see structure definition in c#, this is how it shows.typedef struct Persons{ IntPtr pPersonList; }
我该如何解决?
谢谢.
推荐答案
这篇关于管理与非管理之间的传递结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!