【问题标题】:Haxe and Windows APIHaxe 和 Windows API
【发布时间】:2012-04-16 02:53:47
【问题描述】:

我正在尝试使用 Haxe 中的 Windows API 创建 Windows 应用程序。我已经使用 ndlls 和 Haxe/Neko 完成了这项工作。 我尝试使用 cpp 目标执行此操作,其中我使用 Haxe 2.09 中的新宏功能将 C++ 代码嵌入到 Haxe 文件中。但是,只要我包含windows.h,它就会报错

./src/Main.cpp(79) : error C2039: 'RegisterClassA' : is not a member of 'hx'
./src/Main.cpp(81) : error C2660: 'RegisterClassA' : function does not take 9 arguments
Called from ? line 1
Called from BuildTool.hx line 1246
Called from BuildTool.hx line 554
Called from BuildTool.hx line 591
Called from BuildTool.hx line 710
Called from BuildTool.hx line 785
Uncaught exception - Error in building thread
Error : Build failed
Build halted with errors (haxe.exe).

这是我的代码 -

import cpp.Lib;

@:headerCode("#include <windows.h>")// if i comment this line or replace windows.h with another standard header file like iostream, the error goes

class Main 
{
     static function main() 
     {
           //no code here   
     }
}

事实上,如果我用 Windows 或 DirectX SDK 中的任何头文件替换 windows.h,我会得到同样的错误 我正在使用 Haxe 2.09 和 FlashDevelop。我使用的是 Windows 7。我也在使用最新版本的 hxcpp(2.09 版)。

【问题讨论】:

    标签: windows haxe


    【解决方案1】:

    看起来 &lt;windows.h&gt; 是 #defining RegisterClass 到 RegisterClassA(自动魔术 Unicode 支持的一部分)。

    因为这是使用文本预处理器宏完成的,所以任何具有名为 RegisterClass 的符号的代码(就像 BuildTool 的情况一样)都会自动将其替换为 RegisterClassA,如果有人这样做显然会导致问题以正确的名称查找函数。

    试试这个:

    @:headerCode("#include <windows.h>")
    @:headerCode("#undef RegisterClass")
    

    您可能需要对其他冲突执行类似的操作。另见this question。

    【讨论】:

    • 我明白你的意思。这说得通。但是,我需要稍微更改您给我的代码。我不得不将 undef 语句放在 windows.h 包含之前。否则它会给出同样的错误。你能解释一下为什么。无论如何,非常感谢您的帮助。我真的很感激。
    • @bharu:之前?不,我真的无法解释……对不起! ;-)
    • @bharu:我能想到的唯一解释是,也许标头代码是按相反的顺序注入的……但这没有多大意义。
    • 不,事实证明,你把它放在哪个顺序并不重要。反正你是对的。这实际上是由于我粗心造成的另一个小错误。对不起 !再次感谢!
    猜你喜欢
    • 1970-01-01
    • 2015-09-22
    • 2012-03-31
    • 1970-01-01
    • 1970-01-01
    • 2013-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多