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

用go编译win32的dll 怎么指定 _stdcall 的调用约束 #34466

Closed
dzwvip opened this issue Sep 23, 2019 · 6 comments
Closed

用go编译win32的dll 怎么指定 _stdcall 的调用约束 #34466

dzwvip opened this issue Sep 23, 2019 · 6 comments

Comments

@dzwvip
Copy link

dzwvip commented Sep 23, 2019

What version of Go are you using (go version)?

$ go version

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

What did you expect to see?

win32 程序调用 dll 默认的_stdcall方式, 用 go编译的dll 不能直接调用,我看 #32851 里面
https://github.com/code34/armago_x64 使用 C 函数 又包装了一下,可以使用了,但是又不想导出的函数名称后面 带有 @n ,该怎么解决 ??

What did you see instead?

@zouhuigang
Copy link

我用这个库试了下,生成的armago_x64.h,没发现你说的参数有@n啊!

 extern void goRVExtensionVersion(char* p0, size_t p1);
 extern void goRVExtensionArgs(char* p0, size_t p1, char* p2, char** p3, int p4);
 extern void goRVExtension(char* p0, size_t p1, char* p2)

@ianlancetaylor
Copy link
Contributor

Would somebody like to translate this into English? Thanks. I tried Google Translate but it wasn't clear.

@zouhuigang
Copy link

He said that DLL compiled with go could not be used by other Win32 programs.

@ianlancetaylor
Copy link
Contributor

Thanks. Closing as dup of #22192.

@toy-lin
Copy link

toy-lin commented Feb 7, 2020

The question is how to export WINAPI entry point without decoration.

As i know, this can export an c entry point, exported entry name would be "SayHello":

//export
func SayHello(){
  doSomething()
}

And #32851 offered a way to export WINAPI by using cgo, exported entry name would be "_SayHello@0":

#include <stdlib.h>
extern void goSayHello();
__declspec(dllexport) void __stdcall SayHello() {
  goSayHello();
}

But i want the entry name to be "SayHello", how could i do?

I have tried this answer 2 to add a comment in C code. The compile result is ok, but it didn't work(the entry name is still "_SayHello@0"):

#include <stdlib.h>
extern void goSayHello();
__declspec(dllexport) void __stdcall SayHello() {
  #pragma comment(linker, "/EXPORT:SayHelo=_SayHello@0")
  // or #pragma comment(linker, "/EXPORT:"__FUNCTION__"="__FUNCDNAME__)
  goSayHello();
}

Currently i am using CMAKE to build a dynamic library as intermediary. Adding a .def file to CmakeLists.txt works fine.
But i am still looking for a simple solution i could do this without an intermediary.

@dzwvip 请问你找到解决方案了吗?

@dzwvip
Copy link
Author

dzwvip commented Feb 7, 2020 via email

@golang golang locked and limited conversation to collaborators Feb 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants