Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在Windows上编写DLL时不能使用中文命名 #74

Closed
nobodxbodon opened this issue Jul 28, 2018 · 7 comments
Closed

在Windows上编写DLL时不能使用中文命名 #74

nobodxbodon opened this issue Jul 28, 2018 · 7 comments

Comments

@nobodxbodon
Copy link
Member

nobodxbodon commented Jul 28, 2018

https://zhuanlan.zhihu.com/p/30529835 文后最新评论报告此问题. 需研究影响与对策.

参考:
GetProcAddress官方文档


有一个事实直接反对在Windows上编写DLL时使用中文命名。

<<Windows核心编程第五版>>(中文版)Page 532

说:

"注意:参数pszSymbolName

...

这是因为编译器/链接器始终都是将符号的名称以ANSI字符串的形式保存的"

于是在编写DLL时导出的符号名一定不能用中文。

由于这书是多年以前的,我还亲自做了实验。

实验环境是

VS2017 Version 15.7

Windows10 Pro x64 1803

Visual C++

实验表明,用中文命名的导出符号无法以符号名的形式被导入,无论是动态还是静态。

虽然这个事实只是针对DLL,但DLL是Windows最重要的组成部分之一。


@nobodxbodon
Copy link
Member Author

请有windows开发经验的看看?
看到Having a generic function GetProcAddress for both unicode and ascii builds - fails in release mode, 虽然好像是不同问题.
考虑通过ANSI<->Unicode将中文符号转换为ANSI对应字符串, 作为GetProcAddress的第二个参数, 不知是否可行?

@nobodxbodon
Copy link
Member Author

尝试根据官方文档创建dll并调用, 但未重现问题.
VS community 2017, v15.7.5
Windows 7 pro

MathLibrary.cpp中新添中文名接口:

static MATHLIBRARY_API double 加(double a, double b);

MathClient.cpp中新添:

	cout << "a 加 b = " <<
		MathLibrary::Functions::加(a, b) << endl;

运行输出:

a 加 b = 106.4

先问问报告者可否分享测试代码.

@swizl
Copy link

swizl commented Jul 28, 2018

用GCC、clang试了吗?这应该是编译器实现的问题,不是系统层面的问题。
就算gcc、clang也是这么实现的,理论上是可以改成utf8或unicode的。

@4b5ent1 4b5ent1 added the 笔记 label Jul 28, 2018
@nobodxbodon nobodxbodon added the 求助 help wanted label Jul 28, 2018
@nobodxbodon
Copy link
Member Author

@swizl 上面的中文命名用vs编译运行是成功的. 所以最好拿到报告者的测试代码, 再尝试复现.

@nobodxbodon
Copy link
Member Author

已演示在对DLL库中的接口进行中文命名. 如发现新问题请重开此贴.

@nobodxbodon
Copy link
Member Author

用户回馈, 静态调用确定没有问题. 但GetProcAddress不能获取方法指针.
尝试了#74 (comment) 的思路, 仍未成功. 查看dll接口如下, 感觉通过转码还是有可能?
dll_getprocaddress_dependency

@nobodxbodon nobodxbodon reopened this Aug 1, 2018
@4b5ent1 4b5ent1 added this to the 2018戊戌 milestone Aug 9, 2018
@nobodxbodon
Copy link
Member Author

个人暂不打算继续研究. 如发现实例需求或有兴趣探索请重开此贴.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants