|
What is the safest way to convert a BSTR to a std::string?
FF
|
|
|
|
|
You could add the result from this to your string buffer:
_com_util::ConvertBSTRToString( yourBstr )
|
|
|
|
|
I`m creating an MFC application. I use a modal dialogbox to configure some settings. To read a configuration file i`ve placed this code in the OnActivate event of dialogbox:
<code>
void CPortConfig::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
CDialog::OnActivate(nState, pWndOther, bMinimized);
// TODO: Add your message handler code here
FILE *conffile;
errno_t err;
char tempbuffer[40];
char portname[10];
char baudrate[10];
char flowcontrol[10];
err = fopen_s(&conffile,"..//conffile.dat","r");
if(err !=0)
{
MessageBox(Configuration file not found!\nCreating new one..","Port configuration",MB_OK|MB_ICONERROR);
fopen_s(&conffile,"..//conffile.dat","a+");
fputs("COM1\t9600\tNone\n",conffile);
fclose(conffile);
err = 0;
}
fopen_s(&conffile,"..//conffile.dat","r");
fgets(tempbuffer,40,conffile);
sscanf(tempbuffer,"%s%*[\t\r]%s%*[\t\r]%s",portname,baudrate,flowcontrol);
fcloseall();
this->c_baudrate.SelectString(0,baudrate);
this->v_portname = portname;
this->v_flowcontrol = flowcontrol;
UpdateData(false);
}
</code>
In case when the file doe`s exist everything is OK, but when there is no file, I get the message box displayed on and on and on.I`ve figured out this far, that this part of code is being executed in a loop:
<code>
if(err !=0)
{
MessageBox("Port configuration",
"Configuration file not found!\nCreating new one..",
MB_OK|MB_ICONERROR);
fopen_s(&conffile,"..//conffile.dat","a+");
fputs("COM1\t9600\tNone\n",conffile);
fclose(conffile);
}
</code>
because every time i press OK on the messagebox the line "COM1\t9600\tNone\n" is added to the file.
There is no chance to close the application, only way to do it it using "End task"..
Please help me out with this ! What am I doing wrong?
-- modified at 11:20 Monday 27th November, 2006
|
|
|
|
|
Don't put your initialization code in OnActivate put it in OnInitDialog.
When your message box is dismissed a message is sent to the dialog telling it to activate however this causes the dialog to call OnActivate before your file creation code can execute to create a file.
|
|
|
|
|
Thanx! I was suspecting this to be the cause. Hope this will solve my problem!
|
|
|
|
|
Hi all,
how can I change the font in a RichEdit2 Control to Terminal?
I tried this, but the displayed font is not Terminal.
CHARFORMAT cf;
cf.cbSize = sizeof(cf);
cf.dwMask = CFM_FACE | CFM_SIZE; // makes szFaceName and yHeight valid
cf.yHeight = 9 * 20; // in TWIPS, 20 twips per point
//cf.bPitchAndFamily = FIXED_PITCH;
cf.bCharSet = OEM_CHARSET;
::lstrcpy (cf.szFaceName, "Terminal");
m_pRichEdit->SetSelectionCharFormat(cf);
Thanks
|
|
|
|
|
Has no one any ideas or is it to easy ?
I'm trying to solve this problem since hours. It must be possible.
In Borland Delphi it's no problem, but I have to do this in VC++.
|
|
|
|
|
My understanding of how to use the rich edit is that you have to first select the text for which you wish to change the font.
I found the following code in a program that I wrote some time ago:
CHARRANGE CharRange ;
CHARFORMAT2 CharFormat ;
// To format the text just written, we must select it.
::SendMessage(
m_hwndThis,
EM_SETSEL,
0,
CharRange.cpMax) ; //'cpMax' set to LAST character position.
// Set up the character formatting structure.
CharFormat.cbSize = sizeof(CharFormat) ;
CharFormat.dwMask = CFM_BOLD | CFM_COLOR | CFM_ITALIC ;
CharFormat.dwEffects = (bBold) ? CFE_BOLD : 0 |
(bItalic) ? CFE_ITALIC : 0 ;
CharFormat.yHeight = 0 ;
CharFormat.yOffset = 0 ;
CharFormat.crTextColor = clrFG ; //Previously set
CharFormat.bCharSet = DEFAULT_CHARSET ;
CharFormat.bPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE ;
memset(CharFormat.szFaceName, 0, 1) ;
_tcscpy((_TCHAR*)&CharFormat.szFaceName, _T("Arial")) ;
// Format the text just written.
::SendMessage(
m_hwndThis,
EM_SETCHARFORMAT,
SCF_SELECTION,
(LPARAM)&CharFormat) ;
Don't know if this will help, but maybe it will give you some ideas where to continue.
Scott
|
|
|
|
|
I have writen a program :
#include <string>
using namespace std;
int main()
{
string a("a");
return 0;
}
when i compile it
then it is the result :
--------------------Configuration: abc - Win32 Debug--------------------
Compiling...
abc.cpp
c:\program files\microsoft visual studio\vc98\include\xstring(600) : error C2838: illegal qualified name in member declaration
c:\program files\microsoft visual studio\vc98\include\xstring(618) : see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>' being compiled
c:\program files\microsoft visual studio\vc98\include\stdexcept(19) : error C2629: unexpected 'class std::logic_error ('
c:\program files\microsoft visual studio\vc98\include\stdexcept(19) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body
c:\program files\microsoft visual studio\vc98\include\stdexcept(29) : error C2146: syntax error : missing ';' before identifier '_Str'
c:\program files\microsoft visual studio\vc98\include\stdexcept(29) : error C2501: 'string' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\stdexcept(29) : error C2501: '_Str' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\stdexcept(34) : error C2629: unexpected 'class std::domain_error ('
c:\program files\microsoft visual studio\vc98\include\stdexcept(34) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body
c:\program files\microsoft visual studio\vc98\include\stdexcept(45) : error C2629: unexpected 'class std::invalid_argument ('
c:\program files\microsoft visual studio\vc98\include\stdexcept(45) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body
c:\program files\microsoft visual studio\vc98\include\stdexcept(56) : error C2629: unexpected 'class std::length_error ('
c:\program files\microsoft visual studio\vc98\include\stdexcept(56) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body
c:\program files\microsoft visual studio\vc98\include\stdexcept(67) : error C2629: unexpected 'class std::out_of_range ('
c:\program files\microsoft visual studio\vc98\include\stdexcept(67) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body
c:\program files\microsoft visual studio\vc98\include\stdexcept(78) : error C2629: unexpected 'class std::runtime_error ('
c:\program files\microsoft visual studio\vc98\include\stdexcept(78) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body
c:\program files\microsoft visual studio\vc98\include\stdexcept(88) : error C2146: syntax error : missing ';' before identifier '_Str'
c:\program files\microsoft visual studio\vc98\include\stdexcept(88) : error C2501: 'string' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\stdexcept(88) : error C2501: '_Str' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\stdexcept(93) : error C2629: unexpected 'class std::overflow_error ('
c:\program files\microsoft visual studio\vc98\include\stdexcept(93) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body
c:\program files\microsoft visual studio\vc98\include\stdexcept(104) : error C2629: unexpected 'class std::underflow_error ('
c:\program files\microsoft visual studio\vc98\include\stdexcept(104) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body
c:\program files\microsoft visual studio\vc98\include\stdexcept(115) : error C2629: unexpected 'class std::range_error ('
c:\program files\microsoft visual studio\vc98\include\stdexcept(115) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body
c:\program files\microsoft visual studio\vc98\include\xlocinfo(39) : error C2039: '_Collvec' : is not a member of '`global namespace''
c:\program files\microsoft visual studio\vc98\include\xlocinfo(39) : error C2146: syntax error : missing ';' before identifier '_Collvec'
c:\program files\microsoft visual studio\vc98\include\xlocinfo(39) : error C2868: '_Collvec' : illegal syntax for using-declaration; expected qualified-name
c:\program files\microsoft visual studio\vc98\include\xlocinfo(40) : error C2039: '_Ctypevec' : is not a member of '`global namespace''
c:\program files\microsoft visual studio\vc98\include\xlocinfo(40) : error C2146: syntax error : missing ';' before identifier '_Ctypevec'
c:\program files\microsoft visual studio\vc98\include\xlocinfo(40) : error C2868: '_Ctypevec' : illegal syntax for using-declaration; expected qualified-name
c:\program files\microsoft visual studio\vc98\include\xlocinfo(41) : error C2039: '_Cvtvec' : is not a member of '`global namespace''
c:\program files\microsoft visual studio\vc98\include\xlocinfo(41) : error C2146: syntax error : missing ';' before identifier '_Cvtvec'
c:\program files\microsoft visual studio\vc98\include\xlocinfo(41) : error C2868: '_Cvtvec' : illegal syntax for using-declaration; expected qualified-name
c:\program files\microsoft visual studio\vc98\include\xlocinfo(47) : error C2146: syntax error : missing ';' before identifier '_Getname'
c:\program files\microsoft visual studio\vc98\include\xlocinfo(47) : error C2501: 'string' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\xlocinfo(48) : warning C4183: '_Getname': member function definition looks like a ctor, but name does not match enclosing class
c:\program files\microsoft visual studio\vc98\include\xlocinfo(85) : error C2146: syntax error : missing ';' before identifier '_Days'
c:\program files\microsoft visual studio\vc98\include\xlocinfo(85) : error C2501: 'string' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\xlocinfo(85) : error C2501: '_Days' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\xlocinfo(85) : error C2501: '_Months' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\xlocinfo(85) : error C2501: '_Oname' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\xlocinfo(85) : error C2501: '_Nname' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\xlocale(86) : error C2146: syntax error : missing ';' before identifier '_Name'
c:\program files\microsoft visual studio\vc98\include\xlocale(86) : error C2501: 'string' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\xlocale(86) : error C2501: '_Name' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\xlocale(90) : error C2143: syntax error : missing ',' before '&'
c:\program files\microsoft visual studio\vc98\include\xlocale(90) : error C2059: syntax error : '&'
c:\program files\microsoft visual studio\vc98\include\xlocale(112) : error C2146: syntax error : missing ';' before identifier 'name'
c:\program files\microsoft visual studio\vc98\include\xlocale(112) : error C2501: 'string' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\xlocale(113) : warning C4183: 'name': member function definition looks like a ctor, but name does not match enclosing class
c:\program files\microsoft visual studio\vc98\include\xiosbase(19) : error C2504: 'runtime_error' : base class undefined
c:\program files\microsoft visual studio\vc98\include\xiosbase(21) : error C2629: unexpected 'class std::ios_base::failure ('
c:\program files\microsoft visual studio\vc98\include\xiosbase(21) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body
c:\program files\microsoft visual studio\vc98\include\xiosbase(118) : error C2146: syntax error : missing ';' before identifier 'getloc'
c:\program files\microsoft visual studio\vc98\include\xiosbase(118) : error C2501: 'locale' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\xiosbase(119) : warning C4183: 'getloc': member function definition looks like a ctor, but name does not match enclosing class
c:\program files\microsoft visual studio\vc98\include\xiosbase(120) : error C2146: syntax error : missing ';' before identifier 'imbue'
c:\program files\microsoft visual studio\vc98\include\xiosbase(120) : error C2501: 'locale' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\xiosbase(120) : error C2143: syntax error : missing ',' before '&'
c:\program files\microsoft visual studio\vc98\include\xiosbase(120) : error C2059: syntax error : '&'
c:\program files\microsoft visual studio\vc98\include\xiosbase(168) : error C2146: syntax error : missing ';' before identifier '_Loc'
c:\program files\microsoft visual studio\vc98\include\xiosbase(168) : error C2501: 'locale' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\xiosbase(168) : error C2501: '_Loc' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\xlocnum(21) : error C2653: 'locale' : is not a class or namespace name
c:\program files\microsoft visual studio\vc98\include\xlocnum(69) : see reference to class template instantiation 'std::numpunct<_E>' being compiled
c:\program files\microsoft visual studio\vc98\include\xlocnum(21) : error C2504: 'facet' : base class undefined
c:\program files\microsoft visual studio\vc98\include\xlocnum(69) : see reference to class template instantiation 'std::numpunct<_E>' being compiled
c:\program files\microsoft visual studio\vc98\include\xlocnum(26) : error C2653: 'locale' : is not a class or namespace name
c:\program files\microsoft visual studio\vc98\include\xlocnum(69) : see reference to class template instantiation 'std::numpunct<_E>' being compiled
c:\program files\microsoft visual studio\vc98\include\xlocnum(26) : error C2146: syntax error : missing ';' before identifier 'id'
c:\program files\microsoft visual studio\vc98\include\xlocnum(69) : see reference to class template instantiation 'std::numpunct<_E>' being compiled
c:\program files\microsoft visual studio\vc98\include\xlocnum(26) : error C2501: 'id' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\xlocnum(69) : see reference to class template instantiation 'std::numpunct<_E>' being compiled
c:\program files\microsoft visual studio\vc98\include\xlocnum(31) : error C2146: syntax error : missing ';' before identifier 'grouping'
c:\program files\microsoft visual studio\vc98\include\xlocnum(69) : see reference to class template instantiation 'std::numpunct<_E>' being compiled
c:\program files\microsoft visual studio\vc98\include\xlocnum(31) : error C2501: 'string' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\xlocnum(69) : see reference to class template instantiation 'std::numpunct<_E>' being compiled
c:\program files\microsoft visual studio\vc98\include\xlocnum(32) : warning C4183: 'grouping': member function definition looks like a ctor, but name does not match enclosing class
c:\program files\microsoft visual studio\vc98\include\xlocnum(69) : see reference to class template instantiation 'std::numpunct<_E>' being compiled
c:\program files\microsoft visual studio\vc98\include\xlocnum(39) : error C2629: unexpected 'class std::numpunct<_E> ('
c:\program files\microsoft visual studio\vc98\include\xlocnum(69) : see reference to class template instantiation 'std::numpunct<_E>' being compiled
c:\program files\microsoft visual studio\vc98\include\xlocnum(39) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body
c:\program files\microsoft visual studio\vc98\include\xlocnum(69) : see reference to class template instantiation 'std::numpunct<_E>' being compiled
c:\program files\microsoft visual studio\vc98\include\xlocnum(49) : error C2143: syntax error : missing ',' before '&'
c:\program files\microsoft visual studio\vc98\include\xlocnum(69) : see reference to class template instantiation 'std::numpunct<_E>' being compiled
c:\program files\microsoft visual studio\vc98\include\xlocnum(49) : error C2059: syntax error : '&'
c:\program files\microsoft visual studio\vc98\include\xlocnum(69) : see reference to class template instantiation 'std::numpunct<_E>' being compiled
c:\program files\microsoft visual studio\vc98\include\xlocnum(60) : error C2146: syntax error : missing ';' before identifier 'do_grouping'
c:\program files\microsoft visual studio\vc98\include\xlocnum(69) : see reference to class template instantiation 'std::numpunct<_E>' being compiled
c:\program files\microsoft visual studio\vc98\include\xlocnum(60) : error C2433: 'string' : 'virtual' not permitted on data declarations
c:\program files\microsoft visual studio\vc98\include\xlocnum(69) : see reference to class template instantiation 'std::numpunct<_E>' being compiled
c:\program files\microsoft visual studio\vc98\include\xlocnum(60) : error C2501: 'string' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\xlocnum(69) : see reference to class template instantiation 'std::numpunct<_E>' being compiled
c:\program files\microsoft visual studio\vc98\include\xlocnum(61) : warning C4183: 'do_grouping': member function definition looks like a ctor, but name does not match enclosing class
c:\program files\microsoft visual studio\vc98\include\xlocnum(69) : see reference to class template instantiation 'std::numpunct<_E>' being compiled
c:\program files\microsoft visual studio\vc98\include\xlocnum(83) : error C2653: 'locale' : is not a class or namespace name
c:\program files\microsoft visual studio\vc98\include\xlocnum(83) : error C2143: syntax error : missing ';' before 'tag::id'
c:\program files\microsoft visual studio\vc98\include\xlocnum(83) : error C2501: 'id' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\xlocnum(83) : error C2059: syntax error : ';'
c:\program files\microsoft visual studio\vc98\include\xlocnum(83) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.
abc.exe - 80 error(s), 5 warning(s)
please help me
i will very appreciate
help!!!
|
|
|
|
|
why dont u use the class CString?
|
|
|
|
|
Because it's an STL exercise. Just because someone gets an error with STL does not automatically warrant a "Use MFC" comment.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
And what does he use if he can't get that to work?
Steve
|
|
|
|
|
edit your post so that we can see your include
btw, include this:
#include <STRING>
|
|
|
|
|
I agree, it seems as if you forgt an "#include" statement or some needed setting is not set properly.
|
|
|
|
|
A small knit pick, but you should use lowercase.
Steve
|
|
|
|
|
why ?
i always include the standard C++ headers in uppercase, as the include file names are written like that...
please explain your feeling
|
|
|
|
|
It is standard practice when writing portable code. On some systems, such as Linux, the file system is case sensitive. The standard headers are required to be lowercase.
Steve
|
|
|
|
|
The code you've shown is fine. Something else is at play, like using the /Za compiler switch.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
It should work. Are you using pre-compiled headers? If so did you put the
stdafx.h before the string include?
|
|
|
|
|
Hi everyone,
in my project, i have a DataGrid. If i size the ChildWindow, i refresh the number of rows of the grid
relative to the height.
At the refresh-function i need to change and load some things ( for example a new record from the DB )
So it takes a certain duration.
If i resize the Frame slowly, it works nice.
But if i resize it very fast, so there a many callings to resize the form.
For that reason i will lock the "Refresh-function" and only refresh at the end of the resizing.
But how can i "see" that the user has stopped the resizing of the frame?
Any ideas?
Big thanks
|
|
|
|
|
Hmm when the resizing stops, the user as released the mouse... maybe you can catch this event and look everytime its called if there had been a resizement.
Maybe by a "locking" variable in your "refresh Function"
-> Mosedown -> lock enable refresh part not called
-> Moseup -> lock release -> refresh/paint
|
|
|
|
|
Yeah, i had the same idea, but the Resizing-Border of the View nor of the Frame will call a MouseUp-Event
Trotzdem Danke
|
|
|
|
|
Trapping the mouse will have no effect when sizing, you should try using the WM_ENTERSIZEMOVE and WM_EXITSIZEMOVE . BTW. these two messages are only sent to the main window and not child controls. Another message you could try trapping is the WM_WINDOWPOSCHANGED .
|
|
|
|
|
Great!
Thanks !
|
|
|
|
|
Hi, i have a problem... how i implement the canc button in list box?
The message WM_KEYDOWN and WM_CHAR don't work.
thanks....
Giulio
|
|
|
|