CString help

I'm looking at a website on CString Management:

http://www.codeproject.com:80/string/cstringmgmt.asp

In the section entitled, "CString to char * II: Using GetBuffer," the author 
stresses calling ReleaseBuffer after calling GetBuffer.

Is this always necessary?

I often use CString::GetBuffer when using CStrings in MessageBox dialogs 
like so:

MessageBox(m_hWnd, cString.GetBuffer(0), lpTitle, MB_OK);

Should I be adding a ReleaseBuffer after a MessageBox call?

Should I be passing my string data to the MessageBox in another way?

Regards,
Joe 


0
jp2code
6/21/2007 7:17:04 PM
vc.mfc 33608 articles. 0 followers. Follow

38 Replies
885 Views

Similar Articles

[PageSpeed] 1

> Is this always necessary?
>
> I often use CString::GetBuffer when using CStrings in MessageBox dialogs
> like so:
>
> MessageBox(m_hWnd, cString.GetBuffer(0), lpTitle, MB_OK);

Why use GetBuffer here? You dont need it. Just pass the CString.
Operator LPCTSTR will take care of the rest.

Also, you must call ReleaseBuffer after calling GetBuffer:
http://msdn2.microsoft.com/en-us/library/ms928943.aspx

---
Ajay



0
ajaykalra (6840)
6/21/2007 7:25:21 PM
On Thu, 21 Jun 2007 14:17:04 -0500, "jp2code" <poojo.com/mail> wrote:

>I'm looking at a website on CString Management:
>
>http://www.codeproject.com:80/string/cstringmgmt.asp

This article is by our Joe.
I think that going to his MVP web site would be better, because I
don't know if the CodeProject version of the article is updated like
Joe's own web site version:

http://www.flounder.com/cstring.htm


>In the section entitled, "CString to char * II: Using GetBuffer," the author 
>stresses calling ReleaseBuffer after calling GetBuffer.
>
>Is this always necessary?

I think so.
MSDN seems to say the same thing:

<cite url"=http://msdn2.microsoft.com/en-us/library/ms928943.aspx">
If you use the pointer returned by GetBuffer to change the string
contents, you must call ReleaseBuffer before using any other CString
methods.
</cite>



>I often use CString::GetBuffer when using CStrings in MessageBox dialogs 
>like so:
>
>MessageBox(m_hWnd, cString.GetBuffer(0), lpTitle, MB_OK);

In an MFC context, a simple call to 

  AfxMessageBox( cString ); 

is fine.


MrAsm
0
mrasm (715)
6/21/2007 7:31:03 PM
Wow! Thanks gang! I had 27 occurrences of "GetBuffer(0)" in my code, and not 
one call to ReleaseBuffer.

That's fixed now, though.

I have a little Borland background. There, I had to use AnsiString (like 
std::string) and I accessed the data using AnsiString::c_str(). When I first 
started using VC, GetBuffer looked like Msft's equivalent. Wrong! :)

"Ajay Kalra" wrote:
>
> Why use GetBuffer here? You dont need it. Just pass the CString.
> Operator LPCTSTR will take care of the rest.
>
> Also, you must call ReleaseBuffer after calling GetBuffer:
> http://msdn2.microsoft.com/en-us/library/ms928943.aspx
>
> ---
> Ajay
>



0
jp2code
6/21/2007 7:57:05 PM
On Jun 21, 3:57 pm, "jp2code" <poojo.com/mail> wrote:
> Wow! Thanks gang! I had 27 occurrences of "GetBuffer(0)" in my code, and not
> one call to ReleaseBuffer.
>

Hopefully you are not using GetBuffer/ReleaseBuffer in MessageBox.

---
Ajay

0
ajaykalra (6840)
6/21/2007 8:03:09 PM
No, I'm not. I just deleted all of those. :)

Apparently, I have no need to call GetBuffer!

>
> Hopefully you are not using GetBuffer/ReleaseBuffer in MessageBox.
>
> ---
> Ajay
> 


0
jp2code
6/21/2007 8:08:34 PM
On Thu, 21 Jun 2007 15:08:34 -0500, "jp2code" <poojo.com/mail> wrote:

>Apparently, I have no need to call GetBuffer!

IMHO, it is very uncommon to call GetBuffer...

MrAsm
0
mrasm (715)
6/21/2007 8:13:27 PM
I use GetBuffer() if I need to pass a pointer to a routine that needs to 
modify the buffer (I.E., a LPTSTR).  In those cases you will need to call 
ReleaseBuffer() since the buffer may have changed.  If you are sure the 
buffer was not changed (I.E., you are just reading through it using a 
pointer) you don't need to call ReleaseBuffer().

Tom

"MrAsm" <mrasm@usa.com> wrote in message 
news:ssml73d5j1oivaf8pc94tlit6t0m1gbha6@4ax.com...
> On Thu, 21 Jun 2007 15:08:34 -0500, "jp2code" <poojo.com/mail> wrote:
>
>>Apparently, I have no need to call GetBuffer!
>
> IMHO, it is very uncommon to call GetBuffer...
>
> MrAsm 

0
tom.nospam (3240)
6/21/2007 8:49:02 PM
Hi David,

Doesn't std::string have c_str() to do something similar?  I don't use 
std::string, much, so I could be wrong on this one.

Tom

"David Wilkinson" <no-reply@effisols.com> wrote in message 
news:OTwehBEtHHA.2752@TK2MSFTNGP06.phx.gbl...
> jp2code wrote:
>> Wow! Thanks gang! I had 27 occurrences of "GetBuffer(0)" in my code, and 
>> not one call to ReleaseBuffer.
>>
>> That's fixed now, though.
>>
>> I have a little Borland background. There, I had to use AnsiString (like 
>> std::string) and I accessed the data using AnsiString::c_str(). When I 
>> first started using VC, GetBuffer looked like Msft's equivalent. Wrong! 
>> :)
>
> I don't know Borland, but I would imagine that AnsiString::c_str() returns 
> const char*. CString::GetBuffer() returns char* (in ANSI build), a string 
> whose contents you can modify.
>
> CString::GetBuffer() can increase efficiency in some situations, but is 
> best avoided, IMHO. You will notice that std::string has no such 
> mechanism.
>
> -- 
> David Wilkinson
> Visual C++ MVP 

0
tom.nospam (3240)
6/21/2007 9:02:07 PM
jp2code wrote:
> Wow! Thanks gang! I had 27 occurrences of "GetBuffer(0)" in my code, and not 
> one call to ReleaseBuffer.
> 
> That's fixed now, though.
> 
> I have a little Borland background. There, I had to use AnsiString (like 
> std::string) and I accessed the data using AnsiString::c_str(). When I first 
> started using VC, GetBuffer looked like Msft's equivalent. Wrong! :)

I don't know Borland, but I would imagine that AnsiString::c_str() 
returns const char*. CString::GetBuffer() returns char* (in ANSI build), 
a string whose contents you can modify.

