- 注册时间
- 2010-11-11
- 最后登录
- 2025-5-27
- 阅读权限
- 200
- 积分
- 14361
- 精华
- 2
- 帖子
- 843
  

TA的每日心情 | 无聊 2025-5-27 03:37:20 |
---|
签到天数: 366 天 [LV.9]以坛为家II
我玩的应用:
  
|
com组件的dll文件的php调用方法:
调用说明:
{
调用COM的方法:
首先要在windows的运行框中,运行regsvr32 c:\yourpath\yourcom.dll。需要注意的问题一定要把你用到的所有DLL文件都
放在一个目录下。注册成功后,你就可以调用了。
<?php
$mycom = new COM ("mycom.myclassname") or die ("error");//mycom.myclassname 点前面是你dll的名字,点后面是你在
com中定义的类的名字。
com_invoke($mycom,"yourfunctionname","para1","para2");//有几个参数就写几个para。
$mycom ->;Release();
?>;
注意:在用php想com传参数的时候,会有点问题,在传递字符串时,你的com程序一定要是BSTR类型的,如果是CHAR*就不能成功传递!
}
<?php
$dw = new COM("COMDLL.test");
$ch = $dw->Cat('1x1','2x2');
echo '<br/>',$ch;
exit;
?>
comdll文件代码
inline long Itest::Add ( long n1, long n2 ) {
long _result;
HRESULT _hr = raw_Add(n1, n2, &_result);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
return _result;
}
inline _bstr_t Itest::Cat ( _bstr_t s1, _bstr_t s2 ) {
BSTR _result;
HRESULT _hr = raw_Cat(s1, s2, &_result);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
return _bstr_t(_result, false);
}
二、
非com组件的dll文件的php访问方法:
1.下载dynwrap.dll
2.把该文件放入system32和php/ext/下,修改php.ini,增加extension=dynwrap.dll
3.注册dynwrap.dll:com:cmd regsvr32 d:/dynwrap.dll
4.将要调用的dll放入system32
5.register参数,
/*
输入参数是:
i=描述了函数的参数数量和数据类型 i=uu代表两个INT参数
f=呼叫_stdcall或者_cdecl的类型。因此,它可以在ms C++和Borland C++运行。默认为_stdcall。如果不起作用,使用_cdecl。如果不工作,那么恭喜你!!!
r=返回的数据类型。
*/
<?php
$dw = new COM("DynamicWrapper");
$dw->Register("Dll1test.dll", "add", "f=s", "i=uu", "r=l");
$ch = $dw->add(11,22); //dll的add函数调用
echo '<br/>',$ch;
/**/
$dw->Register("Dll1test.dll", "subtract", "f=s", "i=uu", "r=l");
$ch2 = $dw->subtract(42,22); //dll的sub函数调用
echo '<br/>',$ch2;
exit;
?>
dll1test.dll
#define DLL1TEST_API extern "C" _declspec(dllexport)
DLL1TEST_API int add(int a,int b)
{
return a+b;
}
DLL1TEST_API int subtract(int a,int b)
{
return a-b;
}
附DynamicWrapper说明:
The DynaCall page
Thanks to Ton Plooy and Jeff Stong and their articles published in the August and November issues of the Windows Developers Journal (see the Archive part in www.wdj.com for the articles and the original code) the WSH script programmers has now the possibility to call Win 32 API functions. There is a routine dynacall.dll that provides something like a "Declare statement" in VBScript. Basically it will allow you to call functions in other dlls (like any of the win32 API function).
The history
Months ago I noticed a posting from Michael Hines about the Dynacall.dll in the WSH newsgroup. He mentioned also that the original code comes from a Windows Developers Journal article. But my (first) attempts to find these articles and the code wasn't successful. So I asked several people to send me the parts. But then I get confused about the different versions and so on. To let the WSH scripters participate in the Dynacall.dll I decided to create this page.
Because there was a bit confusion about the different versions of the Dynacall.dll, I like to get a brief overview (as far as I can estimate it from here). The original code published by Ton Plooy was written for Windows 9x (he published the code in an article in the August issue of the Windows Developer Journal www.wdj.com, describing the technique to call an external function without an Declare statement). Then Jeff Stong published an article (An Automation Object for Dynamic DLL Calls) with the code for Dynacall.dll in the November 1998 issue of the Windows Developer Journal.
William Epp extended the component and Michael Hines undertook the task to bring the whole distribution with a few comments and modifications to the WSH newsgroups. During writing the WSH book I experimented a little bit with the dll, and I found out that the original Dynacall.dll published from Jeff Stong was written only for Windows NT. So Michael Hines was so kind to create also a version for Windows 9x. Both ZIP-Archives are offered below for download.
Using the Dynacall.dll
Download the ZIP-Archive and unpack the archive into a separate folder. The archive contains the source code, a few samples Michael Hines and other provides and the already compiled Dynacall.dll. Take care to get the Win 9x or the Win NT version. The register the DLL using the program RegSvr32.dll with the following command:
RegSvr32.exe <path>dynacall.dll
where <path> is the path to your folder containing the dll. Unregistering the dll may be done with the /u switch for RegSvr32.exe (although I got an error message for the Win 9x version during this step).
After you have registered the dll, you can use an automation object to call your external functions.
' Create the wrapper object for dynamic DLL function calling
Dim UserWrap
Set UserWrap = CreateObject("DynamicWrapper")
' GetProcAddress for GetPrivateProfileStringA()
UserWrap.Register "kernel32.DLL", "GetPrivateProfileString", "i=ssssls", "f=s", "r=l"
The input parameters are:
i=describes the number and data type of the functions parameters
f=type of call _stdcall or _cdecl. So it can work with both MS C++ and Borland C++. Default to _stdcall. If that doesn't work use _cdecl. If that doesn't work good luck!
r=return data type.
Data types are:
const ARGTYPEINFO ArgInfo[] =
{
{'a', sizeof(IDispatch*), VT_DISPATCH}, // a IDispatch*
{'c', sizeof(unsigned char), VT_I4}, // c signed char
{'d', sizeof(double), VT_R8}, // d 8 byte real
{'f', sizeof(float), VT_R4}, // f 4 byte real
{'k', sizeof(IUnknown*), VT_UNKNOWN}, // k IUnknown*
{'h', sizeof(long), VT_I4}, // h HANDLE
{'l', sizeof(long), VT_I4}, // l long
{'p', sizeof(void*), VT_PTR}, // p pointer
{'s', sizeof(BSTR), VT_LPSTR}, // s string
{'t', sizeof(short), VT_I2}, // t short
{'u', sizeof(UINT), VT_UINT}, // u unsigned int
{'w', sizeof(BSTR), VT_LPWSTR}, // w wide string
}
William Epp added anr 'r' for VT_BYREF (pass by reference) but is for strings only. This made the GETPROFILESTRING function to work. But it didn't work for the GETPROFILESECTION.
For Windows 9x there a some specialties. If you intend to call different API functions you need to declare for each function your own object variable. Also some parameters submitted to the API must be converted from Variants to the required data type using CString or equivalent functions.
Note: Due to the difficulty of all these issues, I prefer to use an ActiveX control to pass my WSH script calls to an external API function. But for some tests, and if you haven't an ActiveX control handy, the dynacall.dll comes handy. But keep in mind that all the code comes without any support. The original articles and code may be downloaded from the archive pages of the Windows Developers Journal (www.wdj.com). Because it is sometimes difficult to get the articles, because we have now modified versions of the code, because Ton Plony and Michael Hines doesn't run own homepages, I have decided to offer the least recent ZIP archives provided from Michael Hines for download. But keep in mind that I can't support the files nor I will be responsible for any consequences resulting from the use of the code.
The Windows 9x version dynawrap95.zip (43 KB)
The Windows NT version dynawrapnt.zip (44 KB)
http://www.borncity.com/web/WSHBazaar1/dynawrapNt.zip
原文地址:http://www.borncity.com/web/WSHBazaar1/WSHDynaCall.htm
可以看下这个:http://bbs.mjtd.com/thread-85724-1-1.html
是一个类似的插件使用方法
该贴已经同步到 admin的微博 |
|