F# 忽略 DllImport 属性中设置的 CallingConvention?

发布于 2024-12-11 11:54:47 字数 672 浏览 0 评论 0原文

当尝试使用以下签名调用函数时(由 MSVC++ 编译):

BOOL CreateJunctionPoint(LPCTSTR szMountDir, LPCTSTR szDestDir);

并在 F# 中进行了描述,因为

[<DllImport("FSLinks.dll", CallingConvention = CallingConvention.Cdecl)>]
extern int CreateJunctionPoint(string source, string target)

我遇到了堆栈不平衡。

从 C# 调用的相同函数可以完美运行。

在 C++ 中将调用约定更改为 stdcall 后:

 BOOL  __stdcall CreateJunctionPoint(LPCTSTR szMountDir, LPCTSTR szDestDir);

F# 程序开始正常工作(尽管仍然设置了 CallingConvention = CallingConvention.Cdecl) 对我来说这似乎是明显的编译器错误。

两个编译器均来自 Visual Studio 2010(Microsoft (R) F# 2.0 编译器内部版本 4.0.30319.1)

While trying to call function with following signature (compiled by MSVC++):

BOOL CreateJunctionPoint(LPCTSTR szMountDir, LPCTSTR szDestDir);

and described in F# as

[<DllImport("FSLinks.dll", CallingConvention = CallingConvention.Cdecl)>]
extern int CreateJunctionPoint(string source, string target)

I get stack imbalance.

The same function called from C# works perfectly.

After changing calling convention to stdcall in C++:

 BOOL  __stdcall CreateJunctionPoint(LPCTSTR szMountDir, LPCTSTR szDestDir);

F# program begin working normally (though still having CallingConvention = CallingConvention.Cdecl set)
Seems like obvious compiler bug to me.

Both compilers are from Visual Studio 2010 (Microsoft (R) F# 2.0 Compiler build 4.0.30319.1)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文