CString::GetBuffer() can increase efficiency in some situations, but is 
best avoided, IMHO. You will notice that std::string has no such mechanism.

-- 
David Wilkinson
Visual C++ MVP
0
no-reply8010 (1790)
6/21/2007 9:12:05 PM
Tom Serface wrote:
> Hi David,
> 
> Doesn't std::string have c_str() to do something similar?  I don't use 
> std::string, much, so I could be wrong on this one.

Tom:

c_str() returns const char*, not char*. The buffer cannot be modified 
without using const_cast tricks which may corrupt the string.

-- 
David Wilkinson
Visual C++ MVP
0
no-reply8010 (1790)
6/21/2007 10:31:47 PM
"jp2code" <poojo.com/mail> wrote in message 
news:e1xRCjDtHHA.3732@TK2MSFTNGP02.phx.gbl...

> In the section entitled, "CString to char * II: Using GetBuffer," the 
> author stresses calling ReleaseBuffer after calling GetBuffer.

Why do you want to use GetBuffer()?

Too be sure, it is there, but in a dozen years of using CStrings I cannot 
remember ever needing it once!   CString provides copious methods for 
manipulating the string.

And it has a cast to const TCHAR * in order to send it to functions which 
just need to read the string.   The result is that you can effectively pass 
a Cstring to any function which has an argument of type LPCTSTR.  (Including 
message boxes, but many more things too.)

Using GetBuffer() tells the CString  "I am going to do something underhand 
to your contents which you can't manage for yourself, so don't try any funny 
business while I'm doing it."     [The following ReleaseBuffer() is a 
promise to the CString that you have finished buggering about with it, and 
that it has permnission to manage itself again.]

 > Is this always necessary?
>
> I often use CString::GetBuffer when using CStrings in MessageBox dialogs 
> like so:
>
> MessageBox(m_hWnd, cString.GetBuffer(0), lpTitle, MB_OK);

That is a very bad idea.

> Should I be passing my string data to the MessageBox in another way?

Yes.

    MessageBox(m_hWnd, cString, lpTitle, MB_OK);

will do just fine.   Why tell the CString you are going to mess it about, 
when all you are doing is reading it?

If you really want to keep explicit track of what you're doing, then

    MessageBox(m_hWnd, (LPCTSTR)cString, lpTitle, MB_OK);

will remind you, but an implicit cast is sufficient.

Dave
-- 
David Webber
Author of 'Mozart the Music Processor'
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mzusers/mailinglist.htm

0
dave9996 (486)
6/21/2007 10:51:42 PM
First, you are likely reading my essay.

So why would you need to call CString::GetBuffer in a MessageBox call?  There's no useful
purpose served by doing that.  In fact, you should be doing
	AfxMessageBox(cString, MB_OK);

Microsoft guidelines say the title should be the name of the program, so there is no
reason to use a different title.  There is no reason to use m_hWnd since there is already
a CWnd::MessageBox call, so you would write
	MessageBox(cString, lpTitle, MBOK);

So your complaint is that you are doing something unnecessary?
				joe

On Thu, 21 Jun 2007 14:17:04 -0500, "jp2code" <poojo.com/mail> wrote:

>I'm looking at a website on CString Management:
>
>http://www.codeproject.com:80/string/cstringmgmt.asp
>
>In the section entitled, "CString to char * II: Using GetBuffer," the author 
>stresses calling ReleaseBuffer after calling GetBuffer.
>
>Is this always necessary?
>
>I often use CString::GetBuffer when using CStrings in MessageBox dialogs 
>like so:
>
>MessageBox(m_hWnd, cString.GetBuffer(0), lpTitle, MB_OK);
>
>Should I be adding a ReleaseBuffer after a MessageBox call?
>
>Should I be passing my string data to the MessageBox in another way?
>
>Regards,
>Joe 
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15977)
6/21/2007 11:12:13 PM
Ah, that makes sense thanks.  All I've ever used it for was assigning the 
string to a CString ...

Tom

"David Wilkinson" <no-reply@effisols.com> wrote in message 
news:%23ccODuEtHHA.3556@TK2MSFTNGP05.phx.gbl...
> Tom Serface wrote:

> c_str() returns const char*, not char*. The buffer cannot be modified 
> without using const_cast tricks which may corrupt the string.
>
> -- 
> David Wilkinson
> Visual C++ MVP 

0
tom.nospam (3240)
6/21/2007 11:31:35 PM
> In fact, you should be doing
>      AfxMessageBox(cString, MB_OK);

And even better:
    AfxMessageBox(IDS_STRING_TEST);
You don't put on screen something that is not stored in resources, right?
(I know, the exception is if the string is used for a FormatMessage before)


-- 
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
0
6/22/2007 5:21:39 AM
> CString::GetBuffer() can increase efficiency in some situations, but is 
> best avoided, IMHO. You will notice that std::string has no such mechanism.

To be avoided, but still best to have it.
I think it is bad that std::string does not have such a thing.
See my "std::string internal buffer access" note at
http://www.mihai-nita.net/article.php?artID=20060430a


-- 
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
0
6/22/2007 5:25:43 AM
Hi Mihai,

Nice to see you back.

This is true unless the string came from somewhere during runtime (like the 
string from a system error).

That said, I try to put every string possible (often even format strings) in 
the resource editor and use the FormatMessage version using %1 %2, etc. so 
that the translator can simply switch the order of the parameters at 
runtime.  Very convenient.

Tom

"Mihai N." <nmihai_year_2000@yahoo.com> wrote in message 
news:Xns9956E379515C8MihaiN@207.46.248.16...
>
> And even better:
>    AfxMessageBox(IDS_STRING_TEST);
> You don't put on screen something that is not stored in resources, right?
> (I know, the exception is if the string is used for a FormatMessage 
> before)

0
tom.nospam (3240)
6/22/2007 2:12:44 PM
Good point; I presumed that the string had already been obtained by a localized technique.
				joe

On Thu, 21 Jun 2007 22:21:39 -0700, "Mihai N." <nmihai_year_2000@yahoo.com> wrote:

>> In fact, you should be doing
>>      AfxMessageBox(cString, MB_OK);
>
>And even better:
>    AfxMessageBox(IDS_STRING_TEST);
>You don't put on screen something that is not stored in resources, right?
>(I know, the exception is if the string is used for a FormatMessage before)
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15977)
6/22/2007 2:45:14 PM
Mr. Serface,

Do you have a little tutorial describing what you're talking about?

Regards,
Joe

"Tom Serface" <tom.nospam@camaswood.com> wrote in message 
news:1E49DC41-823B-4232-A50F-2EC5D8991ABC@microsoft.com...
> Hi Mihai,
>
> Nice to see you back.
>
> This is true unless the string came from somewhere during runtime (like 
> the string from a system error).
>
> That said, I try to put every string possible (often even format strings) 
> in the resource editor and use the FormatMessage version using %1 %2, etc. 
> so that the translator can simply switch the order of the parameters at 
> runtime.  Very convenient.
>
> Tom
>
> "Mihai N." <nmihai_year_2000@yahoo.com> wrote in message 
> news:Xns9956E379515C8MihaiN@207.46.248.16...
>>
>> And even better:
>>    AfxMessageBox(IDS_STRING_TEST);
>> You don't put on screen something that is not stored in resources, right?
>> (I know, the exception is if the string is used for a FormatMessage 
>> before)
> 


