Results 1 to 2 of 2

Thread: Open File

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Location
    England
    Posts
    94

    Open File

    Can Anyone tell me whats wrong with this code because it just crashes the program.

    TCHAR sFilePath[MAX_PATH] = {NULL};
    TCHAR sFileName[STRING_LENGTH];
    DWORD dwFilePathSize;
    TCHAR sFilter[STRING_LENGTH] = {"Bitmap \0 *.bmp \0 \0"};

    OPENFILENAME OpenFile;
    LPITEMIDLIST pSelectedFolder;

    DWORD dwFileExtension;
    DWORD dwFileOffset;


    OpenFile.lStructSize = sizeof(OPENFILENAME);
    OpenFile.lpstrFilter = sFilter;
    OpenFile.hwndOwner = NULL;
    OpenFile.nFilterIndex = 0;
    OpenFile.lpstrFileTitle = sFileName;
    OpenFile.nMaxFileTitle = sizeof(sFileName) - 1;
    OpenFile.lpstrInitialDir = NULL;
    OpenFile.lpstrFile = sFilePath;
    OpenFile.nMaxFile = MAX_PATH;
    OpenFile.nFileOffset = strlen(sFilePath);

    GetOpenFileName(&OpenFile);
    "Let's all join forces, rule with an iron hand...and prove to all the world, metal rules the land..."
    -- Judas Priest

    My email is [email protected]

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    TCHAR sFilter[STRING_LENGTH] = "Bitmap\0*.bmp\0";

    would be correct. May be the error, may not, I don't know.

    In any case you should first ZeroMemory the complete struct:
    ZeroMemory(&OpenFile, sizeof(OpenFile));
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer 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
  •  



Click Here to Expand Forum to Full Width