pinvoke 数据交互笔记_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > pinvoke 数据交互笔记

pinvoke 数据交互笔记

 2013/8/2 12:08:55  不要急,没问题  博客园  我要评论(0)
  • 摘要:intptrtoarraystringstring[]_outputStrArray=null;intchannelCount=0;///返回数组大小IntPtrChannels=newIntPtr();intreslut=NativeMethods.getChannels(Global.Handle,nru,refChannels,refchannelCount);if(reslut==0)//将指针数据转换为string数组
  • 标签:笔记 数据

intptr to array string

string[]  _outputStrArray=null;

     int channelCount = 0;///返回数组大小
            IntPtr Channels = new IntPtr();
          
            int reslut = NativeMethods.getChannels(Global.Handle, nru, ref Channels, ref channelCount);
            if (reslut == 0) //将指针数据转换为string 数组
            {
                IntPtr[] OutPointers = new IntPtr[channelCount];
                Marshal.Copy(Channels, OutPointers, 0, channelCount);
                _outputStrArray = new string[channelCount];
                for (int i = 0; i < channelCount; i++)
                {
                    _outputStrArray[i] = Marshal.PtrToStringAnsi(OutPointers[i]);
                }
            }

结构体数组指针

定义结构体

 public struct out_TMitObjIdKVPair
    {

...

...

..

}

IntPtr timitobjs = new IntPtr();

 int count = 0;

 int result = NativeMethods.getSubObjs(Global.Handle, par, ref timitobjs, ref count);
            if (result == 0)
            {
                for (int i = 0; i < count; i++)
                {
                    out_TMitObjIdKVPair q = (out_TMitObjIdKVPair)Marshal.PtrToStructure((IntPtr)(timitobjs.ToInt32() + i * Marshal.SizeOf(typeof(out_TMitObjIdKVPair))), typeof(out_TMitObjIdKVPair));

}

}

 

发表评论
用户名: 匿名