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

推荐订阅源

WordPress大学
WordPress大学
Microsoft Security Blog
Microsoft Security Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
V
Visual Studio Blog
宝玉的分享
宝玉的分享
IT之家
IT之家
人人都是产品经理
人人都是产品经理
T
The Blog of Author Tim Ferriss
I
InfoQ
B
Blog RSS Feed
T
Threatpost
博客园_首页
M
MIT News - Artificial intelligence
Spread Privacy
Spread Privacy
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Know Your Adversary
Know Your Adversary
U
Unit 42
Engineering at Meta
Engineering at Meta
C
Cyber Attacks, Cyber Crime and Cyber Security
月光博客
月光博客
Scott Helme
Scott Helme
T
Tor Project blog
有赞技术团队
有赞技术团队
AWS News Blog
AWS News Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Last Week in AI
Last Week in AI
S
Schneier on Security
Vercel News
Vercel News
博客园 - Franky
C
Cybersecurity and Infrastructure Security Agency CISA
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
L
LangChain Blog
爱范儿
爱范儿
Google DeepMind News
Google DeepMind News
The GitHub Blog
The GitHub Blog
雷峰网
雷峰网
Latest news
Latest news
C
CXSECURITY Database RSS Feed - CXSecurity.com
Hugging Face - Blog
Hugging Face - Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
G
GRAHAM CLULEY
S
Security Affairs
A
About on SuperTechFans
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
大猫的无限游戏
大猫的无限游戏
W
WeLiveSecurity
Cisco Talos Blog
Cisco Talos Blog
罗磊的独立博客

博客园 - 简单生活

街霸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);
            }

        }