-
October 10th, 2013, 03:57 PM
#16
Re: ussing if or Switch with LPCWSTR
now with all the post i am getting i will print this page soon ther is a loth of valuable information to keep
nice Arjay this code looks a loth like wat i was trying to do in the ferry beginning
bevore you post it i wrote a new ini.h file that works.
You can also simplify the code by using the CString class (just #include <atlstr.h>).
yes its simple indeed, i can read you code and execute it in my head, i cant say that from my ini.h file
so i am going to play with your code so i learn more about it becorse i think this will be usse full to me for even more things then ini files
my new ini.h file
Code:
char* ini_read_char(LPCWSTR _ini_File_Name, LPCWSTR _ini_Section_Name, LPCWSTR _ini_Key_Name, LPCWSTR _ini_Default )
{
wchar_t ini_index[6];
GetPrivateProfileStringW(_ini_Section_Name, _ini_Key_Name, _ini_Default ,ini_index,6,_ini_File_Name);
wchar_t* vIn = ini_index;
char * vOut = new char[wcslen(vIn)+1];
wcstombs_s(NULL,vOut,wcslen(vIn)+1,vIn,wcslen(vIn)+1);
return vOut;
}
-
October 10th, 2013, 04:07 PM
#17
Re: ussing if or Switch with LPCWSTR
Code:
char * vOut = new char[wcslen(vIn)+1];
Who is responsible for deallocating this memory? Your code now has a memory leak.
Regards,
Paul McKenzie
-
October 10th, 2013, 05:03 PM
#18
Re: ussing if or Switch with LPCWSTR
Originally Posted by MR.Hotdog
thanks a loth Arjay even with my limited englich i understend efrything you say.
tomorow i will go to the website to read that article
GCDEF also thanks a loth for all your posts.
i most say it looks clean how you changet my code.
always eazy to find things back to edit/fix it
rite now GetPrivateProfileString is returning "ON" becorse i have made the ini file
it returnts it value in-to wchar_t ini_index[6]; then convert it to char* vOut;
checking it with if(std::strcmp(vOut, "ON") == 0) printing I left my tv on to the screen
also ussd the other's "OFF" and "qefqd" always priting the right text to the screen
I didn't ask you what you think it's returning. I asked you what it's actually returning. You'll need to use the debugger to find out, or failing that use the TRACE macro or a message box. You're at the point now where you need to use the debugger. None of us that are giving you help would think of writing a program without it. It's essential no matter how small the program.
-
October 13th, 2013, 07:00 AM
#19
Re: ussing if or Switch with LPCWSTR
now this var i dit check both variables
(wchar_t) ini_index, (return value from GetPrivateProfileString) its value is an memory adress (chanching efry time i run this program),
but after i concvert it to (char*) vOut it has the value exactly as in the ini file (or else the defauld return string)
i hope this will anser your question
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|