|
memcpy(szData1, strValue.Left(nPos), sizeof(szData1));
What happens when sizeof(szData1) is greater than the length of strValue.Left(nPos) ??
|
|
|
|
|
memcpy(szData1, strValue.Left(nPos), sizeof(szData1));
This statement seems to be a problem. This statement copies bytes from the CString object itself, not from the string contained within the CString object.
Try:
memcpy(szData1, (LPCSTR)strValue.Left(nPos), sizeof(szData1));
|
|
|
|
|
Sorry. This method couldn't get the correct result.;P
Hongjun Ge
|
|
|
|
|
Sorry for so many posts, but I just realized that you're doing this all wrong.
You should not be copying strings around with the memcpy() function unless you really know what you're doing.
To copy strings from place to place, look up the functions:
strncpy()<br />
strlen()<br />
<br />
and related functions.
|
|
|
|
|
I've used memcpy this way for clipboard stuff. As long as the CString is not on the receiving end, the LPCTSTR operator is just fine. If it's on the receiving end you would need to call CString::GetBuffer() and CString::ReleaseBuffer accordingly to get a non-constant string buffer.
Unless I'm missing something obvious right under my nose that is.
|
|
|
|
|
I agree. Perhaps I spoke too soon. But I took the assumption that this was a beginner's question - someone not well versed in CStrings and nulls.
|
|
|
|
|
Your fine. I would have to say that I agree they should probably leave their parsing within the confines of CString also. However, they will need to know how to interface code littered with CString with the Win32 API which can be quite a trick sometimes but Paul DiLascia, Joseph Newcomer, and Michael Dunn have all done superb jobs explaining all that.
The newer versions of CString have a Tokenize method but it treats consecutive delimiters as one which can easily lead to corrupt parsing so I would not recommend it at all.
|
|
|
|
|
your copying up to the size of your szBuffer but your forgetting to add the \0 (null terminator) so when you attempt to printf or output the string your getting everything up to the end of the szBuffer and then some.
|
|
|
|
|
Hongjun Ge wrote: char szData1[5];
char szData2[10];
char szData3[5];
Why are you not using CString for these? You can certainly complete the task without it, but since you are using MFC, you might as well take advantage of what it has to offer.
CTest::CTest( LPCSTR lpszValue )
{
AfxExtractSubString(strData1, lpszValue, 0);
AfxExtractSubString(strData2, lpszValue, 1);
AfxExtractSubString(strData3, lpszValue, 2);
}
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
my program use matrix to get rgb
and then i hope that white transform into black
int main(int argc, char* argv[])
{
FILE *fidr;
FILE *fidg;
FILE *fidb;
fidr = fopen("logr.txt","w");
fidg = fopen("logg.txt","w");
fidb = fopen("logb.txt","w");
GBmp ImgA, ImgB;
int i,j,k;
ImgA.load("a.bmp");
unsigned char *rgb;
rgb = (unsigned char*) malloc( ImgA.w*ImgA.h*3*sizeof(unsigned char) );
rgb = ImgA.rgb;
for(i=ImgA.h-1;i>=0;i--){
for(j=0;j<imga.w;j++){
="" fprintf(fidr,"rgb(%3d,%3d)=",i,j);
for(k=0;k<3;k++){
if (k==0)
{
fprintf(fidr," %4d",*(rgb+i="" *="" imga.w="" 3="" +="" j*3="" k));
="" }
="" }
="" if(j="ImgA.w-1)
" {
="" fprintf(fidr,"\n");
="" for(i="ImgA.h-1;i">=0;i--){
for(j=0;j<imga.w;j++){
="" fprintf(fidg,"rgb(%3d,%3d)=",i,j);
for(k=0;k<3;k++){
if (k==1)
{
fprintf(fidg," %3d="" ",*(rgb+i="" *="" imga.w="" 3="" +="" j*3="" k));
="" }
="" }
="" if(j="ImgA.w-1)
" {
="" fprintf(fidg,"\n");
="" for(i="ImgA.h-1;i">=0;i--){
for(j=0;j
|
|
|
|
|
If you don't say what does not work, no-one is going to give suggestions.
When you post code, please use the "pre" tag (below the signature box) so the indenting is not lost.
|
|
|
|
|
I'm just starting to learn C++, and i met a problem error below when i compound it...pls teach me how to correct these errors. Your kindness will be appreciated....thank you.
#include "matrix.h"
#ifndef _NO_NAMESPACE
using namespace std;
using namespace math;
#define STD std
#else
#define STD
#endif
#ifndef _NO_TEMPLATE
typedef matrix<double> Matrix;
#else
typedef matrix Matrix;
#endif
#ifndef _NO_EXCEPTION
# define TRYBEGIN() try {
# define CATCHERROR() } catch (const STD::exception& e) { \
cerr << "Error: " << e.what() << endl; }
#else
# define TRYBEGIN()
# define CATCHERROR()
#endif
the software tells the error at these location:
line6 : error C2871: 'std' : does not exist or is not a namespace
line7 : error C2871: 'math' : does not exist or is not a namespace
line14 : error C2143: syntax error : missing ';' before '<'
line14 : error C2143: syntax error : missing ';' before '<'
|
|
|
|
|
you need to #include the files that contian those namespaces, otherwise the compiler doesn't know what your "using" statements refer to.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
I'm sure there are hundreds of tools/addins/libraries for detecting memory leaks. Which one do most of you use? What is the best method for detecting the annoyances? is it possible to find the exact function/line?
I'm using Visual Studio VC6 Enterprise if it makes any difference.
|
|
|
|
|
I've tried many and my preferred tool DevPartner Studio from CompuWare. It has its quirks and sometimes goes a while without an update, but I've been especially impressed with the latest version.
It is a little expensive, but has proven its worth for me many times over.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
I have a message "An unsupported operation was attempted" in MFC release configuration.
How may I locate error point?
|
|
|
|
|
try to search for this message in MFC Source.
Yout find it where your Developer Studio is installed.
|
|
|
|
|
I would try to find it in a debug buid. If it doesn't occur in the debug build alter the compiler setting (for the debug configuration) to include the "/GZ" switch and try again - It's much easier to find bugs in a debug build.
Steve
|
|
|
|
|
How can I tell if my arrival to OnBnClickedOk() came from a mouse click or from a keyboard entry of Enter?
The reason this is important is that I have a multi line edit box and if the user hits Enter while in this edit box I don’t want the system to act as if he clicked on OK.
I already tried removing the Default Button Status from the OK button, but that makes no difference. I can see that if I click on the edit box, the added black line on the OK button remains, as if it has the focus, which of course it doesn’t. Even if I tab to this control the added black line on the OK button remains, showing that Enter will activate it.
Clearly, if I could know in my event handler for the OK button if the event came from a mouse click or from a keyboard Enter, there would be no problem dealing with it.
Any suggestions would be appreciated. Thanks,
Ilan
|
|
|
|
|
I'm not quite sure how to do this in MFC, but in win32, you need to change the way the messages are handled.
This code is inserted into the winMain and it checks for messages being sent to the dialog.
while( GetMessage( &msg, NULL, 0, 0 ) )
{
if(!IsDialogMessage(dlgHwnd, &msg)) {
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
return msg.wParam;
|
|
|
|
|
You're going about it the wrong way, really. Take a look at the ES_WANTRETURN style for the edit box - setting that will probably give you the result you're after.
|
|
|
|
|
Thanks Graham. This gives me EXACTLY the result I wanted. Since I never used it, I didn't know it existed.
Thanks again,
Ilan
|
|
|
|
|
Hi Ilan,
Well, my suggestion is that you declare two time stamps and use them to keep the latest time of left mouse click and Enter key click. In OnOk functions, you may compare the current time with both time stamps and this may give you some idea about which is the source of the action.
regards,
chris
|
|
|
|
|
Oops, I didn't see other replys just now. Obviously, my suggestion is the worst one. hehe, ignor it.
Regards,
Chris
|
|
|
|
|
I want to make a modal class in the visual c++,but when I want to make it ,the system told me that I can't make this class,how should I solove this problem.thank you!waiting for your answer.
Always do you best,what you plant you will harvest
later!
|
|
|
|