I get an error from
invoke FormatMessage,1000,eax,eax,0,OFFSET erbf,100,0
This is the same as code that worked before. The parameters are
1000 = flag, from system eax is from GetLastErrorr
0 is language - default
erbf DB 200 DUP (?) is the receiving buffer
100 is buffer size in tchars
0 is arguments - none/default
I can't figure out what's wrong, When the code worked it was global, but that can't matter, can it?
Can anyone help?
Thanks
Fuller context is:
germs2:
invoke GetLastError
invoke FormatMessage,1000,eax,eax, 0,OFFSET erbf,100,0
invoke MessageBox, hwnd, ADDR erbf, ADDR mbcap, MB_CANCELTRYCONTINUE
int 3
retn
This is in WinMain, which is:
WinMain proc hInst,hPrevinst,CmdLine,CmdShow
LOCAL msg:MSG
LOCAL hwnd:HWND
invoke RegisterClassEx, OFFSET LFwc
mov edx, CW_USEDEFAULT
invoke CreateWindowEx,WS_EX_APPWINDOW,ADDR ClassName,ADDR AppName,\
WS_OVERLAPPEDWINDOW,edx,edx,edx,edx,eax,eax,hInst,eax
or eax, eax
jz germs2
mov [hwnd], eax
invoke ShowWindow,hwnd,SW_SHOWMAXIMIZED
invoke UpdateWindow, hwnd
.while TRUE
invoke GetMessage, ADDR msg,0,0,0
.break .if (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.endw
[gsva omitted]
ret
CreateWindowEx returns 0 and we get to germs2, which is in Winmain just before Winmain endp
FORMAT_MESSAGE_FROM_SYSTEM == 4096 in decimal.... don't use hardcoded numbers in your source... should use the equates...
This works fine for me...
invoke SetLastError, 500
invoke GetLastError
invoke FormatMessage, FORMAT_MESSAGE_FROM_SYSTEM, NULL, eax, NULL, OFFSET erbf, 100, NULL; lea esi, SpammerInfo
invoke MessageBox, NULL, offset erbf, NULL, MB_CANCELTRYCONTINUE
- edit -
Sorry, just noticed you use 16 base... grrrr
either way, just tried:
invoke SetLastError, 500
invoke GetLastError
.radix 16
invoke FormatMessage, 1000, NULL, eax, NULL, OFFSET erbf, 100, NULL; lea esi, SpammerInfo
.radix 10
invoke MessageBox, NULL, offset erbf, NULL, MB_CANCELTRYCONTINUE
and it works as expected
Quote from: Gunner on August 14, 2011, 02:13:41 AM
FORMAT_MESSAGE_FROM_SYSTEM == 4096 in decimal.... FormatMessage expects decimal not hex AFAIK... don't use hardcoded numbers in your source... should use the equates... replace 1000 with FORMAT_MESSAGE_FROM_SYSTEM or 4096 and it will work!
This works fine for me...
invoke SetLastError, 500
invoke GetLastError
invoke FormatMessage, FORMAT_MESSAGE_FROM_SYSTEM, NULL, eax, NULL, OFFSET erbf, 100, NULL; lea esi, SpammerInfo
invoke MessageBox, NULL, offset erbf, NULL, MB_CANCELTRYCONTINUE
I must be missing something. eax is 578 on return from GetLastError. I still get error (0) from FormatMessage and erbf is still all 0s.
testp.lst and the debugger dissasembly show the last push before call FormatMessage as push 1000h. Likewise with your set and get (Except, of course, eax is 500)
Should I have mentioned that my code is radix 16?
germs2:
invoke GetLastError
;invoke SetLastError, 500
;invoke GetLastError
invoke FormatMessage, FORMAT_MESSAGE_FROM_SYSTEM, NULL, eax, NULL, OFFSET erbf, 100, NULL
invoke MessageBox, NULL, offset erbf, NULL, MB_CANCELTRYCONTINUE
retn
I will dl and look at your source, but your return code is invalid handle
(http://www.gunnerinc.com/images/badhandle.png)
Quote from: Gunner on August 14, 2011, 02:51:42 AM
I will dl and look at your source, but your return code is invalid handle
That's nice to know.
I appreciate your effort.
I fixed the CreateWindowEx error, so the priority on the FormatMessage problem has dropped.
The problem still exists; no change. But if you want to drop it, Gunner, I don't mind at all.
I really appreciate the efforts of you and the other Forum experts.
Thank you. :bg
Createwindow..... You were passing it an invalid handle for its parent?
Quote from: Gunner on August 14, 2011, 05:10:45 AM
Createwindow..... You were passing it an invalid handle for its parent?
Exactly. I was passing the return from RegisterClassEx, an atom. I thought I was passing the module handle, but that's not right either. Right (I think - it works) is 0 - no parent.
The bug was easy to find; I just looked at a working program.
I caused the problem for myself by doing 2 things at once, the misguided change in Create and the error routine.
Thanks.
Well, the parent of your main windows, is the desktop.. there is an equate for that... HWND_DESKTOP which is 0 I caught that in your createwindow right before I turned my computer off.. Now if only I can find a text editor for android that I like, then I can view your code on my phone :)
the problem may be in the WndProc, not the CreateWindowEx parameters
make sure you are using the correct hWnd for DefWindowProc
Quote from: raleeper on August 14, 2011, 05:06:18 AM
I fixed the CreateWindowEx error, so the priority on the FormatMessage problem has dropped.
include \masm32\include\masm32rt.inc ; make sure Masm32 macros are in...
; no other includes please, unless you are doing really exotic stuff
....
print LastError$(), 13, 10 ; console mode
MsgBox 0, LastError$(), "Hi", MB_OK ; any mode
(but still it would be nice to know where the bug was, right? :bg)
Quote from: dedndave on August 14, 2011, 06:03:55 AM
the problem may be in the WndProc, not the CreateWindowEx parameters
make sure you are using the correct hWnd for DefWindowProc
Well, I don't have the CreateWindowEx problem since I started (or went back to) passing 0 (which I thought meant none, but which Gunner informed me was the definition of HWND_DESKTOP) as the hparent.
I have a hard time shedding my linear thinking, It never occurred to me that the OS might call the WndProc before it finishes WinMain.
So I'll check to make sure I'm using the correct hWnd for DefWindowProc.
Thank you
Quote from: jj2007 on August 14, 2011, 07:14:40 AM
Quote from: raleeper on August 14, 2011, 05:06:18 AM
I fixed the CreateWindowEx error, so the priority on the FormatMessage problem has dropped.
include \masm32\include\masm32rt.inc ; make sure Masm32 macros are in...
; no other includes please, unless you are doing really exotic stuff
....
print LastError$(), 13, 10 ; console mode
MsgBox 0, LastError$(), "Hi", MB_OK ; any mode
(but still it would be nice to know where the bug was, right? :bg)
I'll need some time to digest this.
Thanks Jochen.
I am giving up on the FormatMessage Error problem.
The return from FormatMessage is
ERROR_NOACCESS 3e6h = 998d Invalid access to memory location.
I don't need FormatMessage. I'll just use the debugger to look at the return from GetLastError, or better yet have my program display it, then look it up.
More trouble, sure, but I'll just curse Microsoft.
Thanks
Quote from: raleeper on August 14, 2011, 05:21:53 PM
I am giving up on the FormatMessage Error problem.
Don't give up so easily, no mystery is safe in the Masm32 Forum:
include \masm32\include\masm32rt.inc
.radix 16 ; test with and without
MyTest PROTO: DWORD, :DWORD
.code
AppName db "Masm32 is great!", 0
Hello db "A message:", 0
start:
invoke MyTest, offset AppName, addr Hello
exit
MyTest proc arg1:DWORD, arg2:DWORD
LOCAL msg:MSG, wx:HWND
MsgBox 0, arg1, arg2, MB_OK
ret
MyTest endp
end start
Olly reveals that the LOCALs are, well, a bit odd. Check for sub esp, xx :bg
Interestingly enough, JWasm produces the same nonsense.
Quote from: jj2007 on August 14, 2011, 09:01:16 PM
Quote from: raleeper on August 14, 2011, 05:21:53 PM
I am giving up on the FormatMessage Error problem.
Don't give up so easily, no mystery is safe in the Masm32 Forum:
include \masm32\include\masm32rt.inc
.radix 16 ; test with and without
MyTest PROTO: DWORD, :DWORD
.code
AppName db "Masm32 is great!", 0
Hello db "A message:", 0
start:
invoke MyTest, offset AppName, addr Hello
exit
MyTest proc arg1:DWORD, arg2:DWORD
LOCAL msg:MSG, wx:HWND
MsgBox 0, arg1, arg2, MB_OK
ret
MyTest endp
end start
Olly reveals that the LOCALs are, well, a bit odd. Check for sub esp, xx :bg
Interestingly enough, JWasm produces the same nonsense.
Well, I'm not going to work on it now, and asking others to go on seems to me just like asking others to do (not help with) your homework. So I won't.
Thanks, Robert
Robert, don't worry - we just discovered a Masm bug thanks to your problem. That's like having a party in the Forum - champagne!! :green2
Quote from: jj2007 on August 14, 2011, 09:19:33 PM
Robert, don't worry - we just discovered a Masm bug thanks to your problem. That's like having a party in the Forum - champagne!! :green2
Well, that vindicates my "curse Microsoft" to some extent.
I'll watch your further progress with considerable interest.
Thanks
Quote from: raleeper on August 14, 2011, 09:44:56 PM
Quote from: jj2007 on August 14, 2011, 09:19:33 PM
Robert, don't worry - we just discovered a Masm bug thanks to your problem. That's like having a party in the Forum - champagne!! :green2
Well, that vindicates my "curse Microsoft" to some extent.
I'll watch your further progress with considerable interest.
Thanks
If I used pushed the parameters, used 'call FormatMessage' instead of 'invoke...' and did my own stack cleanup (for 4 parameters that would just be 'add esp 16d' [and maybe also restore ebp] wouldn't it?),, might that be a viable workaround until a masm patch is available. Or is the bug more pervasive?
{This is still low priority for me. Even if you say 'try it, I might not get aroun to it for a while)
i think it's easier to avoid the radix of 16 :U
delet the .radix in testp and recompile,you see :
Quote
E:\poubelle
Assembling: essai.asm
E:\poubelle
Assembling: testp.asm
testp.asm(306) : error A2048: nondigit in number
testp.asm(333) : error A2048: nondigit in number
testp.asm(334) : error A2048: nondigit in number
testp.asm(390) : error A2048: nondigit in number
testp.asm(391) : error A2048: nondigit in number
testp.asm(393) : error A2048: nondigit in number
testp.asm(399) : error A2048: nondigit in number
testp.asm(414) : error A2048: nondigit in number
testp.asm(462) : error A2048: nondigit in number
testp.asm(466) : error A2048: nondigit in number
testp.asm(467) : error A2048: nondigit in number
testp.asm(474) : error A2048: nondigit in number
testp.asm(327) : error A2006: undefined symbol : dspl_0
Quote
seems the .radix (not very used) have some strange effects
The badest effect is that you are lose in your syntax.
Quote
invoke CreateFontIndirect,edi
mov [hfont1], eax ;<------------------------------------------ mov hfont1,eax N errors like this
use
.if eax ==
.endif
instead off:
cmp eax,value
Jxxx
Masm is able to translate a .if in the correct jxx and put also the label for you.
and finally the big error:
Quote
chinst DD 0 ;14 Dwords at 14,18,1C and 2C are copied
DD 0 ;18 from LFwc in newwin
DD 0 ;1C
DD 0 ;20 From CreateSolidBrush,0EEEE00
DD 0 ;24
DD ChldClass ;28 ClassName
DD 0 ;2C
Use structures
NAME STRUCT
chinst DD ? ;14 Dwords at 14,18,1C and 2C are copied
name1 DD ? ;18 from LFwc in newwin
name2 DD 0 ;1C
name3 DD 0 ;20 From CreateSolidBrush,0EEEE00
DD 0 ;24
DD ChldClass ;28 ClassName
DD 0 ;2C
NAME ENDS
Quote from: ToutEnMasm on August 15, 2011, 05:43:44 AM
and finally the big error:
Quote
chinst DD 0 ;14 Dwords at 14,18,1C and 2C are copied
DD 0 ;18 from LFwc in newwin
DD 0 ;1C
DD 0 ;20 From CreateSolidBrush,0EEEE00
DD 0 ;24
DD ChldClass ;28 ClassName
DD 0 ;2C
Use structures
NAME STRUCT
chinst DD ? ;14 Dwords at 14,18,1C and 2C are copied
name1 DD ? ;18 from LFwc in newwin
name2 DD 0 ;1C
name3 DD 0 ;20 From CreateSolidBrush,0EEEE00
DD 0 ;24
DD ChldClass ;28 ClassName
DD 0 ;2C
NAME ENDS
You mean to tell me that a block of data declared with a label as I have done will assemble differently than the same thing done with a structure? In either case won't eg., hbkbr or LFwc.hbkbr evaluate to LFwc+20h? And the OS will put the same value in ebp and all references to the block or structure will be [ebp+something], and the same thing whether the data is declared one way or the other, which the OS won't even know. What am I missing?
For reference, my block is:
LFwc LABEL DWORD ;LFile Window Class structure
DD SIZEOF WNDCLASSEX ; 0 wc.cbSize
DD lfstyle ; 4 wc.style
DD OF WProc ; 8 wc.lpfnWndProc
DD 0,0 ;0C wc.cbClsExtra, wc.cbWndExtra
hinst DD ? ;14 wc.hinst
hicon DD ? ;18 LoadIcon,0,IDI_APPLICATION
hcurs DD ? ;1C LoadCursor,NULL,IDC_ARROW
hbkbr DD ? ;20 CreateSolidBrush,0FF0000h
wcmen DD 0 ;24 wc.lpszMenuName
DD OF ClassName ;28 wc.lpszClassName
hiconsm DD ? ;2C wc.hIconSm
;30 end LFwc
(Please pardon the tabs)
Nothing wrong with the tabs. Old versions of MS Internet Explorer had problems, but FF always handled them well:
(http://www.masm32.com/board/index.php?action=dlattach;topic=17234.0;id=9615)
Don't open "attached" tabs.zip - it is just the screenshot you see above.
@ToutEnMasm: What you write looks very improbable. Could you post a working example showing the effect you are claiming? Merci.
Quote from: ToutEnMasm
@ToutEnMasm: What you write looks very improbable. Could you post a working example showing the effect you are claiming? Merci.
Sure. I can't tell if the child window is really showing correctly since it's undeveloped, but the main window seems to have no problems'
Without the used of .iF and structures,masm couldn't verify that all is well written.
The big error is here.It is just laborious write with no secure.
Quote from: raleeper on August 15, 2011, 07:35:29 AM
Sure. I can't tell if the child window is really showing correctly since it's undeveloped, but the main window seems to have no problems'
Example back. If have added a trailing h wherever I could so that you can switch between radix 10 and 16. CreateWindowEx is misbehaving for radix 16....
Depending on whether you assemble with radix 10/16, code size differs considerably. Really strange.
@ToutEnMasm: You are on the wrong track. Try a more constructive approach please.
Edit: The wrong stack alignment is present up to MASM version 8.0. Version 9 and 10, and the latest JWasm version, work fine
Quote
@ToutEnMasm: You are on the wrong track. Try a more constructive approach please.
Perhaps can you give those remarks for you ,No ?
and if not is the same.
if the macro language exists is to help writing ;<--------------------------------------
It seems the PROLOGUE/EPILOGUE macros are affected...
end of CWProc:
CPU Disasm
Address Hex dump Command Comments
004013E3 ³. E8 4A010000 call <jmp.&user32.DefWindowP ; ÀUSER32.DefWindowProcA
004013E8 ³. 61 popad
004013E9 ³. 5D pop ebp
004013EA ³. C2 1600 retn 16 <<<<<<<<<<<<<<<< retn 10 for the radix 10 version
004013ED ³> 61 popad
004013EE ³. 33C0 xor eax, eax
004013F0 ³. 5D pop ebp
004013F1 ³. C2 1600 retn 16 <<<<<<<<<<<<<<<< retn 10 for the radix 10 version
The culprit is a simple ret... and imho this is is a big fat Masm bug.
Attached a perfectly working version, in .radix 10 or .radix 16.
Success! I am not certain exactly what did the trick, but I am pretty sure it was the error pointed out by jj2007 in Topic "Later versions of MASM - More Passes",
QuoteBy the way, the original problem in your TestP source was in line 185:
invoke WinMain, hinst, 0, cmdl, SW_SHOWDEFAULT ; bad
invoke WinMain, hinst, 0, offset cmdl, SW_SHOWDEFAULT ; good
Fixing that (or something) also fixed the problem described in Topic "Child Window Makes Parent Inactive - Another try".
Thanks to jj207 and all those who relied.
Here's an example of an unwarned failure to assemble:
Working on test I had:
ChSty EQU WS_CHILD or WS_TILEDWINDOW
That failed to assemble w/ the message 'undefined..WS_TILEDWINDOW'
(I know I probably lack an include file - later for that)
So I changed it to:
ChSty EQU WS_CHILD or WS_OVERLAPPEDWINDOW
THAT failed to assemble w/ the message 'undefined..WS_TILEDWINDOW'
--------------------------
The change was properly shown in the testp.asm file.
So I thought, 'I don't have 2 testp.asm' files, do I' Nope.
Next try - delete testp.asm and start over, check .asm before assy.
Nope. Where could masm be getting the old testp.asm that it is apparently
using.
Maybe the problem is in the batch file I use to assemble. It is:
[This seriously needs cleaning up - I'll do that soon]
g:\prog\masm32\bin\ml /c /coff /Cp /Fl /W2 /Zi /Ig:\prog\masm32\include g:\lfw\testp.asm >errs
if errorlevel 1 goto erfc
if errorlevel 1 goto erfc
g:\prog\masm32\bin\link /SUBSYSTEM:WINDOWS /LIBPATH:g:\prog\masm32\lib /DEBUG /DEBUGTYPE:CV testp.obj >>errs
IF errorlevel 1 goto erfc
exit
:erfc
type errs
pause
cd\
c:
I don't see anything wrong.
Does anyone have an idea as to what's happening?
Thanks, Robert
As I don't use batch files myself... Most batch files I have seen delete the obj files if they exist before linking?
UM.... WS_TILEDWINDOW
you have WS_TILEWINDOW in your source
in one of your createwidows at least... you might be missing WS_TILEDWINDOW from you windows.inc?
The batch file could
- delete the previous executable
- delete the previous obj file
- test the errorlevel variable after assembly (but attention, not all assemblers get it right)
MasmBasic (http://www.masm32.com/board/index.php?topic=12460) users could check \masm32\RichMasm\Res\bldallRM.bax - a true source of inspiration :wink - and it almost never fails when loading a *.asm file and hitting the Assemble & Link & Run button; actually I haven't seen it choking for ages. But it looks pretty daunting I'm afraid.
Quote from: Gunner on August 18, 2011, 09:29:38 PM
As I don't use batch files myself... Most batch files I have seen delete the obj files if they exist before linking?
How do you assemble? My method goes back to the days of DOS and I'd love something better.
Thanks
Quote from: raleeper on August 18, 2011, 09:42:02 PM
Quote from: Gunner on August 18, 2011, 09:29:38 PM
As I don't use batch files myself... Most batch files I have seen delete the obj files if they exist before linking?
How do you assemble? My method goes back to the days of DOS and I'd love something better.
Thanks
The IDE I use handles all that for me :bg
Quote from: jj2007 on August 18, 2011, 09:40:36 PM
The batch file could
- delete the previous executable
- delete the previous obj file
I'll try it. The .obj file is an obvious (now that you mention it) suspect.
But I don't want to do that generally, I want the files for the last successful assembly always available.
Quote
MasmBasic (http://www.masm32.com/board/index.php?topic=12460) users could check \masm32\RichMasm\Res\bldallRM.bax - a true source of inspiration :wink - and it almost never fails when loading a *.asm file and hitting the Assemble & Link & Run button; actually I haven't seen it choking for ages. But it looks pretty daunting I'm afraid.
Quote from: Gunner on August 18, 2011, 09:45:55 PM
The IDE I use handles all that for me :bg
Do you have an estimate as to how long it would take one who doesn't know what an IDE is to get up and running with them?
Quote from: Gunner on August 18, 2011, 09:36:46 PM
UM.... WS_TILEDWINDOW
you have WS_TILEWINDOW in your source
in one of your createwidows at least... you might be missing WS_TILEDWINDOW from you windows.inc?
Ah!. You have a sharp eye.
Thanks
Quote from: raleeper on August 18, 2011, 09:57:19 PM
Quote from: Gunner on August 18, 2011, 09:45:55 PM
The IDE I use handles all that for me :bg
Do you have an estimate as to how long it would take one who doesn't know what an IDE is to get up and running with them?
I use RadASM, you can find it here: http://www.masm32.com/board/index.php?board=11.0... Takes 4.3 minutes :-) to set up... you just tell it some paths in options and you are ready to go..
Quote from: raleeper on August 18, 2011, 09:53:09 PM
Quote from: jj2007 on August 18, 2011, 09:40:36 PM
The batch file could
- delete the previous executable
- delete the previous obj file
Nope.
I manually deleted all the testp files and masm still dredged up from somewhere the file w/ TILEWINDOW. I'm going to restart the cmptr.
Thanks.
I'll try it. The .obj file is an obvious (now that you mention it) suspect.
But I don't want to do that generally, I want the files for the last successful assembly always available.
Quote
MasmBasic (http://www.masm32.com/board/index.php?topic=12460) users could check \masm32\RichMasm\Res\bldallRM.bax - a true source of inspiration :wink - and it almost never fails when loading a *.asm file and hitting the Assemble & Link & Run button; actually I haven't seen it choking for ages. But it looks pretty daunting I'm afraid.
Quote from: Gunner on August 18, 2011, 10:11:45 PM
Quote from: raleeper on August 18, 2011, 09:57:19 PM
Quote from: Gunner on August 18, 2011, 09:45:55 PM
The IDE I use handles all that for me :bg
Do you have an estimate as to how long it would take one who doesn't know what an IDE is to get up and running with them?
I use RadASM, you can find it here: http://www.masm32.com/board/index.php?board=11.0... Takes 4.3 minutes :-) to set up... you just tell it some paths in options and you are ready to go..
Ah! Plus no doubt a couple of hours for learning and mistakes, but still no problem. I'll try it.
Thanks!
Quote from: Gunner on August 18, 2011, 09:36:46 PM
in one of your createwidows at least...
That sounds dangerous, man. So what would CreateWidowsEx do?
Quote from: jj2007 on August 18, 2011, 10:19:20 PM
Quote from: Gunner on August 18, 2011, 09:36:46 PM
in one of your createwidows at least...
That sounds dangerous, man. So what would CreateWidowsEx do?
Lmao
1 I apologize for putting my original post on this sub-topic in the wrong Topic. It should have gone in Re: Later versions of MASM - More Passes or a new Topic. (my original post started(
Quote
Re: FormatMessage Error
« Reply #32 on: Today at 05:23:44 PM »
Reply with quote Modify message
Here's an example of an unwarned failure to assemble:
Working on test I had:
ChSty EQU WS_CHILD or WS_TILEWINDOW
2. But to continue the discussion with jj2007 - last at 5:53:09pm -
I've done everything I can think of to get rid of any source from which masm might be getting the old file with 'WS_TILEWINDOW', including doing a new successful assembly of the last working version.
Next I'll try starting completely afresh with a new file name.
Thanks
Oh No. I had another instance of 'WS_TILEWINDOW' in testp. I've been wasting your time.
I'm sorry. I need to be more careful.
Thank you for the patience you've shown.