0
jp2code
6/22/2007 3:15:22 PM
I can explain it better.  Basically, if you use FormatMessage rather than 
Format your argument string tokens are represented as %1, %2, %3 rather than 
things like %s %c %d.  You would mostly do strings, but you can also do 
numbers with a format like %1!d!.  The advantage is when you call 
FormatMessage() the arguments to the function remain positional, but the 
tokens can be rearranged depending on language use.  For example: in English 
the order might be "XXX: %1 %2 %3", but in Spanish it might be "%2 %3 %1 : 
XXX".  The format can change, but you don't have to change the code.  In the 
Format/printf paradigm you sould have to actually change the argument 
sequence as the tokens (%s, %d, %c, ...) are not positional.

In the case of FormatMessage the above example:

IDS_FORMATRESOURCE "XXX: %1 %2 %3"

CString cs;
cs.FormatMessage(IDS_FORMATERESOURCE,csDate, csTime, csOption);

There would be another version of IDS_FORMATRESOURCE in each language 
satellite DLL.

Joe's tutorial might be interesting to you also:

http://www.flounder.com/formatmessage.htm

Tom

"jp2code" <poojo.com/mail> wrote in message 
news:O$bmoAOtHHA.3400@TK2MSFTNGP03.phx.gbl...
> Mr. Serface,
>
> Do you have a little tutorial describing what you're talking about?
>
> Regards,
> Joe
>
> "Tom Serface" <tom.nospam@camaswood.com> wrote in message 
> news:1E49DC41-823B-4232-A50F-2EC5D8991ABC@microsoft.com...
>> Hi Mihai,
>>
>> Nice to see you back.
>>
>> This is true unless the string came from somewhere during runtime (like 
>> the string from a system error).
>>
>> That said, I try to put every string possible (often even format strings) 
>> in the resource editor and use the FormatMessage version using %1 %2, 
>> etc. so that the translator can simply switch the order of the parameters 
>> at runtime.  Very convenient.
>>
>> Tom
>>
>> "Mihai N." <nmihai_year_2000@yahoo.com> wrote in message 
>> news:Xns9956E379515C8MihaiN@207.46.248.16...
>>>
>>> And even better:
>>>    AfxMessageBox(IDS_STRING_TEST);
>>> You don't put on screen something that is not stored in resources, 
>>> right?
>>> (I know, the exception is if the string is used for a FormatMessage 
>>> before)
>>
>
> 

0
tom.nospam (3240)
6/22/2007 5:13:24 PM
On Thu, 21 Jun 2007 22:25:43 -0700, "Mihai N." <nmihai_year_2000@yahoo.com>
wrote:

>> CString::GetBuffer() can increase efficiency in some situations, but is 
>> best avoided, IMHO. You will notice that std::string has no such mechanism.
>
>To be avoided, but still best to have it.
>I think it is bad that std::string does not have such a thing.
>See my "std::string internal buffer access" note at
>http://www.mihai-nita.net/article.php?artID=20060430a

Practically speaking, you can do this:

   const int N = 100;
   std::string s;
   s.resize(N);
   int len = WindowsAPI(&s[0], N);
   s.resize(len);

Though not guaranteed, I don't know any implementation where this won't
work. (I'd really like the non-contiguity, reference-counted, etc options
to just go away. People who need those things can't do without them, and
the possibility they exist complicates things for everyone else.)

Aside: MSDN has gotten a lot better about defining the meaning of N in the
code above. As a function parameter, it usually indicates the maximum
number of characters that may be written to the buffer, including the
terminating nul. As a return value, it usually indicates the number of
characters actually written, excluding the nul. This is true for functions
like GetWindowText, which truncate the returned text as necessary. What
does this imply for the return value?

-- 
Doug Harrison
Visual C++ MVP
0
dsh (2499)
6/22/2007 10:03:03 PM
One of the odd rules is that if you have a trucating API call, then the deal is that if
you get a value n that is equal to (for non-string values) or equal to one less than (for
string values) the size of the buffer, you need to double the buffer and read again,
repeat until the size read is truly less than the buffer size.
						joe

On Fri, 22 Jun 2007 17:03:03 -0500, "Doug Harrison [MVP]" <dsh@mvps.org> wrote:

>On Thu, 21 Jun 2007 22:25:43 -0700, "Mihai N." <nmihai_year_2000@yahoo.com>
>wrote:
>
>>> CString::GetBuffer() can increase efficiency in some situations, but is 
>>> best avoided, IMHO. You will notice that std::string has no such mechanism.
>>
>>To be avoided, but still best to have it.
>>I think it is bad that std::string does not have such a thing.
>>See my "std::string internal buffer access" note at
>>http://www.mihai-nita.net/article.php?artID=20060430a
>
>Practically speaking, you can do this:
>
>   const int N = 100;
>   std::string s;
>   s.resize(N);
>   int len = WindowsAPI(&s[0], N);
>   s.resize(len);
>
>Though not guaranteed, I don't know any implementation where this won't
>work. (I'd really like the non-contiguity, reference-counted, etc options
>to just go away. People who need those things can't do without them, and
>the possibility they exist complicates things for everyone else.)
>
>Aside: MSDN has gotten a lot better about defining the meaning of N in the
>code above. As a function parameter, it usually indicates the maximum
>number of characters that may be written to the buffer, including the
>terminating nul. As a return value, it usually indicates the number of
>characters actually written, excluding the nul. This is true for functions
>like GetWindowText, which truncate the returned text as necessary. What
>does this imply for the return value?
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15977)
6/23/2007 2:10:57 AM
> &s[0]
....
> Though not guaranteed, I don't know any implementation where this won't
> work.

Possible, but implementation speciffic.
Since it is not captured in the standard in any way, it can disapear at any 
time.
(and in fact I think I know a case where this might break: flex_string of 
Andrei Alexandrescu, a very nice string class, standard compliant).


-- 
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
0
6/23/2007 8:35:24 AM
Hi,

> Nice to see you back.
I was around, but had nothing to add (enough good answers already :-)


> I try to put every string possible (often even format strings) in 
> the resource editor and use the FormatMessage version using %1 %2, etc. so 
> that the translator can simply switch the order of the parameters at 
> runtime.  Very convenient.
True. Both CString + FormatMessage take a string ID, forming a great
combination for good localizability.


-- 
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
0
6/23/2007 8:39:58 AM
On Sat, 23 Jun 2007 01:35:24 -0700, "Mihai N." <nmihai_year_2000@yahoo.com>
wrote:

>> &s[0]
>...
>> Though not guaranteed, I don't know any implementation where this won't
>> work.
>
>Possible, but implementation speciffic.
>Since it is not captured in the standard in any way, it can disapear at any 
>time.

