2012-04-16 88 views
0

我試圖使用Haxe中的Windows API來創建Windows應用程序。我已經使用ndlls和Haxe/Neko完成了這項工作。 我試着用cpp目標來做它,我使用Haxe 2.09中的新宏特性將C++代碼嵌入到Haxe文件中。但是,只要我有windows.h它給出了一個錯誤Haxe和Windows API

./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)。

回答

2

看起來像<windows.h>是#defining RegisterClassRegisterClassA(自動魔術Unicode支持的一部分)。

因爲這是一個文本prepropcessor宏,有一個名爲RegisterClass(如似乎是BuildTool的情形),它會自動換出RegisterClassA符號,如果有人去尋找這顯然會導致問題的任何代碼完成該函數以其專有名稱。

試試這個:

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

您可能需要做其他衝突類似的東西。另見this question

+0

我明白你的意思。這說得通。但是,我需要改變你給我的代碼。我不得不在windows.h include之前放置undef語句。否則,它會出現相同的錯誤。你能解釋一下爲什麼。無論如何非常感謝您的幫助。我真的很感激它。 – carboncopy 2012-04-16 04:01:06

+0

@bharu:之前?不,我真的無法解釋......對不起! ;-) – Cameron 2012-04-16 13:40:01

+0

@bharu:我能想到的唯一解釋是,也許頭代碼以相反的順序被注入......但這沒有多大意義。 – Cameron 2012-04-16 14:29:23