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

推荐订阅源

Martin Fowler
Martin Fowler
V
Visual Studio Blog
有赞技术团队
有赞技术团队
T
Tailwind CSS Blog
B
Blog
I
InfoQ
博客园 - 三生石上(FineUI控件)
阮一峰的网络日志
阮一峰的网络日志
F
Fortinet All Blogs
H
Help Net Security
博客园 - Franky
宝玉的分享
宝玉的分享
博客园 - 司徒正美
C
Check Point Blog
G
Google Developers Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Jina AI
Jina AI
T
The Blog of Author Tim Ferriss
MongoDB | Blog
MongoDB | Blog
云风的 BLOG
云风的 BLOG
A
About on SuperTechFans
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家

博客园 - 步走高飞

[ios5 斯坦福大学2011fall][6.[第6集] 多个MVC和延续符]中的psychologist Demo [ios5 斯坦福大学2011fall][5.Protocols.and.Gestures]中的happiness Demo [ios5 斯坦福大学2011fall]assignment 2实现的代码和截图 myeclipse7.5注册码得计算类 zz如何设置mysql远程访问 ps axu命令详解 zzApache ab命令做简单的性能测试 loadrunner11和QTP 11的下载地址(含破解) Httpwatch中http状态码列表 zzspring和Hibernate整合时候的asm包冲突 java ee环境配置 django拾遗 python环境配置 组件编程总结笔记 G7使用小技巧 Android开发环境搭建过程记录 Java环境安装步骤快速入门简要 背包0-1问题不详细解释 我对公司人脸产品的看法
互操作里传递字符串的烦心事
步走高飞 · 2011-03-28 · via 博客园 - 步走高飞

第一:char[n]别随便转为string,string会自动给你截取‘\0’,结果还是不对,还是老老实实的把c++的char[n]转为c#的char[n]

 // PST数据头

struct SQPstHeader

{

char szVer[5];

char szExt[3];

int  nWorkStep;

int bManuBW;     

int nAutoThres;

int  nManuThres;

};

 [StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Ansi)]

    public struct SQPstHeader {

        /// char[5]

        [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst=5)]

        public char[] szVer;

        /// char[3]

        [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 3)]

        public char[] szExt;

        /// int

        public int nWorkStep;

        /// int

        public int bManuBW;

        /// int

        public int nAutoThres;

        /// int

        public int nManuThres;

    }

 第二,传给c++中的字符串LPCTSTR 得注意编码,要不然用c#的string dllimport方式传过去就是乱码。下面这个加了CharSet = CharSet.Unicode就对了。

c++:DLLEXPORT  SQPstData* STDCALL LoadPst70( LPCTSTR lpszFile );

 c#:       [DllImportAttribute("xxxx.dll", EntryPoint = "LoadPst70", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]

        public static extern IntPtr LoadPst70(string lpszFile); 

先记这么两个,我觉得肯定不只这么两个的,以后再补充。