|
the MSDN tells us :
int CString::Delete( int nIndex, int nCount = 1 )
throw (CMemoryException );
...
Remarks
If nCount is longer than the string, the remainder of the string will be removed.
i thought the following line of code would work :
m_strDateDay.Delete(2, INT_MAX); but i'm afraid, it doesn't !!!
instead of this, it gives me an "Unhandled Exception in Prog.exe".
when i debug, i see that memcpy() is making the error within CString::Delete().
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
toxcct wrote:
m_strDateDay.Delete(2, INT_MAX);
What does m_strDateDay.Delete(2, INT_MAX - 1) yield?
If that does not work, how about:
m_strDateDay = m_strDateDay.Left(2);
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
actually, i've already tried with INT_MAX - 1 , and also with m_strDateDay.GetLength() (which i was certain at the moment that it was no longer than 5 chars).
i currently use CString.Left() , but i wanted to know if anybody had already encountered that problem, or could find a reason to that behavior...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
So these two statements do not work for you:
m_strDateDay = "12345";
m_strDateDay.Delete(2, INT_MAX - 1);
m_strDateDay.Delete(2, m_strDateDay.GetLength()); Is that correct?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
|
It's a bug. It has nothing to do with INT_MAX.
Actually, the exception is thrown if nCount is greater than the (number of remaining characters after nIndex) + 2.
SkyWalker
|
|
|
|
|
so what...?
should I mail Mr MSDN to tell him that its doc is not accorded with the libraries ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Are we all doing all the things perfectly? I guess not.
SkyWalker
|
|
|
|
|
but that's a document used by hundreds of thousands of people...
it needs a particuliar care ! don't you think so ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Cherie Carter-Scott used to say:
"Il n'y a pas d'erreurs, juste des lecons. Grandir implique un processus d'experience par essais et erreurs. Les experiences negatives font autant partie du processus d'apprentissage que les experiences positives."
SkyWalker
|
|
|
|
|
|
This issue has been fixed. I worked with David Lowndes to get word to the MS folks.
http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=f649d7de-cfd9-4c50-b278-17dcf2678920
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
thank you very much...
well, the problem wasn't coming from me so !
now, i have to acquire MS Visual Studio 2005 beta to get it work
thank you again for tracing this bug to me.
cheers,
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Hi Guys/Gals
I need a basic program in vc++ for serial communication where a message is sent from 1 pc to other thru the rs232 cable.Please help me as soon as possible.
|
|
|
|
|
How can i gray out a text in C++ .Net2003? The text is HTREEITEM text.
Thank you.
|
|
|
|
|
|
I have written class inherited from CString for doing arithmetic operations with huge numbers,but it takes too long to convert a decimal number to binary using standard algorithm(dividing on 2,...).
situation is like this:
i want to convert (for example)
CString g = "134.......45645675"; to Binary
//CString binary;
//binary=SOMEFUNCTION(g); binary = "10000100...10011"
can you give me any link where i can find information about converting from decimal to binary using shift left and shift right operaations,or give me any tipps,i think using these operations will make conversion faster.
Thanks in advance
m0n0
|
|
|
|
|
Giorgi Moniava wrote:
can you give me any link where i can find information about converting from decimal to binary
I found this in my toolbox. It's old so adjust as necessary:
void DWORD_To_BinaryString( DWORD value,char string[] )
{
for (int bit = 0; bit < 32; bit++)
{
DWORD mask = 0x80000000 >> bit;
if ((value & mask) == mask)
string[bit] = '1';
else
string[bit] = '0';
}
string[32] = '\0';
}
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Thanks David for your attention, but i need function like
CString string_To_BinaryString( CString value )
{
CString result;
...
...
return result;
}
you know actually variable 'value' in my program appears to be huge number example : "72389472389472389....234234234234"
it maybe 300 digit or more.thats why standard algorithm(division by 2,...) is very slow.you know i am a little inexperienced programmer so things like '0x80000000' are not similiar to me , i would be very thankful to you if you could give me a little explanation about how to adjust your function in order to get what i need.
Thanks in advance
m0n0
|
|
|
|
|
I did a program like this before about 14 years ago. There was no limit to the length of the operands and the supported operators were +, -, *, /, ^, and !. I did not have to convert anything to binary, though.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
well, i don't know any way to convert a string with an integer long enough into another "binary" string.
if you work directly on an integer, you can do this :
<font color=#0000FF>int</font> iVal = 125932; <font color=#008000>
CString strVal = <font color=#808080>""</font>; <font color=#008000>
<font color=#0000FF>while</font> (<font color=#008000></font>) {
strVal.Insert(0, ((iVal & 0x00000001) ? <font color=#808080>"1"</font> : <font color=#808080>"0"</font>));
iVal >>= 1;
} BUT ! if you have a string, unless you cast its content into a binary (short, int or long) type, this method is not applyable beacause of the risk of bits lack (overflow).
do you already have some shorst ideas on the subject to share ?
[EDIT]
...And as Mr Giorgi Moniava asked to Mr Prakash, i'll try to explain a bit more my code (which is quite similar to Mr Prakash's).
- with CString::Insert(0, ...), I add at position 0 the second parameter (i hope i place them in the right order).
- with (iVal & 0x00000001), I use the Bitwise-AND operation to get if the lower bit is set at 1 or 0. In fact, I should have written ((iVal & 0x00000001) == 0x00000001). this operation does this :
iVal -> 100010101101011010010100001010011
& 000000000000000000000000000000001
-------------------------------------
== 000000000000000000000000000000001
iVal -> 100010101101011010010100001010100
& 000000000000000000000000000000001
-------------------------------------
== 000000000000000000000000000000000
that's what Mr Prakash does with its mask .
- if you know about the C/C++ operator ?: , you also know that if its 1st parameter (the condition) is true, then the 2nd parameter is returned, otherwise, it is the 3rd parameter to be returned.
This way, the condition is true if the LSB (Lower Significant Bit) is set to 1. So, i insert "1" in the string.
- Then, i shift all the bits to the right and test again what i've just done before...
[/EDIT]
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
i copied this code to my program and it works ideally to my surprise ,because i am unfamiliar to things like "0x00000001" , but unfortunately i need to cenvert Strings to Binary Strings ex : "17"DEC="10001"BIN and they appear to be very long(100 or more digits), anyway i'd be very thankful to you if you could give me a little explanation on how your code works,
THanks in advance
m0n0
|
|
|
|
|
Giorgi Moniava wrote:
anyway i'd be very thankful to you if you could give me a little explanation on how your code works,
certainly....
read again my previous post. i've added some explainations about my code at its end...
cheers,
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Hi!
I'm designing a toolbar for my aplication with 64x64 buttons. I want to store them all as 256color bitmaps in resources for my app.. This is the code i'm using:
<br />
m_wndToolBar = ::CreateWindowEx (0, TOOLBARCLASSNAME, NULL,ATL_SIMPLE_TOOLBAR_PANE_STYLE, 0, 0, 64, 64, m_hWnd,(HMENU) LongToHandle (ATL_IDW_TOOLBAR), _Module .GetModuleInstance (),NULL);<br />
<br />
TBBUTTON tbb[3];<br />
char blah[250];<br />
sprintf(blah,"Hamsters!!!");<br />
<br />
tbb[0].idCommand = 1; <br />
tbb[0].fsState = TBSTATE_ENABLED; <br />
tbb[0].fsStyle = BTNS_BUTTON|BTNS_AUTOSIZE;<br />
tbb[0].dwData = 0; <br />
tbb[0].iBitmap = 0;<br />
tbb[0].iString = (int)&blah;<br />
<br />
tbb[1].idCommand = 2; <br />
tbb[1].fsState = TBSTATE_ENABLED; <br />
tbb[1].fsStyle = BTNS_BUTTON|BTNS_AUTOSIZE;<br />
tbb[1].dwData = 0; <br />
tbb[1].iBitmap = 1;<br />
tbb[1].iString = (int)&blah; <br />
<br />
tbb[2].idCommand = 3; <br />
tbb[2].fsState = TBSTATE_ENABLED; <br />
tbb[2].fsStyle = BTNS_BUTTON|BTNS_AUTOSIZE; <br />
tbb[2].dwData = 0;<br />
tbb[2].iBitmap = 1;<br />
tbb[2].iString = (int)&blah;<br />
<br />
<br />
list .Create(64, 64, ILC_COLOR, 1, 1);<br />
CBitmap bmSmall;<br />
bmSmall .LoadBitmap (IDB_BITMAP1);<br />
list .Add (bmSmall);<br />
list .SetBkColor (::GetSysColor (COLOR_3DFACE));<br />
<br />
<br />
m_wndToolBar .SetButtonStructSize (sizeof (TBBUTTON));<br />
m_wndToolBar .SetExtendedStyle (TBSTYLE_EX_DRAWDDARROWS|TBSTYLE_EX_MIXEDBUTTONS);<br />
m_wndToolBar .SetMaxTextRows (1);<br />
m_wndToolBar .SetImageList(list);<br />
m_wndToolBar .SetButtonSize (64,64);<br />
m_wndToolBar.AddButtons(3,tbb);<br />
<br />
m_wndToolBar.UpdateWindow();<br />
My problem is that the toolbar doesn't want to show any of my buttons' images! What am i doing wrong? Thanks
|
|
|
|
|
Hi,
I want to create a CAsyncSocket in an array and then get this
variable.I used this but dinn't work:
CObArray ob;
CAsyncSocket cl1;
CAsyncSocket cl2;
CAsyncSocket server;
ob.Add(&cl1);
ob.Add(&cl2);
server.Accept((CAsyncSocket*)ob[0]);
Please help me and tell me what is wrong?
Thanks.
|
|
|
|