Which is why I said:

>>I'd really like the non-contiguity, reference-counted, etc options to just
>>go away. People who need those things can't do without them, and the
>>possibility they exist complicates things for everyone else.

Again, I don't know of any implementation of std::string for which it won't
work, and I expect there would be tremendous resistance to breaking that
sort of code. Furthermore, I bet I can find other non-portable use of
std::string in most every program that makes non-trivial use of it. With at
least 2^4 possible implementations, it's a near certainty.

On a happy note, it appears the contiguity assumption will finally be made
a requirement (note well the rationale, in particular its last sentence):

530. Must elements of a string be contiguous?
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#530

I'm happy to learn of that, but my argument has always been that it's crazy
for a "basic" string to have upwards of 2^4 possible implementations with
wildly difference behavior and performance. Sometimes, too much freedom is
a bad thing, and it's clearly the case here. A basic_string ought to be
"basic", and someone needing a "fancy" string is well-advised to use one
that guarantees the things he requires.

>(and in fact I think I know a case where this might break: flex_string of 
>Andrei Alexandrescu, a very nice string class, standard compliant).

But flex_string != std::basic_string. I skimmed the DDJ article here:

http://www.ddj.com/dept/cpp/184403784

I see Andrei talked at length about "Standard-compliant" and COW. The
problem is, the two aren't compatible, at least if you think
"copy-on-write" actually means "copy-on-write".

-- 
Doug Harrison
Visual C++ MVP
0
dsh (2499)
6/23/2007 5:11:43 PM
Did anyone at Microsoft notice that there is no form of FormatMessage that allows an error
code or the specification of a instance handle for an executable that contains a Message
Table?  How could such critical capability been omitted?
						joe


On Sat, 23 Jun 2007 01:39:58 -0700, "Mihai N." <nmihai_year_2000@yahoo.com> wrote:

>Hi,
>
>> Nice to see you back.
>I was around, but had nothing to add (enough good answers already :-)
>
>
>> I try to put every string possible (often even format strings) in 
>> the resource editor and use the FormatMessage version using %1 %2, etc. so 
>> that the translator can simply switch the order of the parameters at 
>> runtime.  Very convenient.
>True. Both CString + FormatMessage take a string ID, forming a great
>combination for good localizability.
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15977)
6/23/2007 7:56:48 PM
On Fri, 22 Jun 2007 22:10:57 -0400, Joseph M. Newcomer
<newcomer@flounder.com> wrote:

>>Aside: MSDN has gotten a lot better about defining the meaning of N in the
>>code above. As a function parameter, it usually indicates the maximum
>>number of characters that may be written to the buffer, including the
>>terminating nul. As a return value, it usually indicates the number of
>>characters actually written, excluding the nul. This is true for functions
>>like GetWindowText, which truncate the returned text as necessary. What
>>does this imply for the return value?
>
>One of the odd rules is that if you have a trucating API call, then the deal is that if
>you get a value n that is equal to (for non-string values) or equal to one less than (for
>string values) the size of the buffer, you need to double the buffer and read again,
>repeat until the size read is truly less than the buffer size.
>						joe

Yep, it's weird. For a function like GetWindowText, the parameter N is a
"can't happen" return value (except for N == 0, I guess). If you get N-1,
you don't know if the string was exactly N-1 characters long or the API
truncated it, so like you say, you have to assume the worst if you want to
read the whole thing. This is all rather subtle, but I don't see a better
way to do it. If the API were to return the actual number of characters
written, including the nul, it wouldn't be returning the string length, and
that's too useful to give up.

-- 
Doug Harrison
Visual C++ MVP
0
dsh (2499)
6/23/2007 8:40:39 PM
FORMAT_MESSAGE_FROM_HMODULE?

What you mean by "error code"?

"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:tluq73998bac5kvd4ubc9plg9h2r075tcm@4ax.com...
> Did anyone at Microsoft notice that there is no form of FormatMessage that 
> allows an error
> code or the specification of a instance handle for an executable that 
> contains a Message
> Table?  How could such critical capability been omitted?
> joe
>
>
> On Sat, 23 Jun 2007 01:39:58 -0700, "Mihai N." 
> <nmihai_year_2000@yahoo.com> wrote:
>
>>Hi,
>>
>>> Nice to see you back.
>>I was around, but had nothing to add (enough good answers already :-)
>>
>>
>>> I try to put every string possible (often even format strings) in
>>> the resource editor and use the FormatMessage version using %1 %2, etc. 
>>> so
>>> that the translator can simply switch the order of the parameters at
>>> runtime.  Very convenient.
>>True. Both CString + FormatMessage take a string ID, forming a great
>>combination for good localizability.
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm 


0
alegr (1130)
6/23/2007 10:33:22 PM
Of course, if you use GetWindowTextLength() first and allocate a buffer of the right size,
you have a reasonble confidence that you will get all the characters (the liklihood that
someone else will change the string contents from another thread is vanishingly small, and
is a case that could be ignored, in that if you GetTextLength() == N and you allocate a
buffer of N+1 characters, and get N characters back, then either it is dead-on-accurate or
somebody wrote a longer string it between the two calls, and a programmer may choose to
ignore that situation.
					joe

On Sat, 23 Jun 2007 15:40:39 -0500, "Doug Harrison [MVP]" <dsh@mvps.org> wrote:

>On Fri, 22 Jun 2007 22:10:57 -0400, Joseph M. Newcomer
><newcomer@flounder.com> wrote:
>
>>>Aside: MSDN has gotten a lot better about defining the meaning of N in the
>>>code above. As a function parameter, it usually indicates the maximum
>>>number of characters that may be written to the buffer, including the
>>>terminating nul. As a return value, it usually indicates the number of
>>>characters actually written, excluding the nul. This is true for functions
>>>like GetWindowText, which truncate the returned text as necessary. What
>>>does this imply for the return value?
>>
>>One of the odd rules is that if you have a trucating API call, then the deal is that if
>>you get a value n that is equal to (for non-string values) or equal to one less than (for
>>string values) the size of the buffer, you need to double the buffer and read again,
>>repeat until the size read is truly less than the buffer size.
>>						joe
>
>Yep, it's weird. For a function like GetWindowText, the parameter N is a
>"can't happen" return value (except for N == 0, I guess). If you get N-1,
>you don't know if the string was exactly N-1 characters long or the API
>truncated it, so like you say, you have to assume the worst if you want to
>read the whole thing. This is all rather subtle, but I don't see a better
>way to do it. If the API were to return the actual number of characters
>written, including the nul, it wouldn't be returning the string length, and
>that's too useful to give up.
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15977)
6/23/2007 10:50:59 PM
For example, ::GetLastError codes. These are often represented by MESSAGETABLE resources
in a module.  And yes, ::FormatMessage has all this capability, but CString::FormatMessage
exposes only some of the least interesting aspects of ::FormatMessage.
					joe
