惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
V
V2EX
WordPress大学
WordPress大学
Google DeepMind News
Google DeepMind News
Martin Fowler
Martin Fowler
小众软件
小众软件
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
The Cloudflare Blog
T
Tailwind CSS Blog
H
Help Net Security
腾讯CDC
爱范儿
爱范儿
人人都是产品经理
人人都是产品经理
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The GitHub Blog
The GitHub Blog
Microsoft Security Blog
Microsoft Security Blog
Stack Overflow Blog
Stack Overflow Blog
D
DataBreaches.Net
C
Check Point Blog
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com

博客园 - 简单生活

街霸4无法建立离线用户的问题 - 简单生活 - 博客园 尴尬 一个通过散列在文件夹里找出相同文件工具(译) googleTranslateApi 想改变一些习惯很难 史玉柱这个人值得研究 秀才造反十年不成(转载) PLSQL常用方法汇总(转载) 值得收藏的民间小偏方 最近事情超级多 勇敢挑起重担 POP3邮件客户端(.NET2.0)--译 关于webcast的wmv文件在windows2003播放声音问题 2007年抓的兔子太多了,结果没抓到一个。 笔记本交还公司了,伴随了我两年的家伙。 用VS2005打开一个.NET2.0方案,里面有几个工程和一个网站,提示网站的项目.csproj文件无法打开:“此安装不支持该项目类型”,的解决办法。 wcg2007总决赛sky和pj双双银牌 - 简单生活 - 博客园 顿悟 网站盈利模式分析总结十条(转载)
c/c++和.net之间相互调用
简单生活 · 2010-06-08 · via 博客园 - 简单生活

c/c++和.net之间相互调用,代码转换工具:

1.http://download.microsoft.com/download/f/2/7/f279e71e-efb0-4155-873d-5554a0608523/CLRInsideOut2008_01.exe

2.c++/c#互转工具

具体转换代码:

代码

 static object BytesToStruct(byte[] bytes, Type strcutType)
        {
int size = Marshal.SizeOf(strcutType);
            IntPtr buffer 
= Marshal.AllocHGlobal(size);
            
try
            {
                Marshal.Copy(bytes, 
0, buffer, size);
                
return Marshal.PtrToStructure(buffer, strcutType);
            }
            
catch (Exception ex)
            {
                Console.Write(
"BytesToStruct,error{0}\r\n", ex.ToString());
                
return null;
            }
            
finally
            {
                Marshal.FreeHGlobal(buffer);
            }
        }
        
static byte[] StructToBytes(object structObj)
        {
            
int size = Marshal.SizeOf(structObj);
            IntPtr buffer 
= Marshal.AllocHGlobal(size);
            
try
            {
                Marshal.StructureToPtr(structObj, buffer, 
false);
                
byte[] bytes = new byte[size];
                Marshal.Copy(buffer, bytes, 
0, size);
                
return bytes;
            }
            
finally
            {
                Marshal.FreeHGlobal(buffer);
            }

        }