What's wrong with this code ? (CString issue)
-
Hi, Can someone explain why this code crashes (when calling ReleaseBuffer()) ?
#define PROFILE CString("config.ini"); CString result; GetPrivateProfileString("MySection","MyString","",result.GetBuffer(),512,PROFILE); result.ReleaseBuffer();
And how can I avoid this ? -
Hi, Can someone explain why this code crashes (when calling ReleaseBuffer()) ?
#define PROFILE CString("config.ini"); CString result; GetPrivateProfileString("MySection","MyString","",result.GetBuffer(),512,PROFILE); result.ReleaseBuffer();
And how can I avoid this ? -
Hi, Can someone explain why this code crashes (when calling ReleaseBuffer()) ?
#define PROFILE CString("config.ini"); CString result; GetPrivateProfileString("MySection","MyString","",result.GetBuffer(),512,PROFILE); result.ReleaseBuffer();
And how can I avoid this ?My guess is the crash is due to writing past the allocated buffer memory that the CString has. Debug builds have some checks to see if you make this mistake. Get the CString to return a buffer that has a certain minimum size.
#define PROFILE CString("config.ini"); CString result; GetPrivateProfileString("MySection","MyString","",result.GetBuffer(512),512,PROFILE); result.ReleaseBuffer();
-
Hi, Can someone explain why this code crashes (when calling ReleaseBuffer()) ?
#define PROFILE CString("config.ini"); CString result; GetPrivateProfileString("MySection","MyString","",result.GetBuffer(),512,PROFILE); result.ReleaseBuffer();
And how can I avoid this ? -
Hi, Can someone explain why this code crashes (when calling ReleaseBuffer()) ?
#define PROFILE CString("config.ini"); CString result; GetPrivateProfileString("MySection","MyString","",result.GetBuffer(),512,PROFILE); result.ReleaseBuffer();
And how can I avoid this ?Tnarol wrote:
GetPrivateProfileString("MySection","MyString","",result.GetBuffer(),512,PROFILE);
Result of the string where you get the data from ini file, it should be LPTSTR buffer, specify the size of that buffer instead of 512. Knock out 't' from can't, You can if you think you can :cool:
-
Hi, Can someone explain why this code crashes (when calling ReleaseBuffer()) ?
#define PROFILE CString("config.ini"); CString result; GetPrivateProfileString("MySection","MyString","",result.GetBuffer(),512,PROFILE); result.ReleaseBuffer();
And how can I avoid this ? -
Hi, Can someone explain why this code crashes (when calling ReleaseBuffer()) ?
#define PROFILE CString("config.ini"); CString result; GetPrivateProfileString("MySection","MyString","",result.GetBuffer(),512,PROFILE); result.ReleaseBuffer();
And how can I avoid this ?For GetBuffer method : Call this method to return the buffer contents of the CSimpleStringT object. You are having this string empty. Somethings seem HARD to do, until we know how to do them. ;-) _AnShUmAn_
-
Hi, Can someone explain why this code crashes (when calling ReleaseBuffer()) ?
#define PROFILE CString("config.ini"); CString result; GetPrivateProfileString("MySection","MyString","",result.GetBuffer(),512,PROFILE); result.ReleaseBuffer();
And how can I avoid this ? -
Hi, Can someone explain why this code crashes (when calling ReleaseBuffer()) ?
#define PROFILE CString("config.ini"); CString result; GetPrivateProfileString("MySection","MyString","",result.GetBuffer(),512,PROFILE); result.ReleaseBuffer();
And how can I avoid this ?You have two compiler errors. The first is a missing argument to
GetBuffer()
. The second is an erroneous semicolon at the end ofPROFILE
.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb