admin 发表于 2012-3-25 22:21:36

php com dll php COM php DynamicWrapper



首先要在windows的运行框中,运行regsvr32 c:\yourpath\yourcom.dll。需要注意的问题一定要把你用到的所有DLL文件都




                $mycom = new COM ("mycom.myclassname") or die ("error");//mycom.myclassname 点前面是你dll的名字,点后面是你在



                $mycom ->;Release();



$dw = new COM("COMDLL.test");
$ch = $dw->Cat('1x1','2x2');  
echo '<br/>',$ch;

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);
3.注册dynwrap.dll:com:cmd regsvr32 d:/dynwrap.dll

i=描述了函数的参数数量和数据类型 i=uu代表两个INT参数

f=呼叫_stdcall或者_cdecl的类型。因此,它可以在ms C++和Borland C++运行。默认为_stdcall。如果不起作用,使用_cdecl。如果不工作,那么恭喜你!!!

$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;

#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;

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 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, 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 ( 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 (43 KB)
The Windows NT version (44 KB)

是一个类似的插件使用方法 该贴已经同步到 admin的微博
页: [1]
查看完整版本: php com dll php COM php DynamicWrapper