On Sat, 23 Jun 2007 15:33:22 -0700, "Alexander Grigoriev" <alegr@earthlink.net> wrote:

>FORMAT_MESSAGE_FROM_HMODULE?
>
>What you mean by "error code"?
>
>"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
>news:tluq73998bac5kvd4ubc9plg9h2r075tcm@4ax.com...
>> Did anyone at Microsoft notice that there is no form of FormatMessage that 
>> allows an error
>> code or the specification of a instance handle for an executable that 
>> contains a Message
>> Table?  How could such critical capability been omitted?
>> joe
>>
>>
>> On Sat, 23 Jun 2007 01:39:58 -0700, "Mihai N." 
>> <nmihai_year_2000@yahoo.com> wrote:
>>
>>>Hi,
>>>
>>>> Nice to see you back.
>>>I was around, but had nothing to add (enough good answers already :-)
>>>
>>>
>>>> I try to put every string possible (often even format strings) in
>>>> the resource editor and use the FormatMessage version using %1 %2, etc. 
>>>> so
>>>> that the translator can simply switch the order of the parameters at
>>>> runtime.  Very convenient.
>>>True. Both CString + FormatMessage take a string ID, forming a great
>>>combination for good localizability.
>> Joseph M. Newcomer [MVP]
>> email: newcomer@flounder.com
>> Web: http://www.flounder.com
>> MVP Tips: http://www.flounder.com/mvp_tips.htm 
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15977)
6/23/2007 11:25:04 PM
You're right about CString, but the function is pretty simple.  I use this 
one:

CRITICAL_ERROR CSpanRestoreDlg::DisplayCriticalError(DWORD nError)
{
     LPVOID lpMsgBuf;

     FormatMessage(
          FORMAT_MESSAGE_ALLOCATE_BUFFER |
          FORMAT_MESSAGE_FROM_SYSTEM,
          NULL,
          nError,
          MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
          (LPTSTR) &lpMsgBuf,
          0, NULL );
     CString cs;
     cs.FormatMessage(IDS_CRITICAL_ERROR,nError,lpMsgBuf);
     LocalFree(lpMsgBuf);
     int ret = AfxMessageBox(cs,MB_ICONSTOP | MB_ABORTRETRYIGNORE);
     if(ret == IDABORT)
          return CRITICAL_ABORT;
     else if(ret == IDRETRY)
          return CRITICAL_RETRY;
     else
          return CRITICAL_IGNORE;
}

customized a little for my specific use.

Tom
"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:vrar735etcclvtm4fkqnbk10uvs4hll59f@4ax.com...
> For example, ::GetLastError codes. These are often represented by 
> MESSAGETABLE resources
> in a module.  And yes, ::FormatMessage has all this capability, but 
> CString::FormatMessage
> exposes only some of the least interesting aspects of ::FormatMessage.
> joe
> On Sat, 23 Jun 2007 15:33:22 -0700, "Alexander Grigoriev" 
> <alegr@earthlink.net> wrote:
>
>>FORMAT_MESSAGE_FROM_HMODULE?
>>
>>What you mean by "error code"?
>>
>>"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
>>news:tluq73998bac5kvd4ubc9plg9h2r075tcm@4ax.com...
>>> Did anyone at Microsoft notice that there is no form of FormatMessage 
>>> that
>>> allows an error
>>> code or the specification of a instance handle for an executable that
>>> contains a Message
>>> Table?  How could such critical capability been omitted?
>>> joe
>>>
>>>
>>> On Sat, 23 Jun 2007 01:39:58 -0700, "Mihai N."
>>> <nmihai_year_2000@yahoo.com> wrote:
>>>
>>>>Hi,
>>>>
>>>>> Nice to see you back.
>>>>I was around, but had nothing to add (enough good answers already :-)
>>>>
>>>>
>>>>> I try to put every string possible (often even format strings) in
>>>>> the resource editor and use the FormatMessage version using %1 %2, 
>>>>> etc.
>>>>> so
>>>>> that the translator can simply switch the order of the parameters at
>>>>> runtime.  Very convenient.
>>>>True. Both CString + FormatMessage take a string ID, forming a great
>>>>combination for good localizability.
>>> Joseph M. Newcomer [MVP]
>>> email: newcomer@flounder.com
>>> Web: http://www.flounder.com
>>> MVP Tips: http://www.flounder.com/mvp_tips.htm
>>
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm 

0
tom.nospam (3240)
6/24/2007 4:20:17 AM
I have virtually identical code posted on my Web site as far as the conversion code; my
ErrorString function appears in nearly every piece of code I write.  But the real question
is why MFC never supported this?  It should have, if people were more concerned about
useful functionality instead of how to yet-once-again make the IDE even more unusable than
the last release, we might see something productive emerge, something that actually
ENHANCED the usability of the system.  Yet after all these years, we can't even add
extended reflected handlers, which should have been put in as soon as the _EX macros were
invented!  We've gone through four or six releases of MFC and the IDE and MFC *still*
doesn't have methods for every message, or handlers for every event!
					joe

On Sat, 23 Jun 2007 21:20:17 -0700, "Tom Serface" <tom.nospam@camaswood.com> wrote:

>You're right about CString, but the function is pretty simple.  I use this 
>one:
>
>CRITICAL_ERROR CSpanRestoreDlg::DisplayCriticalError(DWORD nError)
>{
>     LPVOID lpMsgBuf;
>
>     FormatMessage(
>          FORMAT_MESSAGE_ALLOCATE_BUFFER |
>          FORMAT_MESSAGE_FROM_SYSTEM,
>          NULL,
>          nError,
>          MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
>          (LPTSTR) &lpMsgBuf,
>          0, NULL );
>     CString cs;
>     cs.FormatMessage(IDS_CRITICAL_ERROR,nError,lpMsgBuf);
>     LocalFree(lpMsgBuf);
>     int ret = AfxMessageBox(cs,MB_ICONSTOP | MB_ABORTRETRYIGNORE);
>     if(ret == IDABORT)
>          return CRITICAL_ABORT;
>     else if(ret == IDRETRY)
>          return CRITICAL_RETRY;
>     else
>          return CRITICAL_IGNORE;
>}
>
>customized a little for my specific use.
>
>Tom
>"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
>news:vrar735etcclvtm4fkqnbk10uvs4hll59f@4ax.com...
>> For example, ::GetLastError codes. These are often represented by 
>> MESSAGETABLE resources
>> in a module.  And yes, ::FormatMessage has all this capability, but 
>> CString::FormatMessage
>> exposes only some of the least interesting aspects of ::FormatMessage.
>> joe
>> On Sat, 23 Jun 2007 15:33:22 -0700, "Alexander Grigoriev" 
>> <alegr@earthlink.net> wrote:
>>
>>>FORMAT_MESSAGE_FROM_HMODULE?
>>>
>>>What you mean by "error code"?
>>>
>>>"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
>>>news:tluq73998bac5kvd4ubc9plg9h2r075tcm@4ax.com...
>>>> Did anyone at Microsoft notice that there is no form of FormatMessage 
>>>> that
>>>> allows an error
>>>> code or the specification of a instance handle for an executable that
>>>> contains a Message
>>>> Table?  How could such critical capability been omitted?
>>>> joe
>>>>
>>>>
>>>> On Sat, 23 Jun 2007 01:39:58 -0700, "Mihai N."
>>>> <nmihai_year_2000@yahoo.com> wrote:
>>>>
>>>>>Hi,
>>>>>
>>>>>> Nice to see you back.
>>>>>I was around, but had nothing to add (enough good answers already :-)
>>>>>
>>>>>
>>>>>> I try to put every string possible (often even format strings) in
>>>>>> the resource editor and use the FormatMessage version using %1 %2, 
>>>>>> etc.
>>>>>> so
>>>>>> that the translator can simply switch the order of the parameters at
>>>>>> runtime.  Very convenient.
>>>>>True. Both CString + FormatMessage take a string ID, forming a great
>>>>>combination for good localizability.
>>>> Joseph M. Newcomer [MVP]
>>>> email: newcomer@flounder.com
>>>> Web: http://www.flounder.com
>>>> MVP Tips: http://www.flounder.com/mvp_tips.htm
>>>
>> Joseph M. Newcomer [MVP]
>> email: newcomer@flounder.com
>> Web: http://www.flounder.com
>> MVP Tips: http://www.flounder.com/mvp_tips.htm 
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15977)
6/24/2007 5:33:47 PM
On Sat, 23 Jun 2007 18:50:59 -0400, Joseph M. Newcomer
<newcomer@flounder.com> wrote:

