bstr

Convert from Wstring to CComBstr

徘徊边缘 提交于 2019-12-13 07:09:44
问题 Please suggest me methods for converting from wstring to CComBstr. I tried to convert like following but it is failing CComBSTR BstrAddress(strID); // strID is wstring type I am getting error as "cannot convert parameter 1 from 'std::wstring' to 'int'" Please help me regarding this 回答1: These are constructors of CComBSTR class: CComBSTR( ) throw( ); CComBSTR( const CComBSTR& src ); CComBSTR( REFGUID guid ); CComBSTR( int nSize ); CComBSTR( int nSize, LPCOLESTR sz ); CComBSTR( int nSize,

ATL how to Convert BSTR* str to registry key.SetValue(LPCTSTR str type

空扰寡人 提交于 2019-12-13 03:49:03
问题 It's been years since I have done C++ let alone ATL code I have this method that needs surgical help :( This is for a mobile app so I don't want to use CString and MFC I need to convert the BSTR* str to the correct type LPCTSTR for use in the registry Set.Value method STDMETHODIMP CAXSampleCtl::SendMSG(BSTR* str) { CRegKey key; key.Create(HKEY_LOCAL_MACHINE, _T("MyKeyName")); key.SetValue( str <<<--- nope, _T("MyValueName")); key.Flush(); key.Close(); return S_OK; } 回答1: COLE2T macro is just

Problems converting BSTR to char *

倾然丶 夕夏残阳落幕 提交于 2019-12-13 01:11:47
问题 We've an old C++ app that's making calls to third-party webservices, using WinHttp.WinHttpRequest.5.1. I won't list all of the details of the call sequence, as I don't think it's relevant to the problem, but we finish by calling hr = pIWinHttpRequest->get_ResponseText(&bstrResponse); , where bstrResponse is of type BSTR. The calling code doesn't work with BSTRs, it works with standard C/C++ char * 's, so the code converts the BSTR to a char * with: _bstr_t b(bstrResponse); const char *c =

Appending BSTR in a LPCSTR

坚强是说给别人听的谎言 提交于 2019-12-12 12:27:03
问题 I have a class function which is receving a BSTR. In my class I have a member variable which is LPCSTR. Now I need to append BSTR ins LPCSTR. How I can do that. Here is my function. void MyClass::MyFunction(BSTR text) { LPCSTR name = "Name: "; m_classMember = name + text; // m_classMember is LPCSTR. } in my m_classMember I want that after this function value should be "Name: text_received_in_function". How i can do that. 回答1: Use the Microsoft specific _bstr_t class, which handles the ANSI

VBA/Excel, and C++ DLL, specifically problems with strings

旧街凉风 提交于 2019-12-11 05:49:02
问题 I am working on a project for serial communications between Excel and an Arduino. The following is what I have in VBA for the reading of data from the Arduino which is where my problem lies. Private Declare Function readFromSerialPort Lib "C:PathToDll.dll"(ByRef Buffer As String) As String And in a looping function within my VBA I have the following which sets a cell value to a string which is my buffer. BigData.Range("Buf").Value = "B " Another cell called dataWindow takes in Buf as an

PHP - Using COM error message: Parameter 5: Type mismatch

北慕城南 提交于 2019-12-11 03:06:16
问题 I'm using PHP to call an object on server with class COM, at IIS 7. The object is well created, but when I'm using a method of it, PHP return this error: PHP Fatal error: Uncaught exception 'com_exception' with message 'Parameter 5: Type mismatch. The error occurs in the parameter $bd. My PHP code: $oem = new COM("LogicControlOEM.OEM_EjecutaOEM") or die("ERROR"); var_dump($oem); $empresa = 1; $usuario = 'XXX'; $pass = 'XXX'; $proveedor = ''; $servidor = 'XXXX'; $bd = 'example'; // I tried to

Why is BSTR length prefix 4 bytes on 64-bit platforms?

天涯浪子 提交于 2019-12-10 19:29:54
问题 It seems that on 64-bit platforms it would be reasonable to have a 8-byte length prefix. If we can address more than 4Gb of mem why not allow, say, 5Gb strings? Is the answer just "by specification" or there is some interoperability/backwards compatibility reasons that I'm not aware of? Thanks. 回答1: The BSTR data type is the standard COM string data type. Changing the length prefix would make it impossible to safely move strings between processes of different bitness (or at least make it

_bstr_t to UTF-8 possible?

爷,独闯天下 提交于 2019-12-08 16:24:41
问题 I have a _bstr_t string which contains Japanese text. I want to convert this string to a UTF-8 string which is defined as a char * . Can I convert the _bstr_t string to char * (UTF-8) string without losing the Japanese characters? 回答1: Use WideCharToMultiByte() – pass CP_UTF8 as the first parameter. Beware that BSTR can be a null pointer and that corresponds to an empty string – treat this as a special case. 回答2: Here is some code that should do the conversion. void PrintUtf8(const TCHAR*

How do you efficiently copy BSTR to wchar_t[]?

廉价感情. 提交于 2019-12-07 06:25:56
问题 I have a BSTR object that I would like to convert to copy to a wchar__t object. The tricky thing is the length of the BSTR object could be anywhere from a few kilobytes to a few hundred kilobytes. Is there an efficient way of copying the data across? I know I could just declare a wchar_t array and alway allocate the maximum possible data it would ever need to hold. However, this would mean allocating hundreds of kilobytes of data for something that potentially might only require a few

Shall we treat BSTR type in COM as value or reference?

家住魔仙堡 提交于 2019-12-07 05:26:54
问题 From book ATL Internals , I knew BSTR is different from OLECHAR*, and there are CComBSTR and CString for BSTR. According MSDN Allocating and Releasing Memory for a BSTR, I knew memory management responsibility for caller/callee. Take this line from MSDN, HRESULT CMyWebBrowser::put_StatusText(BSTR bstr) I still do not know how to handle bstr properly in my implementation. Since I still have a basic question for BSTR -- should we treat bstr as a value (like int) or as a reference (like int*),