在 D 中使用 windows dll 的正确方法?
我有一个小 dll,我想与 D 语言一起使用。我假设它是用 C 编写的。这些是我有权访问的文件,它们与我的程序存在于同一目录中。:
- b3d.dll
- blitz3dsdk.exp
- blitz3dsdk.lib
- blitz3dsdk.h
这是我尝试过的让D使用这个dll。
test.d
pragma(lib, "blitz3dsdk.lib");
int main(string[] Args)
{
bbBeginBlitz3D();
bbEndBlitz3D();
return 0;
}
编译: dmd test.d -w -wi -debug
结果: 错误 43:不是有效的库文件。
Blitz3DSDK.d
module Blitz3DSDK;
// __declspec(dllimport) int bbBeginBlitz3D() - from the header file.
export extern (Windows) int bbBeginBlitz3D();
// __declspec(dllimport) void bbEndBlitz3D() - from the header file.
export extern (Windows) void bbEndBlitz3D();
test.d
import Blitz3DSDK;
int main(string[] Args)
{
bbBeginBlitz3D();
bbEndBlitz3D();
return 0;
}
编译: dmd test.d -w -wi -debug
结果: 错误 42:符号未定义 _bbBeginBlitz3D@0
错误 42:符号未定义 _bbEndBlitz3D@0
有关如何使用此 dll 的任何想法或任何有用的信息迄今为止的在线指南将不胜感激。我已经有一段时间没有摆弄本机代码和共享库等了。
I have a small dll that i want to use with the D language. I'm assuming it has been written in C. These are the files i have access to and they exist in the same directory as my program.:
- b3d.dll
- blitz3dsdk.exp
- blitz3dsdk.lib
- blitz3dsdk.h
Here's what i've tried to get D to use this dll.
test.d
pragma(lib, "blitz3dsdk.lib");
int main(string[] Args)
{
bbBeginBlitz3D();
bbEndBlitz3D();
return 0;
}
Compile: dmd test.d -w -wi -debug
Result: Error 43: Not a Valid Library File.
Blitz3DSDK.d
module Blitz3DSDK;
// __declspec(dllimport) int bbBeginBlitz3D() - from the header file.
export extern (Windows) int bbBeginBlitz3D();
// __declspec(dllimport) void bbEndBlitz3D() - from the header file.
export extern (Windows) void bbEndBlitz3D();
test.d
import Blitz3DSDK;
int main(string[] Args)
{
bbBeginBlitz3D();
bbEndBlitz3D();
return 0;
}
Compile: dmd test.d -w -wi -debug
Result: Error 42: Symbol Undefined _bbBeginBlitz3D@0
Error 42: Symbol Undefined _bbEndBlitz3D@0
Any ideas how to use this dll or any helpful up to date online guides would be appreciated. It's been a while since i've fiddled with native code and shared libraries, etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
库文件可能是COFF 格式。使用
coffimplib
将其转换为可与 D 链接器一起使用的 OMF 库,或使用implib
从 DLL 创建导入库。export
用于从 DLL 导出函数,而不是用于导入函数。The library file is probably in the COFF format. Use
coffimplib
to convert it to an OMF library usable with D's linker, orimplib
to create an import library from the DLL.export
is used when exporting functions from a DLL, not for importing them.按照 CyberShadow 的建议,我使用
coffimplib
工具将blitz3dsdk.lib
文件转换为 OMF 格式,并使用编译指示导入该文件。然后,我定义了它包含在extern (C)
块内的外部函数。示例:
我按照 此页面的指南尝试了此 dll 中的更多功能 用于某些类型的转换等,一切都很好。
Following CyberShadow's advice i used the
coffimplib
tool to convert theblitz3dsdk.lib
file to be in OMF format and imported that using a pragma. I then defined the external functions it contains inside anextern (C)
block.Example:
I've tried it with a few more functions from this dll following the guideline from this page for conversion of some types, etc and all works great.