How does PHP obtain the returned string from the COM component?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.