当前位置:编程学习 > C#/ASP.NET >>

DLL调用问题

本人菜鸟,恳请大家指点。
C++的MFC   DLL7.dll:
typedef struct Rssi
{
int rss;
char* mac ;
}Rssi;

_declspec(dllexport) void Ap_scan(Rssi* mesh)
{
mesh->mac="this is mac address!";
mesh->rss=80;
return;
}


在c#中调用:
   public  struct Rssi
    {
          public int rss;
          public String mac;
    }

        [DllImport("Dll7.dll")]
        public static extern void Ap_scan(ref Rssi ap);
         Rssi _ap;

        public Form1()
        {
            InitializeComponent();
        }

        private void scan_Click(object sender, EventArgs e)
        {
           Ap_scan( ref _ap);//此处报错:尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
           
        }
大家指点下小弟,谢谢 --------------------编程问答-------------------- Rssi _ap = new Rssi(); --------------------编程问答-------------------- mesh->mac="this is mac address!";

也不能这么写。 --------------------编程问答--------------------

引用 2 楼 caozhy 的回复:
mesh->mac="this is mac address!";

也不能这么写。



为什么不能这么写啊?将常量指针赋值给非const修饰的char指针难道不可以吗?只要我在后来的程序中不修改这个指针所指向的内容,这么写结果对啊。望指点 --------------------编程问答--------------------
引用 2 楼 caozhy 的回复:
mesh->mac="this is mac address!";

也不能这么写。


引用 2 楼 caozhy 的回复:
mesh->mac="this is mac address!";

也不能这么写。



版主,这个DLL返回的是一个结构体指针。。。但是如果要返回结构体数组呢?C#该采用何种调用形式?
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,