1 inline HRESULT TCHAR2BSTR(TCHAR * szBuf, BSTR * bstrNew) 2 { 3 try 4 { 5 WCHAR * wszBuf; 6 #ifndef UNICODE 7 wszBuf = new WCHAR[512]; 8 MultiByteToWideChar(CP_ACP, 0, szBuf, -1, wszBuf, 512); 9 #else 10 wszBuf = szBuf; 11 #endif 12 13 bstrNew = ::SysAllocString(wszBuf); 14 15 #ifndef UNICODE 16 delete [] wszBuf; 17 #endif 18 19 } 20 catch (...) 21 { 22 return E_OUTOFMEMORY; 23 } 24 25 return S_OK; 26 }
何时释放BSTR内存请参考
https://msdn.microsoft.com/zh-cn/library/cc485262
时间: 2024-10-11 11:20:51