CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    Join Date
    Oct 2013
    Posts
    10

    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;
    }

  2. #17
    Join Date
    Apr 1999
    Posts
    27,449

    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

  3. #18
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: ussing if or Switch with LPCWSTR

    Quote Originally Posted by MR.Hotdog View Post
    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

    Code:
    [test]
    key=ON
    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.

  4. #19
    Join Date
    Oct 2013
    Posts
    10

    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

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured