Thread: WChar to char

  1. #16
    Registered User
    Join Date
    Aug 2005
    If your program is in English or some of the other western languages then you may not need any conversion functions at all -- just copy using a simple loop
    wchar_t  tbuf[50];
    char str[] = "Hello World";
    for(int i = 0; str[i]; i++;
      tbuf[i] = str[i];
    tbuf[i]  0;

  2. #17
    Registered User
    Join Date
    Jan 2006
    England, Norwich
    Hey sorry i'm really rubish at this i still cannot get this to work what ever i try - Maybe becuse i'm usless and still a berginner at c++. but anyway i made a new project and just did a simple bit of code thats sets the wallpaper no error handle's or anything just simple stuff.

    int ChangeWallpaper (char* FilePath) {
    ////////// Variables ////////// 
    HRESULT hr;
    ////////// //////// ////////// 
    CoInitialize(0); // Initialize COM
    IActiveDesktop *pActiveDesktop; // Set IActiveDesktop Type
    hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER, // Load IActiveDesktop
    						 IID_IActiveDesktop, (void**)&pActiveDesktop);
    pActiveDesktop -> SetWallpaper (FilePath,0);   // Set the Wallpaper ||| Problem is here!
    pActiveDesktop -> ApplyChanges (AD_APPLY_ALL); // ApplyChanges
    pActiveDesktop->Release(); // Unload IActiveDesktop
    CoUninitialize (); // Uninitialize COM
    return 1;
    Yep as you see i have not converted the FilePath this is because every thing i try i still get that same type of error so if possable ( i know you have done ton and tons and well tons for me and thanks ) could somone tell me exactly how to change FilePath into a LPCWSTR. basicly i dont think i'm going to be able to figure out the conversion into a LPCWSTR with out being shown. oh yeh btw erm really i want this to subport multi languages so i dont think that loop thing would work but thanks.
    Last edited by MK4554; 04-19-2006 at 06:52 AM.

  3. #18
    Registered User
    Join Date
    Jan 2006
    England, Norwich
    edit opps posted it twice

  4. #19
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    WCHAR FilePathW[MAX_PATH];
    MultiByteToWideChar(CP_ACP, 0, FilePath, -1, FilePathW, MAX_PATH);
    pActiveDesktop->SetWallpaper(FilePathW, 0);

  5. #20
    Registered User
    Join Date
    Jun 2004
    You made another mistake

    LPCWSTR FilePath[77];
    is like saying
    wchar_t *FilePath[77];

    you declare an array of 77 wchar_t pointers.

    so FilePath = L"......" doesn't work.

    you just need LPCWSTR FilePath = L"......";

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting Linked Lists
    By DKING89 in forum C Programming
    Replies: 6
    Last Post: 04-09-2008, 07:36 AM
  2. Conversion Char To Char * Problem
    By ltanusaputra in forum Windows Programming
    Replies: 3
    Last Post: 03-01-2008, 02:06 PM
  3. Wierd Segmentation Faults on Global Variable
    By cbranje in forum C Programming
    Replies: 6
    Last Post: 02-19-2005, 12:25 PM
  4. I'm having a problem with data files.
    By OmniMirror in forum C Programming
    Replies: 4
    Last Post: 05-14-2003, 09:40 PM
  5. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 01:18 AM