|
_bstr_t is a wrapper class that does the conversion for you, so you can do this:
CString s((_bstr_t)BSTR);
This will create a _bstr_t, which will return a char * to the CString constructor.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
sorry i forgot, that bstr is of type _bstr_t. u r rite, Chris.
|
|
|
|
|
No worries
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
Thanks!
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
the best & easy way to conver BSTR to string is use the com_util helper as follows:
_bstr_t tmpBSTR = _com_util::ConvertStringToBSTR(szString);
or the other way around:
CString szString = _com_util::ConvertBSTRToString((BSTR)tmpBSTR);
you can check out the definitions of this functions in
COMUTIL.H
hope this helps ya
Yaron
Ask not what the application can do for you, ask what you can do for your application
|
|
|
|
|
Nope, the best and easiest way to construct a CString from a BSTR is to use the LPCWSTR constructor that CString has. So:
CString str( (LPCWSTR)bstr );
should do what you want. Note that this works because a BSTR is also a LPCWSTR (although a LPCWSTR is not necessarily a BSTR!). This method means that no temporary copies will be made, the Unicode-to-MBCS conversion will be made inside CString and no unnecessary string manipulation happens. Using _bstr_t will also work but with the overhead of a temporary copy of both the _bstr_t and the char* (_bstr_t will first construct itself from BSTR, then it will make an MBCS version and then CString will make a copy of it).
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
The casting is unneeded here, since:
typedef wchar_t *LPCWSTR;
typedef wchar_t *BSTR;
There is no need for casting, unless bstr is not a pure BSTR.
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
Correct. It does however make it clear what constructor we are using - but then again we might not care
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
It is a gratuitious cast and has the potential to break the code in the future. NEVER use an explicit cast unless you have to.
--------
There are 10 types of people in this world. Those who know binary and those who don't.
|
|
|
|
|
CString str = bstr;
Regards,
Alvaro
There is much pleasure to be gained from useless knowledge. - Bertrand Russell
|
|
|
|
|
Hello,
How to I know if a pidl or a path is a shortcut? I know how to resolve
the path by using IShellLink but I would like to detect if it's a shortcut
before resolve it.
Thanks!
|
|
|
|
|
I press F1 in the editor window. However, it displayed very often "The page cannot be displayed" or "Cannot find server". It makes the help system not usable. Isn't it the help is in my harddisk after installation of VS.NET ?? How can i solve this problem ?
|
|
|
|
|
I use Visual C++ 6.0 and I want to display thai font on dialog box. So I open resource and write thai font on dialog box. When I compile program the dialog box can not show thai font. It display _________ . Do you know how to solve my problem?
Thank you.
|
|
|
|
|
Try set properties of that dialog. In dialog properties page you should set language to 'Neutral' and recompile it.
|
|
|
|
|
Hi,
how can I make my own CEdit context menu with the default options?
Normaly, it has Undo, Cut, Copy, Delete, Paste, Select All.... disabled depending on input. I like to have it + my own menu entry. How do I create the default options. Thanks for help!
|
|
|
|
|
PJ Arends (spelling) has an article under the edit section of this site that shows exactly how this is accomplished...
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Hockey wrote:
PJ Arends (spelling) has an article under the edit section of this site that shows exactly how this is accomplished...
thx! exactly what i searched
|
|
|
|
|
Hi virtual friends,
my requirement is to display all the exposed properties
and its values of a activex control.
currently am using a function GetIDsofNames shown below
pDispatch->GetIDsOfNames(IID_NULL, names, 1, LOCALE_USER_DEFAULT, &dispid))
where pDispatch is the Dispatch pointer of the activeX control, to access
the properties.The problem am facing currently is that whenever i access a
runtime property it pop-ups a message box telling that this property is
runtime property.
Now how do i avoid this messagebox.Is there anyway that i could know if its
a runtime property and hence bypass GetIDsofNames?
Regards
Pradeep
|
|
|
|
|
I have a question about DLLs and esp MFC extension DLLs. If I make the MFC extension DLL and put in it many exported classes and also have other defines etc, are these defines then ONLY used internally to the DLL? How would you make some "defines" exported or would you not do this? THose classes not exported in the DLL are then assumed to be used only WITHIN the DLL, is that right?
Thanks.
|
|
|
|
|
I forgot to add this. If I several classes in the DLL to export, I need to include the header file for all the classes?
|
|
|
|
|
First of all, I am not sure what you mean by "defines". Is it #define, or is it any variable, method or class ?
In short, I recommend to just use the __declspec(dllexport) / __declspec(dllimport) modifiers.
#ifdef MFC_DLL
#define EXPORTEDSTUFF __declspec(dllexport)
#else
#define EXPORTEDSTUFF __declspec(dllimport)
#endif
You can use EXPORTEDSTUFF in front of a variable, C method, C++ method, class.
Now you can compile your MFC dll with the MFC_DLL symbol.
In the client application, you just include the appropriate headers (because of course the compiler needs to solve the type declarations), without the MFC_DLL symbol.
That's all about it.
How low can you go ? (MS rant)
|
|
|
|
|
Can anyone see why this block, which is reading from the serial port, allows szBuffer to filled with more than 10 bytes? I just dont see how its being allocated more. When I run in the program it will allow an unlimited number of characters to be placed into szBuffer (so long as the '>' isnt sent to it (ASCII 62))
Any help would be appreciated
-Mel
ps. I left the last while statement there to lend clarity to what fContinue is doing but the code above is just error handling of error events and I was tryign to keep the post small so I left it out
-Mel
<br />
if (eEvent & CSerial::EEventRecv)<br />
{<br />
DWORD dwBytesRead = 0;<br />
char szBuffer[10];<br />
do<br />
{<br />
lLastError = serial.Read(szBuffer,sizeof(szBuffer)- 1,&dwBytesRead);<br />
if(lLastError != ERROR_SUCCESS)<br />
return ShowError(serial.GetLastError(), _T("Unable to read from COM-Port"));<br />
<br />
if(dwBytesRead >0)<br />
{<br />
if (szBuffer[dwBytesRead-1] == 62)<br />
fContinue = false;<br />
}<br />
}while (dwBytesRead == sizeof(szBuffer)-1);<br />
}
}while (fContinue);<br />
<br />
---------------------------------------------
Be good! But if you can't be good, at least be good at it and try not to get any on ya!
-mjf
|
|
|
|
|
How come there are two while loops?
Kuphryn
|
|
|
|
|
I left the last while statement there to lend clarity to what fContinue is doing but the code above is just error handling of error events and I was tryign to keep the post small...
-Mel
---------------------------------------------
Be good! But if you can't be good, at least be good at it and try not to get any on ya!
-mjf
|
|
|
|
|
As an experiment, use "10" instead of sizeof().
Kuphryn
|
|
|
|