F# 忽略 DllImport 属性中设置的 CallingConvention?
当尝试使用以下签名调用函数时(由 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这是一个已知的错误。
http://connect.microsoft.com/VisualStudio /feedback/details/612713/f-ignores-callingconvention-for-dllimport
Yes, this is a known bug.
http://connect.microsoft.com/VisualStudio/feedback/details/612713/f-ignores-callingconvention-for-dllimport