How does PHP obtain the returned string from the COM component? The COM component defines a method HRESULTGetStr ([in, out] BSTR * vStr, [in, out] LONG * vLen, [out, retval] LONG * vError). The method is implemented as follows: CC ++ codeSTDMETHODIMPMC_MyClass: GetStr (BSTR * vStr, how does PHP obtain the returned string from the COM component?
Define a method in the COM component
HRESULT GetStr ([in, out] BSTR * vStr, [in, out] LONG * vLen, [out, retval] LONG * vError );
Method implementation:
C/C ++ code
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;}
PHP calls this method
C/C ++ code
$tStr = "";$tLen = 100;$tStr = str_pad($tStr, $tLen, "0");$tRes = $tCom->GetStr(&$tStr, &$tLen);
Result
$ TRes = 1;
$ TStr = "";
$ TLen = 26;
Solution: Why is $ tStr empty?
------ Solution --------------------
It may be retrieved using the vsscanf function.
Unable to provide further suggestions because there are no test conditions
------ Solution --------------------
Memcpy (* vStr, tStr, wcslen (tStr ));
Wcslen is the number of UNICODE characters, memcpy is the number of copied bytes, it is obvious that wcslen (tStr) * 2, and not * vStr, directly vStr.
------ Solution --------------------
Discussion
Memcpy (* vStr, tStr, wcslen (tStr ));
Wcslen is the number of UNICODE characters, memcpy is the number of copied bytes, it is obvious that wcslen (tStr) * 2, and not * vStr, directly vStr.