dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Changing of CString to const char*

  1. #1
    Join Date
    Jan 2010
    Posts
    41

    Thumbs up Changing of CString to const char*

    I tried the following code. However, the compiler keep on throwing exceptions that the parameters are not compatible. Can anyone please tell me how to convert CString path. So i can call the system() function.

    CString pathname;
    pathname.Format(L"BatchFiles\\RE2P2_ReadInfoSectors.bat %c",&drive);
    const char* path;
    wcscpy(path,pathname);
    system(path);

  2. #2
    Join Date
    Aug 2008
    Location
    Scotland
    Posts
    379

    Re: Changing of CString to const char*

    Hi,

    system() is expecting an ANSI string, but judging from your code you are compiling in Unicode. Simplest way to fix this is to change your project settings for "Character Set" to Not Set, then you can use pathname.GetString() as your argument to system().

    If you need to use Unicode, then it's probably simplest to find a way to do this without using CString at all. What's the "drive" variable?

    Alan

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,562

    Re: Changing of CString to const char*

    Don't use system().
    In Win32 application you should use either CreateProcess or ShellExecute(Ex) API
    Victor Nijegorodov

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)