本文目錄一覽:
- 1、我用php調用ocx控制項,採用new COM()方法,但是報錯了,錯誤如下,望大神解答
- 2、如何用PHP調用自己編寫的COM組件
- 3、thinkphp 中如何使用 new com(‘XXX’)
- 4、php中有個com組件,它裡面都有哪些屬性和方法可以調用呢?
我用php調用ocx控制項,採用new COM()方法,但是報錯了,錯誤如下,望大神解答
我沒用過ocx 只從你報錯頁的信息上幫你分析一下
第一行只是一個警告,可以忽略,
第二行才是出錯的地方, unexpected ‘ 未保護的單引號在那個ocx文件的第2581行
檢查一下這個地方
如何用PHP調用自己編寫的COM組件
首先寫ActiveX Dll:
新建一個VB6工程,ActiveX Dll將工程命名為P_test,類名為c_test ,類的文件內容如下:
Option Explicit
Private MyscriptingContext As scriptingContext
Private MyApplication As Application
Private MyRequest As Request Private MyResponse As Response
Private MyServer As Server
Private MySession As Session Public
Sub OnStartPage(PassedscriptingContext As scriptingContext)
Set MyscriptingContext = PassedscriptingContext
Set MyApplication = MyscriptingContext.Application
Set MyRequest = MyscriptingContext.Request
Set MyResponse = MyscriptingContext.Response
Set MyServer = MyscriptingContext.Server
Set MySession = MyscriptingContext.Session
End Sub
Public Sub OnEndPage()
Set MyscriptingContext = Nothing
Set MyApplication = Nothing
Set MyRequest = Nothing
Set MyResponse = Nothing
Set MyServer = Nothing
Set MySession = Nothing
End Sub
Public Function Test_Number(num) As Variant
If num 0 Then Get_Number_Attrib = 1
If num = 0 Then Get_Number_Attrib = 0
End Function
編譯生成p_test.dll文件
註冊
提示符下運行:regsvr32 p_test.dll
編寫php文件,test.php4代碼如下:
?php
$b=new COM(“p_test.c_test”);
$a=$b-Test_Number(-454);
echo $a;
?
可能碰到的問題是,編譯工程時通不過,要將Microsoft Active Server Pages Object Library引用進來,具體實現”Project-References”找到改庫,並勾上 。
thinkphp 中如何使用 new com(‘XXX’)
這個需要開啟COM擴展, 好吧,剛看到最後一句,不好意思。。。。。。。。。
php中有個com組件,它裡面都有哪些屬性和方法可以調用呢?
先到PHP.INI中打開COM選項,com.allow_dcom = true
PHP 5.4.5後,com/dotnet 模塊已經成了單獨的擴展,所以需要在PHP.ini中配置extension=php_com_dotnet.dll,如果PHP VERSION5.4.5 則不需要。否則的話,可能就是報錯 Fatal error: Class ‘COM’ not found 了
配置方法為:只需在擴展列表裡添加extension=php_com_dotnet.dll即可
另外需要了解的是,COM組件雖然也是DLL擴展,但它不是PHP擴展,所以把Senc.dll拷貝到php/ext 目錄,然後在PHP.INI里載入是錯誤的,PHP也不認識它
配置完畢後可以測試下,語句為
$word = new COM(“word.application”) or die(“Unable to instanciate Word”);
print “Loaded Word, version {$word-Version}\n”;
上面語句本機必須安裝了office才可以
openoffice的為:
$obj = new COM(“com.sun.star.ServiceManager”) or die(“Unable to instanciate Word”);
原創文章,作者:TLNZ,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/141620.html