bstr

Getting a char* from a _variant_t in optimal time

旧巷老猫 提交于 2020-01-24 06:27:27
问题 Here's the code I want to speed up. It's getting a value from an ADO recordset and converting it to a char*. But this is slow. Can I skip the creation of the _bstr_t? _variant_t var = pRs->Fields->GetItem(i)->GetValue(); if (V_VT(&var) == VT_BSTR) { char* p = (const char*) (_bstr_t) var; 回答1: The first 4 bytes of the BSTR contain the length. You can loop through and get every other character if unicode or every character if multibyte. Some sort of memcpy or other method would work too. IIRC,

Getting a char* from a _variant_t in optimal time

a 夏天 提交于 2020-01-24 06:26:09
问题 Here's the code I want to speed up. It's getting a value from an ADO recordset and converting it to a char*. But this is slow. Can I skip the creation of the _bstr_t? _variant_t var = pRs->Fields->GetItem(i)->GetValue(); if (V_VT(&var) == VT_BSTR) { char* p = (const char*) (_bstr_t) var; 回答1: The first 4 bytes of the BSTR contain the length. You can loop through and get every other character if unicode or every character if multibyte. Some sort of memcpy or other method would work too. IIRC,

Reading single chars from a .NET SecureString in C#?

本小妞迷上赌 提交于 2020-01-02 11:26:40
问题 WPF's PasswordBox returns a SecureString, which hides the password from snoopers. The problem is that you eventually have to get the value of the password, and the suggestions I've found on the net all involve copying the value into a string, which gets you back to the problem of snoopers. IntPtr bstr = Marshal.SecureStringToBSTR(secureString); string password = Marshal.PtrToStringBSTR(bstr); Marshal.FreeBSTR(bstr); But if you really think about it, you don't really need the value, as a

Which is better code for converting BSTR parameters to ANSI in C/C++?

柔情痞子 提交于 2019-12-30 10:35:41
问题 So far I've discovered I can convert incoming BSTRs to ANSI in two (of many?) ways, and I'm curious to know whether one is "better" than the other with respect to speed / efficiency etc. The way I've been using for a while is use the USES_CONVERSION and W2A macros, e.g. BSTR __stdcall F(BSTR p1, BSTR p2 ) { USES_CONVERSION; LPSTR sNum1 = W2A( p1 ); LPSTR sNum2 = W2A( p2 ); Recently, however, I came across another technique: BSTR __stdcall F(BSTR p1, BSTR p2 ) { long amt = wcstombs( NULL, p1,

Should there be a difference between an empty BSTR and a NULL BSTR?

你说的曾经没有我的故事 提交于 2019-12-29 04:47:07
问题 When maintaining a COM interface should an empty BSTR be treated the same way as NULL ? In other words should these two function calls produce the same result? // Empty BSTR CComBSTR empty(L""); // Or SysAllocString(L"") someObj->Foo(empty); // NULL BSTR someObj->Foo(NULL); 回答1: Yes - a NULL BSTR is the same as an empty one. I remember we had all sorts of bugs that were uncovered when we switched from VS6 to 2003 - the CComBSTR class had a change to the default constructor that allocated it

Random characters from casting Arduino string to Excel BSTR through c++ DLL

别来无恙 提交于 2019-12-24 11:44:47
问题 So in some Arduino code I am Serial.print a few numbers like this ( var1=##,var2=##,var3=## ). I have a C++ DLL that I am making to get this information and Parse it into a variant array like this ( "var1=",##.##,"var2=",##.##,"var3=",##.## ) storing the string portions as variant BSTRs and the # s as Variant doubles. This variant array comes from Excel and the purpose of my C++ DLL is to allow serial communications to and from Excel and an Arduino board. My problem is that instead of getting

C++ Create BSTR at compile time / insert length into string at compile time?

倾然丶 夕夏残阳落幕 提交于 2019-12-24 01:24:39
问题 Is it possible using macro magic or TMP to insert the length into a string at compile time? For example: const wchar_t* myString = L"Hello"; I would want the buffer to actually contain "[length] [string constant]". I'm using MSVC 2010 which lacks constexpr. I figured there must be some trick to make this work as its possible to do: const wchar_t* myString = L"\x005Hello"; My attempt so far: template<int Size> wchar_t* toBstr(const wchar_t* str) { #pragma pack(push) #pragma pack(1) struct BStr

Is there a way to write a BSTR literal?

百般思念 提交于 2019-12-22 08:18:03
问题 When calling a function that expects a BSTR it'd be nice to be able to write something like: iFoo->function( bs"HELLO" ); However the only workaround I'm aware of is to use a wrapper that calls SysAllocString etc., e.g.: iFoo->function( WideString(L"HELLO").c_bstr() ); which is kind of ugly. Is there actually such an option to create a BSTR literal? Motivation: easier-to-read code, and faster runtime performance by avoiding an allocation and deallocation. Clarification: I am only talking

Convert BSTR to char*

☆樱花仙子☆ 提交于 2019-12-18 04:35:19
问题 Anyone know how to convert BSTR to char* ? Update: I tried to do this, but don't know if it is right or wrong. char *p= _com_util::ConvertBSTRToString(URL->bstrVal); strcpy(testDest,p ); 回答1: Your code is okay. ConvertBSTRToString does just that. As for the strcpy , testDest needs to be large enough to hold the string pointed to by p . Note that since ConvertBSTRToString allocates a new string you will need to free it somewhere down the line. Once you are done make sure you do: delete[] p; A

_bstr_t memory leak

血红的双手。 提交于 2019-12-14 04:25:15
问题 I have a c++ code. But it is not releasing memory properly. Tell me where I am wrong, here is my code 1 void MyClass::MyFunction(void) 2 { 3 for (int i=0; i<count; i++) 4 { 5 _bstr_t xml = GetXML(i); 6 // some work 7 SysFreeString(xml); 8 } 9 } GetXML (line 5) returns me a BSTR. At this memory of program increases. But after SysFreeString (line 7) memory does not release. What I am doing wrong here? 回答1: First: // This makes a copy. // This is where the leak is. You are leaking the original