OPENFILENAME ofn;

This is a discussion on OPENFILENAME ofn; within the Windows Programming forums, part of the Platform Specific Boards category; hi there, i'm new to the forum, i've been visiting cp for a while and i decided to join the ...

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    21

    OPENFILENAME ofn;

    hi there, i'm new to the forum, i've been visiting cp for a while and i decided to join the forum =).. plus i have a question lol..

    Ok the thing is, i have 3000+ lines of code, and the only thing that doesn't work is the ofn declaration..

    ...
    OPENFILENAME ofn;
    ...
    then when i try to access a member of ofn, it's like it hadn't been declared ever.. at first i thought maybe it has to do something with the program flow so i've put it in different parts of the code, still doesn't works...

    i was able to compile another prog that used only this OFN struct and some menus and it did work correctly and it's placed almost exactly in the same place... WTF am i doing wrong? sorry for not giving much detail but i've checked every possible thing, i'm so confused... my prog is ready after a week of writing and this &%$& error is the only thing left to figure out before compiling the final version =(...

    yeah.. i could code another browser-type dlgbox but am i guilty of being lazy if there's already one.. it just doesn't work =( =( =(

    I first tried compiling with DEV-C++ 5.0 Beta 8 (4.9.8.3) so i thought it was a bug in the compiler, i reinstalled DEV-C++ 4.0 and the same thing happened so.... =( please help me...
    Last edited by ROCKaMIC; 10-13-2003 at 07:11 AM.

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Do you ZeroMemory()/memset() on ofn first? This could be one reason..

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    21
    Originally posted by knutso
    Do you ZeroMemory()/memset() on ofn first? This could be one reason..
    yup =( it goes like this:

    Code:
    OPENFILENAME ofn;
    ZeroMemory(&ofn, sizeof(ofn));
    .....
    .........
    but as i said before, it's like ofn isn't declared so when i use ZeroMemory it return a compiling error saying ofn hasn't been declared =(

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Could you post some code?

  5. #5
    Registered User
    Join Date
    Oct 2003
    Posts
    21
    Originally posted by knutso
    Could you post some code?
    you might find this piece of the ocde a little akward but lol after recoding and recoding to see if the problem fixed this is what's left.. but it's acceptable hehe.. as long as ti works ='(....

    Code:
    ...........
    case WM_COMMAND:
     switch(wParam)
     {
     case (IDM_ENCRYPT || IDM_DECRYPT):
    /* start */
                    //OFN struct, used for the browser-type dlgbox
                    //======================================
                    OPENFILENAME ofn;
                    ZeroMemory(&ofn, sizeof(ofn));
                    ofn.lStructSize = sizeof(ofn);
                    ofn.hwndOwner = hwnd;
                    //ofn.lpstrFile
                    //File name is stored in "lpstrFile" member......
                    ofn.nMaxFile = MAX_PATH;
                    ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST;
                    //======================================
                    ////////////////////////////////////************ =)
                    if(WM_COMMAND == IDM_ENCRYPT)
                    {
    //=============================================
        ofn.lpstrFilter = "All Files (*.*)\0*.*\0";
        ofn.lpstrDefExt = "exe";
    //============================================
                      if(GetOpenFileName(&ofn))
                      {
                      FileW.StartCrypt(ofn.lpstrFile, ACTION_ENCRYPT);
                      }
                     else
                      {
                      MessageBox(hwnd, "Unexpected file error.", "ERROR!", MB_OK);
                      }
                    }
                    else if(WM_COMMAND == IDM_DECRYPT)
                    {
    //OFN struct, used for the browser dlgbox type..
    //============================================
        ofn.lpstrFilter = "File Encryptor Files (*.fem)\0*.fem\0";
        ofn.lpstrDefExt = "fem";
    //============================================
                      if(GetOpenFileName(&ofn))
                      {
                      FileW.StartCrypt(ofn.lpstrFile, ACTION_DECRYPT);
                      }
                      else
                      {
                      MessageBox(hwnd, "Unexpected file error.", "ERROR!", MB_OK);
                      }
                    }
    /* End */       break;               
                    case IDM_EXIT:
    .......
    ..........
    .................
    at first i used szFileName but since it didn't work =( i replaced it for using directly the struct member.. lpstrFile

    oh yeah don't make comments about my code commenting lol i was desperate and the smileys in the source code well lol seemed relaxing.. hehehe
    Last edited by ROCKaMIC; 10-13-2003 at 07:49 AM.

  6. #6
    Registered User
    Join Date
    Oct 2003
    Posts
    21
    i just spotted an error in the code.. but it won't solve anything regarding this problem.. =(

    if(WM_COMMAND == IDM_...)...

    ***
    change to
    ***
    if(wParam == IDM...)...
    .......
    Last edited by ROCKaMIC; 10-13-2003 at 07:54 AM.

  7. #7
    Registered User
    Join Date
    Oct 2003
    Posts
    21

    &/$#&/$# COMPILER!!!!

    I KNEW IT!!!! IT'S THE COMPILER... i added this to the beggining of the source code:
    Code:
    struct buffy
    {
    int yay;
    };
    
    buffy yp;
    
    yp.yay = 0;
    and when i try to compile, it gives me the same error as with ofn..

    But this has never happened before =(...i had always trusted dev-c++ ='(.....

    but the thing is this doesn't happen on another source files.... i'm off to keep testing the dev-c++ 4.8.9.3, now testing staff lol i'm putting a complaint for this to be solved! ='(

  8. #8
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Hi. Don't you hate these seemingly unexplainable errors that turn out to be simple?
    Code:
     case (IDM_ENCRYPT || IDM_DECRYPT):
    /* start */
                    //OFN struct, used for the browser-type dlgbox
                    //======================================
                    OPENFILENAME ofn;
    A. I've never seen || used in a case label.
    B. Variables in C must be declared at the start of a code block. That is after a {

    Solution:
    Code:
    case IDM_ENCRYPT:    // Fall through
    case IDM_DECRYPT: {  // Start code block
    // Now declare variables...
    Code:
    struct buffy
    {
    int yay;
    };
    
    buffy yp;
    I believe that if you don't use a typedef you must declare a struct as such:
    Code:
    struct buffy yp;
    Welcome to the forums. In the future please post the error messages. This makes it a lot easier to see the problem.

    Have Fun!

    Edit: In the unlikely event that you are actually compiling as C++ and not C you can ignore most of this post.
    Last edited by anonytmouse; 10-13-2003 at 11:47 AM.

  9. #9
    Registered User
    Join Date
    Oct 2003
    Posts
    21
    Originally posted by anonytmouse

    Edit: In the unlikely event that you are actually compiling as C++ and not C you can ignore most of this post.
    Hehe yup i'm compiling as C++... anyway thanks for trying to help.. and as to the switch statement and placement and such.. i've also tried putting it in the beggining of the code.. but nothing.. err someone needs the phone brb.. please HELP =(

  10. #10
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    AFAIK this is not legal in C/C++ (could be in PASCAL)

    case (IDM_ENCRYPT || IDM_DECRYPT)://error but not picked up by the compiler
    In MSVC .NET the case declared as you have will never be entered. The default, if present, will be used instead.

    as case is defined as

    case constant-expression :

    ie

    case IDM_ENCRYPT:
    case IDM_DECRYPT:
    // code
    break;


    As the complier does not think you have entered this section of the code (the bad case statement which can never be entered) it does not declare the variable.

    Unless you have a good reason for declaring variables inside blocks of code, and not at the function start, then don't.


    Try putting the case as per my example and declare the open file name dlg struct at the very begining of the callback.
    This will solve the problem.

    edit;

    try
    Code:
    case WM_COMMAND:
    	idControl	= GET_WM_COMMAND_ID(wParam,lParam) ;
            switch(idControl)
             {
    Last edited by novacain; 10-13-2003 at 10:33 PM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  11. #11
    Registered User lobo's Avatar
    Join Date
    Oct 2001
    Posts
    71
    novacain: I'm not completly sure if i catched the sense of whole prev. post, but are you sure about this?

    As the complier does not think you have entered this section of the code (the bad case statement which can never be entered) it does not declare the variable.
    I think that 'case' would be evaluated as case (1) as (IDM_ENCRYPT || IDM_DECRYPT) would be evaluated as TRUE (if any of IDM_ENCRYPT, IDM_DECRYPT is non-zero).. so OFN variable would be declared properly and could be used if some part of code called WM_COMMAND with 1 as wParam for example, no?

  12. #12
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    The case statement is not evauated though. It is not a constant.

    So it is simply ignored (on my complier MSVC.NET 2003) and the default is called.

    Try it on your complier. See if you get the same result I did.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  13. #13
    Registered User lobo's Avatar
    Join Date
    Oct 2001
    Posts
    71
    I use bcc5.5 and it seems to evaluate it, i made small test and code like 'case (A || B):' (where A, B were #defined as nonzero) was equal to 'case 1:'... now we have to figure out how Dev-C++ does that

  14. #14
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    >.(where A, B were #defined as nonzero) was equal to 'case 1:'.

    Was either one #defined as 1?

    try
    Code:
    char     sText[64]={0};
    
    for(int iVar=0;iVar<4;iVar++)
    {
          switch (iVar)
           {
                  case (0||2):
                       sprintf(sText,"reached 0, 2 case");
                  break;
                  case 1:
                       sprintf(sText,"reached 1 case");
                  break;
                  default:
                      sprintf(sText,"reached default case");
                  break;
           }
           MessageBox(NULL, sText, "Test case", MB_OK);
    }
    See what I mean about the behavior being undefined?
    Last edited by novacain; 10-15-2003 at 02:50 AM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  15. #15
    Registered User lobo's Avatar
    Join Date
    Oct 2001
    Posts
    71
    Bcc5.5 throws 'duplicate case' error on this; my test was quite the same (#define A 0, #define B 2)

    edit: gcc (3.3) does the same - evaluates A || B acc. to logical values of A, B and final case value is 0 or 1 (T or F)..
    Last edited by lobo; 10-15-2003 at 04:17 AM.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Save vs Save As.... OPENFILENAME flags
    By csonx_p in forum Windows Programming
    Replies: 16
    Last Post: 06-01-2008, 02:42 PM
  2. Openfilename
    By Gordon in forum Windows Programming
    Replies: 15
    Last Post: 09-22-2007, 04:37 PM
  3. Using OPENFILENAME
    By IdioticCreation in forum Windows Programming
    Replies: 9
    Last Post: 01-16-2007, 07:26 AM
  4. OPENFILENAME structure
    By SuperNewbie in forum Windows Programming
    Replies: 1
    Last Post: 01-22-2004, 06:51 AM
  5. OPENFILENAME and multiple files.
    By -leech- in forum Windows Programming
    Replies: 4
    Last Post: 02-25-2003, 12:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21