VS2008建立dll:
1、new Project/ATL project,取名为ATLHello
2、Add/Class/ATL Simple Object,输入short name 为 test , 然后finish
3、Itest上 Add/Add Method , Method name为show,第一个参数为 in,ULong* pKeys,第二个为out、retrval,BSTR* pReturn
4、实现函数
C:
-
STDMETHODIMP Ctest::show(ULONG* pKeys, BSTR* pReturn)
-
{
-
// TODO: Add your implementation code here
-
*pReturn =::SysAllocString(L"show");
-
return S_OK;
-
}
5、编译后,regsvr32 ATLHello.dll,注册成功则可用。
php中调用dll:
PHP:
-
<?php
-
$com = new COM("ATLHello.test") or die("无法建立COM组件");
-
-
$result = $com->show(50);
-
echo '$result = "'.$result.'"<br />';
-
-
$com = null;
-
?>
附加:
1,用vs做的这个dll在我的机器上面php调用几经成功了。
2,我用VB6.0也做了一个dll,进行注册,用php,通过com调这个dll时,无论我做怎样的尝试,总是提示Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `P_test.c_test': 无效的语法 ' ;
在网上找到com dll 和非com dll在 php调用的方法,也进行了尝试,还是这个错误,真心求高手答疑~