Thread: Problems with resource files

  1. #1
    Unregistered
    Guest

    Arrow Problems with resource files

    I am having trouble incorperating resource files into my programs. With resource files I have created and resource files given as examples I have not been able to compile my program. I am using the Borland free compiler(5.5), and I get the following error:

    Error E2141 d1.rc 9: Declaration syntax error

    The code from the resource script is..

    DIALOG1 DIALOG 127, 64, 228, 138
    STYLE WS_VISIBLE | WS_SYSMENU | WS_THICKFRAME | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_POPUP |WS_CAPTION |WS_BORDER |WS_DLGFRAME
    CAPTION "Dialog"
    FONT 8, "MS Sans Serif"
    LANGUAGE LANG_NEUTRAL, 0
    BEGIN
    CONTROL "Ok",106,"BUTTON",BS_PUSHBUTTON|WS_VISIBLE|WS_TABS TOP,179,73,35,20
    CONTROL "Cancel",107,"BUTTON",BS_PUSHBUTTON|WS_VISIBLE|WS_ TABSTOP,177,106,35,20
    END


    The error happens on the first line here, the "DIALOG1 DIALOG etc" line.

    This is very frusterating because it seems like the error is in something I didn't do, but I'm guessing that it has something to do with the compiler's options. Can anybody help?

  2. #2
    zooo
    Guest
    Hopefully someone with more knowledge about this compiler will post a reply, but I think you have to use the resource compiler to compile a .rc file.

    brc32 filename.rc

    Possibly there may be a switch that allows you to compile it with bcc32.

  3. #3
    Unregistered
    Guest
    Okay I compile just fine with brc32 and I get a d1.res file. Now how do I get my program to read from the d1.res file? I can compile but because the program can't find it's resource file the program doesn't do much of anything. I tried including it in the compile line and that doesn't work.

  4. #4
    zoo
    Guest
    I'll let you know in about an hour. My borland compiler is on another computer, and the command is long.

  5. #5
    zoo
    Guest
    Here's the commands:

    1. Make sure you compile your .cpp file something similar to this:
    bcc32 -c -W filename.cpp

    2. To link the program into an .exe, do this:
    ilink32/Tpe c0w32 filename.obj,filename.exe,,cw32.lib import32.lib,,resource_filename.res

    This assumes filename is the name of your .cpp and resource_filename.res is the name of your compiled resource.

    Supposedly there is a command to add the resource to the .exe after linking, but apparently it does not work on this version of the borland compiler.

  6. #6
    zoo
    Guest
    An easy way to do this is to put these commands in a batch (.bat) file and run the batch file to compile.

  7. #7
    Unregistered
    Guest
    I got it all to compile but still no results.

    Here's the main file:

    #include <windows.h>
    #include <tchar.h>
    #include "wintestres.h"

    BOOL MainDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
    return FALSE;
    }

    int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {

    DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(DIALOG1),
    NULL, (DLGPROC)MainDialogProc, 0);
    return 0;

    }



    wintestres.h:
    //{{NO_DEPENDENCIES}}
    // Used by d1.rc
    //
    #define DIALOG1 101

    // Next default values for new objects
    //
    #ifdef APSTUDIO_INVOKED
    #ifndef APSTUDIO_READONLY_SYMBOLS
    #define _APS_NEXT_RESOURCE_VALUE 102
    #define _APS_NEXT_COMMAND_VALUE 40001
    #define _APS_NEXT_CONTROL_VALUE 1000
    #define _APS_NEXT_SYMED_VALUE 101
    #endif
    #endif



    d1.rc:
    /*********************************************
    File: C:\BORLAND\BCC55\BIN\D1.RC
    Generated by Resource Builder 1.0.
    *********************************************/
    // Below are important 3 lines, don't change them!
    /*
    OutputExt=RES
    */
    DIALOG1 DIALOG 127, 64, 228, 138
    STYLE WS_VISIBLE | WS_SYSMENU | WS_THICKFRAME | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_POPUP |WS_CAPTION |WS_BORDER |WS_DLGFRAME
    CAPTION "Dialog"
    FONT 8, "MS Sans Serif"
    LANGUAGE LANG_NEUTRAL, 0
    BEGIN
    CONTROL "Ok",106,"BUTTON",BS_PUSHBUTTON|WS_VISIBLE|WS_TABS TOP,179,73,35,20
    CONTROL "Cancel",107,"BUTTON",BS_PUSHBUTTON|WS_VISIBLE|WS_ TABSTOP,177,106,35,20
    END

    Do you see any problems anywhere in there? I took most of this stuff from a tutorial and the rc file was through a resource generator, so it doesn't seem like anything should be wrong, but..

  8. #8
    .
    Join Date
    Aug 2001
    Posts
    598
    Of coarse instad of using the command promp, you could use vide. Witch is much easer. All I have to do to use a resource file is include it with my project. Very simple.
    To Err Is To Be Human. To Game Is Divine!"

  9. #9
    Unregistered
    Guest
    The command prompt is all I have.

  10. #10
    .
    Join Date
    Aug 2001
    Posts
    598
    >The command prompt is all I have.

    Vide is an IDE that can be used with borland 5.5. You can get it at www.objectcentral.com and it's free.
    To Err Is To Be Human. To Game Is Divine!"

  11. #11
    zoo
    Guest
    Getting Vide is a good idea ... need to do that myself.

    As far as your code, try this:


    int WINAPI WinMain( HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszCmdLine,int nCmdShow ) {

    DialogBoxParam(hInstance, MAKEINTRESOURCE(DIALOG1),
    NULL, (DLGPROC)MainDialogProc, 0);


    You need to pass the module instance (hInstance) to DialogBoxParam().

  12. #12
    zoo
    Guest
    I think you can simply your call to DialogBoxParam() like this:

    DialogBoxParam(hInstance, "DIALOG1", NULL, (DLGPROC)MainDialogProc, 0);

    Try it and if it doesn't work, use the MAKEINTRESOURCE.

    Also, your dialog procedure should be a CALLBACK function. Plus, each button needs to be processed:

    Code:
    BOOL CALLBACK MainDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
       switch( uMsg ) {
          case WM_INITDIALOG:
             return TRUE;
          case WM_COMMAND:
             switch( wParam ) {
                //case IDOK:
                //   EndDialog( hDlg, TRUE );
                //   return TRUE;
                case 106:
                   EndDialog( hDlg, TRUE );
                   return TRUE;
                case 107:
                   EndDialog( hDlg, TRUE );
                   return TRUE;
                case IDCANCEL:
                   EndDialog( hDlg, TRUE );
                   return TRUE;
             }
          break;
       }
    
       return FALSE;
    }
    Also there are predefined names for OK and CANCEL buttons. To use these, change your .rc, and change 106 to IDOK and 107 to IDCANCEL. Then you can remove the cases for 106 and 107 in the dialog procedure, and uncomment the one for IDOK. If you had a third button, add code to process it:

    Code:
    BOOL CALLBACK MainDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
       switch( uMsg ) {
          case WM_INITDIALOG:
             return TRUE;
          case WM_COMMAND:
             switch( wParam ) {
                case IDOK:
                   EndDialog( hDlg, TRUE );
                   return TRUE;
                case IDCANCEL:
                   EndDialog( hDlg, TRUE );
                   return TRUE;
                case BUTTON3:
                   ...
                   return TRUE;
             }
          break;
       }
    
       return FALSE;
    }

  13. #13
    zoo
    Guest
    Typo:
    I think you can "simplify" your call to DialogBoxParam() like this:

  14. #14
    Unregistered
    Guest
    ! Error: 'C:\BORLAND\BCC55\BIN\CW32.LIB' contains invalid OMF record, type
    * 0x0d


    Why am I getting this error? Doesn't seem fair when the files I got with my compiler are having errors..

  15. #15
    zoo
    Guest
    If you are getting this error during the ILINK32 step, make sure you are not missing any commas, the command must be exact.
    Just cut and paste the following into a .bat file.

    ilink32/Tpe c0w32 filename.obj,filename.exe,,cw32.lib import32.lib,,resource_filename.res


    If you are getting this error from some other command, then I have no idea.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do you work with resource files???
    By Finchie_88 in forum Windows Programming
    Replies: 4
    Last Post: 10-23-2004, 02:39 PM
  2. Replies: 6
    Last Post: 08-13-2003, 04:35 AM
  3. Problems openning huge files
    By acoelho74 in forum C Programming
    Replies: 4
    Last Post: 02-11-2003, 07:02 PM
  4. Resource Files
    By Unregistered in forum Windows Programming
    Replies: 11
    Last Post: 09-11-2001, 10:52 PM