>Of course, if you use GetWindowTextLength() first and allocate a buffer of the right size,
>you have a reasonble confidence that you will get all the characters (the liklihood that
>someone else will change the string contents from another thread is vanishingly small, and
>is a case that could be ignored, in that if you GetTextLength() == N and you allocate a
>buffer of N+1 characters, and get N characters back, then either it is dead-on-accurate or
>somebody wrote a longer string it between the two calls, and a programmer may choose to
>ignore that situation.
>					joe

Sure, that's how I actually did it in my string class:

   const size_type len = ::GetWindowTextLength(hWnd);
   uninitialized_resize(len);
   // Windows doesn't truncate in the strncpy sense; it always
   // nul-terminates.
   resize(::GetWindowText(hWnd, raw_data(), len+1));
   return *this;

I wrote this almost 10 years ago as part of a std::basic_string-like class
that provides true COW, which I still use today. I talked some more about
it here:

http://groups.google.com/group/microsoft.public.vc.stl/msg/fa3c6c5d1ba99453

My string class always makes room for the terminating nul, so the
uninitialized_resize call is indeed correct. That function differs from
resize in that it doesn't initialize the new space when growing the string,
and it was written for exactly this usage pattern. The function raw_data()
is like data() except it returns a non-const pointer. Ironically, I can't
use the &s[0] approach, because s[0] returns a reference object that is
actually of class type, and taking its address returns an iterator, not a
pointer. This is where I deviated from the standard, and it was necessary
to support real COW.

-- 
Doug Harrison
Visual C++ MVP
0
dsh (2499)
6/24/2007 5:45:04 PM
>>(and in fact I think I know a case where this might break: flex_string of 
>>Andrei Alexandrescu, a very nice string class, standard compliant).
> 
> But flex_string != std::basic_string. I skimmed the DDJ article here:
> 
> http://www.ddj.com/dept/cpp/184403784
> 
> I see Andrei talked at length about "Standard-compliant" and COW. The
> problem is, the two aren't compatible, at least if you think
> "copy-on-write" actually means "copy-on-write".

I don't think there is any standard requirement for "copy-on-write" behavior,
that is implementation speciffic.
for me standard-compliant is good enough. It means at any time some
compiler crator can decide to drop his implementation and adopt Andrei's
implementation.
Even the DDJ article says "a policy-based basic_string implementation"
It is an implementation, and I don't know based on what criteria one can
say that flex_string != std::basic_string

The standard does not provide an implementation. So if I write something
that exposes all the public behavior and methods required by the C++
standard for std::basic_string, then the class *is* std::basic_string


-- 
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
0
6/24/2007 9:11:59 PM
On Sun, 24 Jun 2007 14:11:59 -0700, "Mihai N." <nmihai_year_2000@yahoo.com>
wrote:

>>>(and in fact I think I know a case where this might break: flex_string of 
>>>Andrei Alexandrescu, a very nice string class, standard compliant).
>> 
>> But flex_string != std::basic_string. I skimmed the DDJ article here:
>> 
>> http://www.ddj.com/dept/cpp/184403784
>> 
>> I see Andrei talked at length about "Standard-compliant" and COW. The
>> problem is, the two aren't compatible, at least if you think
>> "copy-on-write" actually means "copy-on-write".
>
>I don't think there is any standard requirement for "copy-on-write" behavior,
>that is implementation speciffic.

Of course the standard doesn't require it. What I was getting at is that
the standard does not permit COW.

>for me standard-compliant is good enough. It means at any time some
>compiler crator can decide to drop his implementation and adopt Andrei's
>implementation.
>Even the DDJ article says "a policy-based basic_string implementation"
>It is an implementation, and I don't know based on what criteria one can
>say that flex_string != std::basic_string

I don't know any standard library implementation that comes with
flex_string renamed to basic_string.

>The standard does not provide an implementation. So if I write something
>that exposes all the public behavior and methods required by the C++
>standard for std::basic_string, then the class *is* std::basic_string

And you should feel free to use it. Just make sure you've observed all the
little nuances necessary to use std::string in a truly portable way.

-- 
Doug Harrison
Visual C++ MVP
0
dsh (2499)
6/24/2007 9:21:04 PM
> I don't know any standard library implementation that comes with
> flex_string renamed to basic_string.
True.

> And you should feel free to use it. Just make sure you've observed all the
> little nuances necessary to use std::string in a truly portable way.
After reading your open-std.org link it seems I can do this, but not for long
:-)

But reading it, I still think there is no decend standard way to write
something in a standard string in a standard way.
Even if the storage is contigous, the data is still const, you I cannot
safely change it.


-- 
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
0
6/24/2007 9:33:54 PM
On Sun, 24 Jun 2007 14:33:54 -0700, "Mihai N." <nmihai_year_2000@yahoo.com>
wrote:

>But reading it, I still think there is no decend standard way to write
>something in a standard string in a standard way.
>Even if the storage is contigous, the data is still const, you I cannot
>safely change it.

The following will be fine:

   string s;
   s.resize(n);
   memcpy(&s[0], 0, n);

One of the benefits to requiring s[0] to return a real reference (which is
what disallows COW) is that &s[0] returns a real pointer.

-- 
Doug Harrison
Visual C++ MVP
0
dsh (2499)
6/24/2007 10:10:05 PM
Yeah, I'm hoping a version coming up soon will have some of this fleshed 
out.  It seems like most of the stuff you mention should be table driven and 
easy enough to add to the IDE.  Now that MSFT is focusing again on MFC as a 
native solution I'm hoping it gets some attention.

