Results 1 to 1 of 1

Thread: [Resolved] Character String -> Wide Character String conversion problems

  1. #1

    Thread Starter
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    [Resolved] Character String -> Wide Character String conversion problems

    Trying to use the StgCreateDocfile or StgOpenStorage functions, MSDN says the first parameter, pwcsName, should point to the path of the file containing the storage object. I use the following code to get the filename of an existing file:
    Code:
    OPENFILENAME ofn;
    ZeroMemory(&ofn, sizeof(ofn));
    ofn.lStructSize = sizeof(ofn);			// OS specific - may need to change for different Windows versions
    ofn.hwndOwner = hwnd;
    ofn.lpstrFilter = "Word Documents (*.doc)\0*.doc\0All files (*.*)\0*.*\0";
    ofn.lpstrFile = szFileName;
    ofn.nMaxFile = MAX_PATH;
    ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
    ofn.lpstrDefExt = "doc";
    if (GetOpenFileName(&ofn))
    {
    	// Do something with the file name
    ...
    Then, since I need it in Wide Character String format, I do the following:
    Code:
    MessageBox(NULL, szFileName, "", MB_OK);  // Debugging purposes - supplies correct filename, e.g "C:\My Documents\test.doc"
    CharsConverted = mbstowcs(wcsFileName, szFileName, NULL);
    This I *assume* has converted correctly, since I can't figure out how to view the contents of it in Debug mode
    So, I try to open this storage file:
    Code:
    hresFile = StgOpenStorage(wcsFileName, NULL, grfDocFileFlags, NULL, 0, ppstgDocFile);
    But this returns STG_E_INVALIDNAME in hresFile:
    STG_E_INVALIDNAME
    Indicates bad name in the pwcsName parameter.
    Any ideas what I'm doing wrong?

    Thanks

    Chris

    [Edit: Okay, i got it now. Stupid stupid me:
    Code:
    CharsConverted = mbstowcs(wcsFileName, szFileName, NULL);
    should be:
    Code:
    CharsConverted = mbstowcs(wcsFileName, szFileName, MAX_PATH);
    I thought NULL would mean carry on until you get to the end, but it's just an alias for /0, so it converted no characters ]
    Last edited by Evil_Giraffe; Feb 6th, 2003 at 01:01 PM.

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