2013-06-11 44 views
0

這是對我的另一個問題的擴展。我有一個應該與Game Maker連接的DLL,它使用DoublePCharPascal:將接口類加倍,接口實例

我必須將我的對象轉換爲Double s(引用)才能與Game Maker來回傳遞。

我有2個課程:TBitmapTWindow。每個實施IBlittable。這意味着,在IBlittable的經營方法,既可以使用,但這裏的問題:

這裏是我如何創建它們:

{Creation of Bitmaps and Windows} 

function CreateBitmap(W, H: Double): Double; STDCall; 
var 
    TBM: TBitmap; 
begin 
    TBM := TBitmap.Create(Floor(W), Floor(H)); 
    CreateBitmap := Double(Integer(TBM)); 
end; 

function GetWindowByHWND(Handle: Double): Double; STDCall; 
var 
    ReturnVal: TWindow; 
begin 
    ReturnVal := TWindow.Create(Floor(Handle)); 
    GetWindowByHWND := Double(Integer(ReturnVal)); 
end; 

而這裏的如何,我試圖來對它們進行操作:

function SetPixel(Handle, X, Y, Color: Double): Double; STDCall; 
var 
    <stuff> 
begin 
    Blittable := IBlittable(Floor(Handle)); //This! 
    <set the pixel> 
    SetPixel := 0; 
end; 

當我將Floor(Handle)轉換爲IBlittable時,它會發生段錯誤和崩潰。

當我將它轉換爲之前的版本(TWindow或TBitmap)時,它工作正常。我如何繞過這個問題?

我真的不希望所有的方法特別重寫(那簡直是非常多餘的,跛腳)

+0

你爲什麼存儲指針在*雙* *?這根本沒有意義。特別是使用floor時,double只有53位精度,所以它絕不會在64位精度的64位系統上工作。另外,你使用的是CORBA還是COM接口? – BeniBela

+0

@BeniBela Game Maker是一款您可以使用DLL進行擴展的軟件。它只使用'Double'與DLL進行通信,所以我不得不使用它們。它也保證是32位。非常哈克和愚蠢的,不是嗎? –

回答

0

我需要改變類型的創建功能:

function CreateBitmap(W, H: Double): Double; STDCall; 
var 
    TBM: IBlittable; //See 
begin 
    TBM := TBitmap.Create(Floor(W), Floor(H)); 
    CreateBitmap := Double(Integer(TBM)); 
end; 

function GetWindowByHWND(Handle: Double): Double; STDCall; 
var 
    ReturnVal: IBlittable; //Here too 
begin 
    ReturnVal := TWindow.Create(Floor(Handle)); 
    GetWindowByHWND := Double(Integer(ReturnVal)); 
end;