码迷,mamicode.com
首页 > 编程语言 > 详细

C++/C# 最基本的Marshal和Ptr

时间:2015-11-10 15:38:39      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:

Vidyo32.VidyoClientInEventLogin Login = new Vidyo32.VidyoClientInEventLogin();

 

            Login.portalUri = this.tbxIP.Text.Trim(); //"http://kaunas.vidyo.scandihealth.net";

            Login.userName = this.tbxID.Text.Trim(); //"test-sa3";

            Login.userPass = this.tbxPwd.Text.Trim(); //"test-sa3";

 

 

 

            int size = Marshal.SizeOf(Login);

            IntPtr ptr = Marshal.AllocCoTaskMem(size);

            Marshal.StructureToPtr(Login, ptr, false);

 

            Int32 test = Vidyo32.VidyoClientSendEvent(Vidyo32.VidyoClientInEvent.VIDYO_CLIENT_IN_EVENT_LOGIN, ptr, size);

            Login = (Vidyo32.VidyoClientInEventLogin)Marshal.PtrToStructure(ptr, typeof(Vidyo32.VidyoClientInEventLogin));

 

 

在此总结一句,C++结构体和C#结构体转换过程中,一定要注意内存大小一致

C++/C# 最基本的Marshal和Ptr

标签:

原文地址:http://www.cnblogs.com/acdyf/p/4953048.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!