cgo: Is it possible to make exported function have __stdcall calling convention?

297 views
Skip to first unread message

Konstantin Khomoutov

unread,
Oct 29, 2022, 8:23:36 AM10/29/22
to golan...@googlegroups.com
Hi!

I have a need to create a Windows i386 DLL whose exported functions have
__stdcall calling convention - this is the requirement of the piece of
software which is to load and call this DLL; we cannot change the caller, and
have to adapt to its requirements.

The only approach I was able to find so far is to export the Go function under
a different name and have a separate C file with an adapter function declared
as __stdcall, which calls the target Go function. For instance, this approach
is detailed in [1].

The question: is there a more direct approach? Is it somehow possible to tell
cgo to generate the wrapper for the exported function as using __stdcall
calling convention (as such a wrapper is generated anyway)?

1. https://github.com/golang/go/issues/32851#issuecomment-507017147

Ian Lance Taylor

unread,
Oct 29, 2022, 10:34:09 AM10/29/22
to golang-nuts
As far as I know that is the only way.

Ian

Reply all
Reply to author
Forward
0 new messages