标签:std sls result sig china 通过 hello var view
转载自http://blog.chinaunix.net/uid-20787846-id-3530180.html
编译com的dll
下面简单介绍一下步骤和注意事项:
几点疑问
PHP调用dll
用DynamicWrapper方法调用。下载DynamicWrapper.dll到php ext下与windows system32下
$dw = new COM("DynamicWrapper"); $dw->Register("EbUsbApi.dll", "EbCreateDataFile", ‘i=sls‘, "f=s", "r=l"); $ch = $dw->EbCreateDataFile("222",11,"22"); #dll其中一个函数 HANDLE EbCreateDataFile(LPCTSTR lpFileName, DWORD dwCreationDisposition, LPCTSTR lpPassword)
查看CPU荷载:
$wmi = new COM(‘winmgmts://‘); $processor = $wmi->ExecQuery("SELECT * FROM Win32_Processor"); foreach($processor as $obj){ $cpu_load_time = $obj->LoadPercentage; } echo $cpu_load_time;
调用自定的dll组件:
1) 创建ActiveX dll组件 --
CODE:
Public Function hello() As String
hello = "Hello World!"
End Function并存为"test.dll" 文件
2) 用regsvr32.exe注册此组件
regsvr32 test.dll
3) 在PHP内调用此dll组件:
$obj = new COM("test.dll"); $output=$obj->hello(); // Call the "hello()" 方法 echo $output; // 显示Hello World! (so this comes from the dll!)
准备工作
比如我作了一个COM组件,新建一个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" br style=‘font-size:16px;font-style:normal;font-weight:400;font-family:Verdana;color:rgb(102, 102, 102);‘ />If num > 0 Then Get_Number_Attrib = 1
If num = 0 Then Get_Number_Attrib = 0
End Function
编译生成p_test.dll文件
第一步,做为一个COM组件,这个DLL要被系统识别就要先到系统来报到
regsvr32 [路径]/[组件文件名]
regsvr32 C:/WINDOWS/system32/p_test.dll
放在系统文件夹system32下不容易出现权限问题
这时候这个文件就不能移动位置了,系统会在用到它时到这个目录来找,如果改目录就得先删除注册
再重新注册
regsvr32 /u [路径]/[组件文件名]
系统会显示窗口表示成功,大意是 组件Dllregister成功或是Dllunregister成功
第二步就可以直接调用它了
$b=new COM("p_test.c_test"); //一般前边是它的主文件名后边是它的类名从注册表里找这个文件可以找到。这样就生成了一个叫b的对象,我们就可以用它的属性和方法来操作了 $a=$b->Test_Number(-454); echo $a;
可能遇到的问题是,编译工程时通不过,要将
Microsoft Active Server Pages Object Library
引用进来,具体实现"Project->References"找到改库,并勾上 。
标签:std sls result sig china 通过 hello var view
原文地址:http://www.cnblogs.com/xueyuwyz/p/6214395.html