2009-10-28 23 views
0

有人能告訴我在Oxygene for .NET中如何找到一個如何製作DLL(WindowsControlLibrary)的例子嗎?
在舊的Delphi中,您創建了一個導出部分。Oxygene中的DLL示例

回答

2

要使用德爾福棱鏡創建一個非託管的DLL導出和與2010年德爾福叫什麼你必須做到以下幾點:

在德爾福棱鏡:

  1. 文件|新增|項目
  2. 在樹視圖在左邊,選擇德爾福棱鏡
  3. 選擇Windows類庫

按OK。

這將創建的模板的Windows類庫

右鍵單擊該項目「ClassLibraryX」,然後選擇屬性:

  1. 在兼容性選擇「允許不安全的代碼」
  2. 在構建,找到General Section並將CPU Type更改爲「x86」
  3. 右鍵單擊已創建的「ClassLibraryX」選項卡並選擇「Save selected Items」

設置該項目以支持UnmanagedExportAttribute

然後在代碼中,您將需要創建一個類方法。在下面的例子中,我添加了對System.Windows.Forms的引用。

namespace ClassLibrary2; 

interface 

type 
    Class1 = public class 
    private 
    protected 
    public 
    [UnmanagedExport('ShowMessage')] 
    class method ShowMessage(aMsg : String); 
    end; 

implementation 

class method Class1.ShowMessage(aMsg : String); 
begin 
System.Windows.Forms.MessageBox.Show(aMsg); 
end; 

end. 

使用PEViewer,我用了一個船舶在JCL一個例子,你應該能夠看到新的出口。在上述exampele「ShowMessage」

+0

謝謝。 我用一個過程做了一個簡單的ClassLibrary,但是當我嘗試從Delphi2010應用中讀取時,它找不到該條目。 應該有可能嗎? 這是否意味着,只有其他Prism2010可以訪問該dll? 我想從Delphi2010應用程序訪問DLL – 2009-10-30 12:32:39

+0

更新了答案以顯示我做了什麼來創建導出。 – 2009-11-02 13:53:47

1

如果你whant,使其與德爾福兼容,那麼你必須表明「STDCALL」調用約定

命名空間ClassLibrary2;

接口

類型 的Class1 =公共類

私人

保護

公共

[UnmanagedExport( 'ShowMessage'),System.Runtime.InteropServices.CallingConvention。 StdCall]

類方法ShowMessage(aMsg:String); 結束;

實施

class method Class1。ShowMessage(aMsg:String);

開始

System.Windows.Forms.MessageBox.Show(AMSG);

end;

結束。