2009-12-23 86 views
4

我正在使用xampp。如何從Windows中的一個DLL調用一個函數?

我搜索,它看起來像PHP 4.x,有一個擴展名爲php_w32api.dll似乎已經消失了PHP 5.x.儘管如此,它仍然在php.net的文檔中,但標記爲實驗性的。

有人建議在pecl中使用win32std,但這只是包裝了win32 api的某些功能,但不允許我調用自己的dll函數。 :/

有FFI,但在PECL網站的鏈接是死的,這似乎是發展於2004年

任何想法已經停止如何做到這一點沒有寫我自己的PHP擴展?

問候 馬克

回答

4

COM功能僅適用於Windows版本的PHP。 .Net支持需要PHP 5和.Net運行時。 無需安裝即可使用這些功能;他們是PHP核心的一部分。

首先創建您的ActiveX dll(Visual Basic): 將您的項目命名爲「foo」並將其命名爲「bar」。

'---start VB code--- 
Public Function hello() As String 
    hello = "Hello World!" 
End Function 
'---end VB code--- 

然後使DLL與regsvr32.exe的 註冊它現在創建你的PHP腳本:

<?php 
    $obj = new COM("foo.bar"); 
    $output=$obj->hello(); // Call the "hello()" method 
    // once we created the COM object this can be used like any other php classes. 
    echo $output; // Displays Hello World! (so this comes from the dll!) 
    ?> 
+0

嗯。如果我已經有一個導出簡單函數的dll會怎麼樣?不知何故,這是否適用? – marc40000 2009-12-23 21:57:17

+0

嗯..如果你知道這個DLL提供了什麼功能,那麼你只需要抓住邏輯並把它放到你的PHP應用程序;-) – streetparade 2009-12-23 23:34:13

+0

我不知道。我沒有寫dll。 – marc40000 2009-12-26 14:12:10

相關問題