correct way to copy bstr ?
-
BSTR strLoggedInUser=GetLoggedInUser();//is this line of code is correct or i use wcscpy here. BSTR value=::SysAllocStringLen(L"",::SysStringLen(strLoggedInUser)); wcscpy(value,strLoggedInUser); ::SysFreeString(strLoggedInUser); /////////////////////////////////////////////////////////////////////// HRESULT hr = pclsObj->Get(L"Manufacturer", 0, &vtProp, 0, 0); BSTR strItemName =vtProp.vt==VT_NULL?L"-NA-":vtProp.bstrVal;// here too is this line of code is correct or i use wcscpy here.
“You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
-
BSTR strLoggedInUser=GetLoggedInUser();//is this line of code is correct or i use wcscpy here. BSTR value=::SysAllocStringLen(L"",::SysStringLen(strLoggedInUser)); wcscpy(value,strLoggedInUser); ::SysFreeString(strLoggedInUser); /////////////////////////////////////////////////////////////////////// HRESULT hr = pclsObj->Get(L"Manufacturer", 0, &vtProp, 0, 0); BSTR strItemName =vtProp.vt==VT_NULL?L"-NA-":vtProp.bstrVal;// here too is this line of code is correct or i use wcscpy here.
“You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
BSTR value=::SysAllocString(strLoggedInUser);
You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_
-
BSTR strLoggedInUser=GetLoggedInUser();//is this line of code is correct or i use wcscpy here. BSTR value=::SysAllocStringLen(L"",::SysStringLen(strLoggedInUser)); wcscpy(value,strLoggedInUser); ::SysFreeString(strLoggedInUser); /////////////////////////////////////////////////////////////////////// HRESULT hr = pclsObj->Get(L"Manufacturer", 0, &vtProp, 0, 0); BSTR strItemName =vtProp.vt==VT_NULL?L"-NA-":vtProp.bstrVal;// here too is this line of code is correct or i use wcscpy here.
“You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
let me suggest something for you ... http://lmgtfy.com/?q=copy+bstr[^]
-
let me suggest something for you ... http://lmgtfy.com/?q=copy+bstr[^]
i know how to copy bstr, but my problem is that when i assign BSTR b=L"hello"; some where in code the value of b changes to " some garbage value". but if i use wcscpy, the value of b doesn't change. please read my question and answer me.
“You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
-
i know how to copy bstr, but my problem is that when i assign BSTR b=L"hello"; some where in code the value of b changes to " some garbage value". but if i use wcscpy, the value of b doesn't change. please read my question and answer me.
“You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
Take a look at: http://msdn.microsoft.com/en-us/library/ms221069.aspx[^] It is clearly stated that asigning anything to a BSTR should be done using SysAllocString. So using wcscpy or a regular asignment operator (=) is wrong by definition. You can try something like this (I assume GetLoggedInUser() returns a wchar *):
BSTR strLoggedInUser = ::SysAllocStringLen( GetLoggedInUser() );
//..do something..
//Call this when you are sure the BSTR is no longer used!!
::SysFreeString(strLoggedInUser); -
i know how to copy bstr, but my problem is that when i assign BSTR b=L"hello"; some where in code the value of b changes to " some garbage value". but if i use wcscpy, the value of b doesn't change. please read my question and answer me.
“You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
Mogaambo wrote:
BSTR b=L"hello";
That is bad. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Mogaambo wrote:
BSTR b=L"hello";
That is bad. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]BSTR b=SysAllocString(L"hello"); BSTR c=b;// here wcscpy should be used or it will work
“You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
-
BSTR b=SysAllocString(L"hello"); BSTR c=b;// here wcscpy should be used or it will work
“You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
Mogaambo wrote:
BSTR b=SysAllocString(L"hello");
The above is fine.
Mogaambo wrote:
BSTR c=b;// here wcscpy should be used or it will work
The above is bad. Use, instead
BSTR c = SysAllocString(b);
Please read [^]. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]