Tom

"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:iiat73tsjk0vbnid23847fo1u0tda8mgpa@4ax.com...
>I have virtually identical code posted on my Web site as far as the 
>conversion code; my
> ErrorString function appears in nearly every piece of code I write.  But 
> the real question
> is why MFC never supported this?  It should have, if people were more 
> concerned about
> useful functionality instead of how to yet-once-again make the IDE even 
> more unusable than
> the last release, we might see something productive emerge, something that 
> actually
> ENHANCED the usability of the system.  Yet after all these years, we can't 
> even add
> extended reflected handlers, which should have been put in as soon as the 
> _EX macros were
> invented!  We've gone through four or six releases of MFC and the IDE and 
> MFC *still*
> doesn't have methods for every message, or handlers for every event!
> joe

0
tom.nospam (3240)
6/25/2007 5:30:20 AM
> The following will be fine:
> 
>    string s;
>    s.resize(n);
>    memcpy(&s[0], 0, n);
> 
> One of the benefits to requiring s[0] to return a real reference (which is
> what disallows COW) is that &s[0] returns a real pointer.

From wat I know works in all current implementations, but still not
*guaranteed* by the standard in any way.



-- 
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
0
6/25/2007 7:26:54 AM
Reply:

Similar Artilces:

Help with formula #8
On Sheet1 column A:A there is a list of different part numbers, (some that are the same part numbers) over and over again. What I'd like to do is: Each time a part number is entered in sheet1 column A:A, that part number be sent to sheet2 in columa A:A (without duplicating that part number)and in the cell next to that part number count each time that part number was entered in sheet1 column A:A. I know this is asking alot! Thanks in advance so much! Hi! You have 2 different requests. The second one, counting the number of times a particular part number appears is easy. The first...

Beginning project help
Though I'm moderately versed in C++ and have been for a while, most of my projects have been console exes only, mostly because they've been simple text extraction and formatting utilities. I've finally decided it was time to get my hand into Windows programming. VC++ seems to be the way to go for me since I've had difficulty keeping all the minutiae in my head building from the ground up. So I began what I thought would be a simple project. As it is, despite having an 1999 copy of the MSDN DVD to help me, it's really difficult to know how to look something up without kn...

Need help to explain this formula
Anyone can explain this formula please? =LOOKUP(99^99,--("0"&MID(C11,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},C11&"0123456789")),ROW($1:$10000)))) Thanks in advance E The formula will return the first set of consecutive digits in a string. If C11 contains: abc123r56t78 the formula will return: 123 ...

Chart Tiltes and axis are invisible, however they and print, help
When I make a chart, I can't see the Chart Title or Axis Labels. However, in print preview, and when printed, the Title and Axis labels Appear and print properly... How do of fix this so that I can see the Title and axis while working on the chart. ...

An Object could not be found??!? Please Help!
I have seen this question asked a few times on Web Forums as well as newsgroups, however it seems that none of the solutions seem to work for me. Here is my scenario. I recently purchased a brand new Dell Server and workstations. The Dell Server is configured as a PDC running Windows Server 2003. The workstations are running Windows XP with Office 2003 installed. The only other software installed on both server and workstations are Symantec Corporate Edition Virus v.7.6, and Exchange Server 2003 on the server. I ran the Exchange Server setup and all seemed to go well. I created a mailbo...

Pivottable help
When any field is grouped in my pivottable, I can't add any calculated item and vice-versa. Each time I receive the error message: "Because a Pivottable report field is grouped, you cannot add a calculated item to this report..." I am stucked on this for months now; please help. .. Instead of grouping the data in the PivotTable, you maybe able to add a field to the source data table, and calculate a group. For example, instead of grouping by year, add a field named year, with the formula =YEAR(A2). Add this field to the PivotTable, instead of the date field. Ngalula M...

sending CString to CStatic label control from worker thread
I need to send a CString from a thread to a static label on the main dialog form. I think I have the thread working okay, but I am unsure how to send the CString to the dialog control. I have seen information on using PostMessage and SendMessage, but I don't really understand how to use these functions. Obviously I can't do like I tried below and I can't get a pointer to the control from the thread function, so just how do I say send the word "hello" to the SetWindowText() function of the label control on the dialog form. I have looked on the Internet and in se...

help with 2 xl sheets...
I need help with 2 worksheets. first sheet is a time schedule sheet. I need to count the total number of shifts entered in a week The sheet is set up so columns are days of weeks, each person has 2 rows, top row is the start time bottom row is end time, time is entered is in 24Hr format and shifts start at various times of days. Second I have a row of numbers 1 to 20 that is averaged in row 21 in column A. Row 1 has the most current figure, row 20 is oldest, Can I set it up so I can enter the most current number in row 1 column A and all the existing figures automatically bump down 1 row? ...

Help! Memory shortage
I'm running and older version of office (97 SR-2b) due to incompatibility with other applications, and have run into memory problem when loading 15-20 workbooks which are heavily linked together. The size of the files is approx. 3.5 mb per file. I've got 512 mb ram, and a paging file of 1.5 gb which shouldn't be any limitation. I guess that the problem is the way this old excel version handles the memory. How can I utilize memory better? I know that the undo function takes a lot of ram. How can I turn it off? Best regards Terje ...

help #11
I have a worksheet which updates a list every min onto a timesheet, Instead of having every minuit i want it just to show the period I want this 2 AUX 9:39 2 AUX 9:40 2 AUXOUT 9:41 2 AUXOUT 9:42 2 AUXOUT 9:43 2 AUXOUT 9:44 2 AUXOUT 9:45 2 AUXOUT 9:46 2 AUXOUT 9:46 2 AUXOUT 9:47 2 AUXOUT 9:48 2 AUXOUT 9:49 2 AUXOUT 9:50 2 AUXOUT 9:51 2 AUX 9:52 2 AUX 9:53 2 AUX 9:54 2 AUX 9:55 2 AUX 9:56 2 AUX 9:57 2 AUX 9:58 2 AUX 9:59 2 AUX 10:00 AUX 10:01 To look like 2 AUX 9:40 2 AUXOUT 9:51 2 AUX 10:01 any help, What i want is to If A2 = A1 then d -- Message posted from http://...

Please help!
Hello to all! I recently installed CRM 3.0 professional edition on Windows 2003 server standard edition. Now my manager wants to have sample database Adventure Works on the same server. How can I install Adventure works on already installed CRM 3.0 ? Or I have to reinstall whole CRM ? If yes, how can I specify during the installation that I need sample database to be installed ? This is really urgent question, and any help will be highly appreciated! thank you!!! Ozz, The AdventureWorks sample db isn't so much "installed" as it's run. It's an ..exe which you run...

