DialogBox returns -1. GetLastError returns error 1813.

This is a discussion on DialogBox returns -1. GetLastError returns error 1813. within the Windows Programming forums, part of the Platform Specific Boards category; DialogBox returns -1. GetLastError returns error 1813: The specified resource type cannot be found in the image file. I have ...

  1. #1
    A source of questions... Benji Wiebe's Avatar
    Join Date
    Mar 2011
    Location
    Durham, Kansas
    Posts
    69

    DialogBox returns -1. GetLastError returns error 1813.

    DialogBox returns -1. GetLastError returns error 1813: The specified resource type cannot be found in the image file.
    I have looked through the code, and as far as I can tell, the program has nothing to do with icons, bitmaps, or any other sort of images. Any ideas?
    Ever notice how fast Windows runs?
    Neither did I.
    Which is why I switched to Linux.

  2. #2
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Post the smallest possible code that has the same result.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  3. #3
    A source of questions... Benji Wiebe's Avatar
    Join Date
    Mar 2011
    Location
    Durham, Kansas
    Posts
    69
    I will work on trimming that 300+ lines of code down a little bit.
    Ever notice how fast Windows runs?
    Neither did I.
    Which is why I switched to Linux.

  4. #4
    A source of questions... Benji Wiebe's Avatar
    Join Date
    Mar 2011
    Location
    Durham, Kansas
    Posts
    69
    It gives the error whenever I add the two files accel.rc and accel.h to the project.
    Code:
    //accel.rc
    #include <windows.h>
    /*#include "C:/project/resource.h"*/
    #include "C:/project/accel.h"
    //
    // Accelerator resources
    //
    IDR_ACCELERATOR1 ACCELERATORS
    BEGIN
        "^i",            ID_ACCELERATOR_ADMIN_LOGIN, ASCII
        VK_F1,         ID_ACCELERATOR_HELP, VIRTKEY
        "^o",            ID_ACCELERATOR_ADMIN_LOGOUT
        "^a",            ID_ACCELERATOR_ADD_USER
        "^d",            ID_ACCELERATOR_DELETE_USER
    END
    Code:
    //accel.h
    #define IDR_ACCELERATOR1              99900
    #define ID_ACCELERATOR_ADMIN_LOGIN    99901
    #define ID_ACCELERATOR_HELP           99902
    #define ID_ACCELERATOR_ADMIN_LOGOUT   99903
    #define ID_ACCELERATOR_ADD_USER       99904
    #define ID_ACCELERATOR_DELETE_USER    99905
    Ever notice how fast Windows runs?
    Neither did I.
    Which is why I switched to Linux.

  5. #5
    A source of questions... Benji Wiebe's Avatar
    Join Date
    Mar 2011
    Location
    Durham, Kansas
    Posts
    69
    Anyone have any ideas as to why this is happening?
    Ever notice how fast Windows runs?
    Neither did I.
    Which is why I switched to Linux.

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Benji Wiebe View Post
    Anyone have any ideas as to why this is happening?
    Yep... your accellerator table is malformed... only the first and second lines are correct.

    Accelerator Tables (Windows)

    The correct format is ... key, command value, type, options

    "^o" does not identify shifted O... you need to add the SHIFT option to the line, instead.
    Code:
    "O", 1200, ASCII, SHIFT

    You should also know that when you are using accelerators you have to modify your windows message dispatcher... For accelerators in dialogs it will end up looking something like this...

    Code:
    while( GetMessage(&Msg, hWND, 0, 0) > 0 )
       if ( ! TranslateAccellerator( hWND, hAccellTable,&Msg) )
        if ( ! IsDialogMessage( hWND, &Msg) )
          { TranslateMessage( &Msg);
             DispatchMessage( &Msg); }
    Finally, you should, whenever possible, use the default windows keyboard processing of certain keys...

    For example:
    WM_HELP is issued when the user presses F1
    WM_CONTEXTMENU is issued when the user presses the menu key
    WM_COMMAND is issued with the value IDOK when the user presses Enter
    WM_COMMAND is issued with the value IDCANCEL when the user presses Esc


    And, finally, for reference here's a copy of a working table....
    Code:
    HOTKEYS ACCELERATORS
    {
      80, 1000, VIRTKEY
      VK_SPACE, 1001, VIRTKEY
      83, 1002, VIRTKEY
      VK_PRIOR, 1003, VIRTKEY
      VK_NEXT, 1004, VIRTKEY
      VK_LEFT, 1005, VIRTKEY
      VK_RIGHT, 1006, VIRTKEY
      VK_UP, 1007, VIRTKEY
      VK_DOWN, 1008, VIRTKEY
      49, 1009, VIRTKEY
      50, 1010, VIRTKEY
      51, 1011, VIRTKEY
      52, 1012, VIRTKEY
      VK_RETURN, 1013, VIRTKEY
      84, 1014, VIRTKEY
      88, 1015, VIRTKEY
    }
    Last edited by CommonTater; 09-17-2011 at 11:55 AM.

  7. #7
    A source of questions... Benji Wiebe's Avatar
    Join Date
    Mar 2011
    Location
    Durham, Kansas
    Posts
    69
    ^o was supposed to be Ctrl+o. How do I do that?
    Ever notice how fast Windows runs?
    Neither did I.
    Which is why I switched to Linux.

  8. #8
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Benji Wiebe View Post
    ^o was supposed to be Ctrl+o. How do I do that?
    Did you read the documentation in the link I provided? It explains it quite well.

    Code:
    "O", CMD_VALUE, ASCII, CONTROL
    Really... people do need to know how to look this stuff up for themselves...
    Last edited by CommonTater; 09-17-2011 at 12:33 PM.

  9. #9
    A source of questions... Benji Wiebe's Avatar
    Join Date
    Mar 2011
    Location
    Durham, Kansas
    Posts
    69
    Quote Originally Posted by CommonTater View Post
    Did you read the documentation in the link I provided? It explains it quite well.

    Code:
    "O", CMD_VALUE, ASCII, CTRL
    Really... people do need to know how to look this stuff for themselves...
    Oops. Sorry.
    Ever notice how fast Windows runs?
    Neither did I.
    Which is why I switched to Linux.

  10. #10
    A source of questions... Benji Wiebe's Avatar
    Join Date
    Mar 2011
    Location
    Durham, Kansas
    Posts
    69
    These are the build errors.
    Code:
    windres.exe -i C:\project\resource.rc -J rc -o obj\Debug\project\resource.res -O coff 
    C:\project\resource.rc:9:0: fatal error: when writing output to : No such file or directory
    compilation terminated.
    windres.exe: C:\\project\\resource.rc:21: syntax error
    windres.exe: preprocessing failed.
    Process terminated with status 1 (0 minutes, 0 seconds)
    3 errors, 0 warnings
    This happens with the following accelerator table:
    Code:
    IDR_ACCELERATOR1 ACCELERATORS
    BEGIN
        0x69,            ID_ACCELERATOR_ADMIN_LOGIN, ASCII, CONTROL //ctrl-i
        VK_F1,         ID_ACCELERATOR_HELP, VIRTKEY //F1
        0x6F,            ID_ACCELERATOR_ADMIN_LOGOUT, ASCII, CONTROL //ctrl-o
        0x61,            ID_ACCELERATOR_ADD_USER, ASCII, CONTROL //ctrl-a
        0x64,            ID_ACCELERATOR_DELETE_USER, ASCII, CONTROL //ctrl-d
    END
    Now what?
    Ever notice how fast Windows runs?
    Neither did I.
    Which is why I switched to Linux.

  11. #11
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Benji Wiebe View Post
    These are the build errors.
    Code:
    windres.exe -i C:\project\resource.rc -J rc -o obj\Debug\project\resource.res -O coff 
    C:\project\resource.rc:9:0: fatal error: when writing output to : No such file or directory
    compilation terminated.
    windres.exe: C:\\project\\resource.rc:21: syntax error
    windres.exe: preprocessing failed.
    Process terminated with status 1 (0 minutes, 0 seconds)
    3 errors, 0 warnings
    This happens with the following accelerator table:
    Code:
    IDR_ACCELERATOR1 ACCELERATORS
    BEGIN
        0x69,            ID_ACCELERATOR_ADMIN_LOGIN, ASCII, CONTROL //ctrl-i
        VK_F1,         ID_ACCELERATOR_HELP, VIRTKEY //F1
        0x6F,            ID_ACCELERATOR_ADMIN_LOGOUT, ASCII, CONTROL //ctrl-o
        0x61,            ID_ACCELERATOR_ADD_USER, ASCII, CONTROL //ctrl-a
        0x64,            ID_ACCELERATOR_DELETE_USER, ASCII, CONTROL //ctrl-d
    END
    Now what?
    Here... try using this...

    ResEdit Resource Editor - free resource editor for Win32
    Last edited by CommonTater; 09-17-2011 at 03:29 PM.

  12. #12
    A source of questions... Benji Wiebe's Avatar
    Join Date
    Mar 2011
    Location
    Durham, Kansas
    Posts
    69
    Quote Originally Posted by CommonTater View Post
    That is what I used to create the accelerator table.
    Ever notice how fast Windows runs?
    Neither did I.
    Which is why I switched to Linux.

  13. #13
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Then I have to admit to being stumped... unless the output folder doesn't exist, I have no idea what the problem might be.

  14. #14
    A source of questions... Benji Wiebe's Avatar
    Join Date
    Mar 2011
    Location
    Durham, Kansas
    Posts
    69

    Post

    This is the current content of accel.rc:
    Code:
    // Generated by ResEdit 1.5.7
    // Copyright (C) 2006-2010
    // http://www.resedit.net
    
    #include <windows.h>
    #include <commctrl.h>
    #include <richedit.h>
    #include "accel.h"
    
    
    
    
    //
    // Accelerator resources
    //
    IDR_ACCELERATOR1 ACCELERATORS
    {
        "^I",            ID_ACCELERATOR_ADMIN_LOGIN //ctrl-i
        VK_F1,         ID_ACCELERATOR_HELP, VIRTKEY //F1
        "^O",            ID_ACCELERATOR_ADMIN_LOGOUT //ctrl-o
        "^A",            ID_ACCELERATOR_ADD_USER //ctrl-a
        "^D",            ID_ACCELERATOR_DELETE_USER //ctrl-d
    }
    Now it compiles just fine but when I run it DialogBox generates error 1813. Is the accelerator table okay now?
    Ever notice how fast Windows runs?
    Neither did I.
    Which is why I switched to Linux.

  15. #15
    Registered User
    Join Date
    Sep 2011
    Posts
    1
    thanks a lot ,very helpful

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Operator that returns no value but returns value
    By keira in forum C++ Programming
    Replies: 3
    Last Post: 01-19-2008, 06:22 PM
  2. WriteFile() fails and returns strange error
    By Gerread in forum Windows Programming
    Replies: 7
    Last Post: 11-27-2007, 04:02 AM
  3. DialogBox() Always returns -1
    By Necrofear in forum Windows Programming
    Replies: 5
    Last Post: 12-09-2006, 08:20 AM
  4. main returns int -- compiler returns nonsense
    By Zach L. in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 06-15-2005, 09:53 AM
  5. GetLastError always returns zero
    By saravanan_ts in forum Windows Programming
    Replies: 7
    Last Post: 08-20-2003, 05:48 AM

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