.CODE
invoke LoadAccelerators, hInst, IDA_ACCEL
mov hAccel,eax
.WHILE TRUE
INVOKE GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke TranslateAccelerator, msg.hwnd, hAccel, ADDR msg
.CONTINUE .IF (eax)
INVOKE TranslateMessage, ADDR msg
INVOKE DispatchMessage, ADDR msg
.ENDW
mov eax,msg.wParam
ret



:?
Posted on 2002-06-02 07:01:30 by hunter
hunter,
The second parameter to LoadAccelerators should be a pointer to a string name. By passing the IDA_ACCEL you're pointing it to some random place in memory. This is the proper way to do it (I will assume you are defining the accelerator table in a resource)



rsrc.rc:

AppAccel ACCELERATORS
BEGIN
"O",IDM_FILE_OPEN,CONTROL,VIRTKEY
END

source.asm:

.data
MyAccelName db "AppAccel",0

.code
invoke LoadAccelerators,hInstance,addr MyAccelName\



cya

--Chorus
Posted on 2002-06-02 12:32:44 by chorus
.rc

TheAccel ACCELERATORS
BEGIN
"x",IDM_EXIT,CONTROL,VIRTKEY
"s",IDM_SAVE,CONTROL,VIRTKEY
END


.asm

.DATA

AccelName db 'TheAccel',0

.CODE

invoke LoadAccelerators, hInst, ADDR AccelName
mov hAccel,eax
.WHILE TRUE
INVOKE GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke TranslateAccelerator, msg.hwnd, hAccel, ADDR msg
.IF !EAX
invoke TranslateMessage,ADDR msg
invoke DispatchMessage,ADDR msg
.ELSE
invoke GetLastError
invoke FormatMessage,\
FORMAT_MESSAGE_FROM_SYSTEM,\
NULL, eax, NULL, ADDR buffer, MAX_PATH, NULL
invoke MessageBoxEx, hwnd, ADDR buffer, ADDR
szAppName,\
MB_OK+MB_ICONINFORMATION, LANG_SPANISH
.ENDIF
.ENDW
mov eax,msg.wParam
ret


GetLastError = ERROR_NOT_ENOUGH_MEMORY EQU 8
Posted on 2002-06-02 18:21:23 by hunter
this is wired!

you can of course use an ID for the accel table, like in your first post (invoke LoadAccelerators, hInst, IDA_ACCEL).

This error should not happen :)
Can you give some more details? Did you try the code posted or have you some more "body" around it? Maybe the function works only with valid window handles. Do you have a window proc? maybe some register save problems - these lead somethimes to such wired errors.
Posted on 2002-06-03 04:20:43 by beaster
code:

myprog.rc

TheAccel ACCELERATORS
BEGIN
"s",IDM_SAVE,VIRTKEY, CONTROL
"x",IDM_EXIT,VIRTKEY, CONTROL
"r",IDM_RELOAD,VIRTKEY, CONTROL
END


code:

.DATA
...
AccelName db 'TheAccel',0
....

code:
invoke GetModuleHandle, NULL
mov hInstance,eax

invoke GetCommandLine
invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
invoke ExitProcess,eax

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG

mov wc.cbSize,SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInst
pop wc.hInstance
mov wc.hbrBackground,COLOR_WINDOW
mov wc.lpszMenuName,OFFSET MenuName
mov wc.lpszClassName,OFFSET szClassName
invoke LoadIcon,hInst,IDI_ICON1
mov hIcon,eax
mov wc.hIcon,eax
mov wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
invoke RegisterClassEx, addr wc
INVOKE CreateWindowEx,NULL,ADDR szClassName,ADDR szAppName,\ WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
CW_USEDEFAULT,700,500,NULL,NULL,\
hInst,NULL
mov hwnd,eax
INVOKE ShowWindow, hwnd,SW_SHOWNORMAL
INVOKE UpdateWindow, hwnd
invoke LoadAccelerators, hInst, ADDR AccelName
mov hAccel,eax
.WHILE TRUE
INVOKE GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke TranslateAccelerator, msg.hwnd, hAccel, ADDR msg
.IF !EAX
invoke TranslateMessage,ADDR msg
invoke DispatchMessage,ADDR msg
.ELSE
call show_error
.ENDIF
.ENDW
mov eax,msg.wParam
ret
WinMain endp


It is very strange ... :(
Posted on 2002-06-03 05:13:23 by hunter
Compiler options:

d:\masm32\bin\ml /c /coff /Cp /Id:\masm32\include myprog.asm
d:\masm32\bin\rc myprog.rc
d:\masm32\bin\Link /SUBSYSTEM:WINDOWS /LIBPATH:d:\masm32\lib myprogr.obj myprog.res
Posted on 2002-06-03 05:17:01 by hunter
The docs say the return code of TranslateAccelerators is nonzero if the function succeeds. So if it succeeds, why are you checking for an error code?
Posted on 2002-06-03 05:24:02 by tenkey
int TranslateAccelerator(

HWND hWnd, // handle of destination window
HACCEL hAccTable, // handle of accelerator table
LPMSG lpMsg // address of structure with message
);

If the function succeeds, the return value is TRUE.

If the function fails, the return value is FALSE. To get extended error information, call GetLastError.

...
When TranslateAccelerator returns a nonzero value and the message is translated, the application should not use the TranslateMessage function to process the message again.
....
Posted on 2002-06-03 05:49:41 by hunter
too MUCH data while procesing

.ELSEIF uMsg == WM_COMMAND
...
...


I 'move' some code and make 'call function1' .. 'call function2' .. .etc and voila! .. it works.
Posted on 2002-06-03 10:58:23 by hunter