CString
How can I covert argv[0] to LPCSTR? Hi, Shouldn't CString(argv[0]) do the trick? Sander Verhagen [ Verhagen@nonono.Sander.com ] "Oliver Young" <please@no.spam.com> wrote in message news:er3JuEogDHA.616@TK2MSFTNGP11.phx.gbl... > > How can I covert argv[0] to LPCSTR? > > > Shouldn't CString(argv[0]) do the trick? OK. And how can I convert CString into LPCSTR? I need LPCSTR. I need to convert from char** ( argv[0] ) into LPCSTR. Please, forget CString, and MFC if possible. > How can I covert argv[0] to LPCSTR? LPCSTR...

Need Help Filtering a Form with VBA
I have a form whose underlying data comes primarily from "Table1" (for this example). On the form is a drop-down box that displays a field named "Primary OBS" for each record. "Primary OBS" is stored in "Table1". It is an index into another table "Table2" which contains a field named "Team Code". "Team Code" can look like "JD130000" or "JG320000", etc. What I need to do is to filter the records in the form by the first two letters of the "Team Code". In other words, the user ca...

Print Help
Whenever I try to Print it shows a box that says "Cannot Load the Printer Driver." I've tried reinstalling and printing works on all other prgrams like Word. Can anyone help? What version of Publisher? Have you checked to see if there are any updates to your printer? Has it ever worked properly? -- JoAnn Paules MVP Microsoft [Publisher] ~~~~~ How to ask a question http://support.microsoft.com/KB/555375 "www.teenfellowship4christ.com" <www.teenfellowship4christ.com@discussions.microsoft.com> wrote in message news:22CAD42C-3DD0-4D8A-A93B-5DCB0E5FC62E@micr...

Help With VBA Macros
I've created a spreadsheet that, when I try to save manually as a CS using a macro... it works, but the program that reads the CSV is no picking up the text within the CSV because it's reading the macr code. How can I get the macro code to be deleted or ignored? C -- cyoung2t ----------------------------------------------------------------------- cyoung2ty's Profile: http://www.msusenet.com/member.php?userid=79 View this thread: http://www.msusenet.com/t-187013413 Macro code is not saved in csv files. How are you saving the file with the macro? In article <cyoung2ty.1o...

Windows Live Mail Help
When I click HELP in Windows Live Mail, I'm connected to the Microsoft website. Help is very basic. Several times now, I've not been able to find the help I need. When will this be improved please? Geoff PS This is the second time of posting, for the same reason. ...

CString (again)
I have a class: class TestClass{ public: TestClass(){}; virtual ~TestClass(){}; BOOL CalcArea(double * pArea); void ReversePoints(); void OrderFromLowest(); std::vector<CoordinateClass> Pts; double OrientationType; BOOL XFlip; BOOL YFlip; double LTilt; double RTilt; double Buffer; int Style; CString Name; }; Now when I go like this: TestClass * pNew = new TestClass; pNew->Name = "anything in here will cause an error"; At runtime i get an unhandled exception which is comign from CString::AssignCopy() How do i fix this? Can't seem to reproduce this ...

Formula Sorting Help
Is there a way to sort data by sub-fields? Ex Given my Cells look like: A10.1234 I would like to sort by everything to the right of the decimal (i.e. 1234) Is there a smart way of doing this? ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~ View and post usenet messages directly from http://www.ExcelForum.com/ With your data in Col A, starting in A1, in B1 put the following:- =MID(A1,FIND(".",A1)+1,LEN(A1)) and then copy down. Select both Col A and B and sort on B. -- Regards Ken....................... Mic...

std::string vs Cstring
Hello, I have recently been encouraged to utilise String classes, as opposed to C type char arrays due to some difficulty debugging some buffer overflows. I have looked into std::string and CString, but what are the benefits and drawbacks? The main problem I have is that I do a lot of data formatting using sprintf, for which I see no substitute using std::string, - MR On Thu, 30 Dec 2004 23:25:21 -0000, "Mark Randall" <strike@rapiercom.freeserve.co.uk> wrote: >Hello, > >I have recently been encouraged to utilise String classes, as opposed to C >type cha...

Pivot Table Calculated Field- Help
Hi, I have a pivot table that is coming from a simple spreadsheet with following columns: Name, Credits - Where name is the name of an individual, and credit is the credit amount they have. I want to add a calculated column on the pivot, that has a value of "Allow" or "Deny" depending upon credit. So, if, Credit < 5, the value of the calculated field should be Deny, else it shoudl be Allow. I tried using the If statement, but it doesn't seem to work for me when I use string values. Is there a way for this to be done? Will appreciate any help on this. Thank...

Starting Excel from file Help please
Can anyone help? I've just started getting a problem loading excel from a file. It starts just fine from the start menu etc. and I can open files from within Excel. However, if I click on (say) an excel file icon in My Documents or on one of my saved icons on the desktop then Excel loads fine but NOT the file!! This is really frustrating as it means I have to go through the process of loading excel separately every time I wish to use it. I Use Office XP + Windows XP PRO. I have done a system restore to before the problem occurred - no luck. I have completely uninstalled Office (from...

help with dates please
hello I have a date in A1 which is a 'start date', 01/02/10 In A2 I have the same date formatted as Mon 01/02/10 using Text(A1,"ddd dd/mm/yy") . no problem In A3, A4 etc I need Tue 02/02/10, Wed 03/02/10 etc etc etc. ie the dates are incrementing by 1 day in each row. Normally I would just add 1 to the date above, but the text formula makes this impossible. help & advice please ?? Thanks as always KK Is there a reason you can't just format a2>>> -- Don Guillett Microsoft MVP Excel SalesAid Software dguillett@gmail.co...

Error Help
"Message delivery to the remote domain 'mydomain.com' failed for the following reason: Unable to bind to the destination server in DNS' My DNS and Exchange Servers are is NT 4.0 Ther error is from 2000 boxes. Any help? sounds like DNS can't resolve mydomain.com. If that's a local domain, check with your DNS admin, or if you are the DNS admin, track down the resolution issue, focus on the mx records for the exchange server in the domain. If it's not a local domain, check the internet (dnsstuff.com or the like) for resolution and if it fails contact them dir...

I need help with this.
I keep getting "Application-defined or object-defined error." Any ideas, please help. With Range("B3").Validation .Add Type:=xlValidateList, _ AlertStyle:=xlValidAlertStop, _ Operator:=xlBetween, Formula1:="=OFFSET(MarketStart,MATCH(B20,Markets,0)-1,1,COUNTIF(Markets,B20),1)" End With Hello Ayo, Not sure, but aren't you missing an underscore at the end of the fourth line in order for it to be a continuation of the prior line. Perhaps, this is generating the indicated error. Good Luck, Richard **...

How to covert CString to TCHAR and CString to LPCWSTR?
How to covert CString to TCHAR and CString to LPCWSTR? Where can I read about this? See my essay on CStrings on my MVP Tips site. joe On Mon, 30 Jun 2003 04:33:56 -0700, "julych" <julych@msn.com> wrote: >How to covert CString to TCHAR and CString to LPCWSTR? >Where can I read about this? Joseph M. Newcomer [MVP] email: newcomer@flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm ...