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

Open
nobodxbodon opened this Issue Jul 28, 2018 · 6 comments

Comments

4 participants
@nobodxbodon
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

This comment has been minimized.

Show comment
Hide comment
@nobodxbodon

nobodxbodon Jul 28, 2018

Member

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

Member

nobodxbodon commented Jul 28, 2018

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

@nobodxbodon

This comment has been minimized.

Show comment
Hide comment
@nobodxbodon

nobodxbodon Jul 28, 2018

Member

尝试根据官方文档创建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

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

Member

nobodxbodon commented Jul 28, 2018

尝试根据官方文档创建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

This comment has been minimized.

Show comment
Hide comment
@swizl

swizl Jul 28, 2018

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

swizl commented Jul 28, 2018

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

@nobodxbodon

This comment has been minimized.

Show comment
Hide comment
@nobodxbodon

nobodxbodon Jul 28, 2018

Member

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

Member

nobodxbodon commented Jul 28, 2018

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

@absente absente added this to related in E2030 Jul 29, 2018

@nobodxbodon

This comment has been minimized.

Show comment
Hide comment
@nobodxbodon

nobodxbodon Jul 29, 2018

Member

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

Member

nobodxbodon commented Jul 29, 2018

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

@nobodxbodon

This comment has been minimized.

Show comment
Hide comment
@nobodxbodon

nobodxbodon Aug 1, 2018

Member

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

Member

nobodxbodon commented Aug 1, 2018

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

@nobodxbodon nobodxbodon reopened this Aug 1, 2018

@absente absente added this to the 2018戊戌 milestone Aug 9, 2018

@nobodxbodon nobodxbodon added 调研 and removed n笔记/总结 labels Aug 13, 2018

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