当前位置:网站首页>C#引入WINAPI传递中文字符串参数字符集问题
C#引入WINAPI传递中文字符串参数字符集问题
2022-07-28 00:50:00 【foenix66】
C#引入WINAPI传递中文字符串参数字符集问题
C#可以通过DllImport引入WinAPI。完整的引入语句包含dll文件名(路径),CharSet字符集,EntryPoint函数入口,SetLastError是否在调用前设置WinAPI函数SetLastError值
[DllImport("user32.dll", CharSet = CharSet.Auto, EntryPoint = "MessageBox", SetLastError=false)]
public static extern int MyMessageBox(IntPtr hWnd, String text, String caption, uint type);
CharSet默认值是并不是CharSet.Auto,而是CharSet.Ansi
WinAPI函数的字符串参数所用字符集在不同版本的Windows系统并不统一,XP以前的系统通常是Ansi字符集,Windows7和NT系统是Unicode字符集。通常使用CharSet.Auto参数,让系统自动选择总是没错的(但不知道默认参数为什么不是CharSet.Auto),除非你指定调用AbcW宽字符集或AbcA窄字符集的函数版本。
如果你没有指定CharSet,系统默认使用CharSet.Ansi,如果传递中文字符串,大概率是会调用失败,或者出现乱码的。
边栏推荐
- Software testing interview question: why should we carry out testing in a team?
- Codeworks round 810 (Div. 2) a~c problem solution
- day7
- 都在说DevOps,你真正了解它吗?
- 华为APP UI自动化测试岗面试真题,真实面试经历。
- N32l43x FLASH read \ write \ erase operation summary
- 11-Django-基础篇-数据库操作
- Likeshop takeout ordering system [100% open source, no encryption]
- Huawei app UI automation test post interview real questions, real interview experience.
- Behind every piece of information you collect, you can't live without TA
猜你喜欢

Record a production deadlock

Completely delete MySQL in Linux system

Flex开发网页实例web端

Hcip 13th day notes

Embedded classic communication protocol

11 Django basics database operation
![Likeshop takeout ordering system [100% open source, no encryption]](/img/e6/a73aa817b5b30339d755aa53708072.png)
Likeshop takeout ordering system [100% open source, no encryption]

Traversal and properties of binary trees

云原生爱好者周刊:Prometheus 架构演进之路

QGIS制图:矢量数据制图流程及导出
随机推荐
对话Atlassian认证专家叶燕秀:Atlassian产品进入后Server时代,中国用户应当何去何从?
54: Chapter 5: develop admin management services: 7: face warehousing process; Face login process; The browser turns on the video debugging mode (so that the camera can also be turned on in the case o
mysql创建存储过程---------[HY000][1418] This function has none of DETERMINISTIC, NO SQL
Hcip 13th day notes
Principle and implementation of cross entropy
The cooperation between starfish OS and metabell is just the beginning
Flex开发网页实例web端
小米网站主页面大模块——小模块+导航(浮动案例)
Packet capturing wizard netcapture app packet capturing tutorial "complete"
Codeworks round 810 (Div. 2) a~c problem solution
mongodb/mongoTemplate.upsert批量插入更新数据的实现
软考 --- 数据库(2)关系模型
Use of classes in typescript
Embedded classic communication protocol
损失函数-交叉熵的原理及实现
Typescript中类的使用
Software testing interview question: what do you think is the key to good test case design?
WMS you don't know
Data output - image annotation and annotation
FreeRTOS kernel summary