Maison > Article > développement back-end > PHP怎么从COM组件中获取返回的字符串
PHP如何从COM组件中获取返回的字符串?
COM组件中定义一个方法
HRESULT GetStr([in,out] BSTR* vStr, [in,out] LONG* vLen, [out,retval] LONG* vError);
方法实现为:
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> STDMETHODIMP MC_MyClass::GetStr(BSTR* vStr, LONG* vLen, LONG* vError) { *vError = 0; if(0 == vStr) return S_FALSE; if(0 == vLen) return S_FALSE; wchar_t tStr[] = L"This is a string from com!"; memcpy(*vStr, tStr, wcslen(tStr)); *vLen = wcslen(tStr); *vError = 1; return S_OK; }
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> $tStr = ""; $tLen = 100; $tStr = str_pad($tStr, $tLen, "0"); $tRes = $tCom->GetStr(&$tStr, &$tLen);