flat assembler
Message board for the users of flat assembler.

Index > Windows > MSDN discrepancies...

Author
Thread Post new topic Reply to topic
bitRAKE



Joined: 21 Jul 2003
Posts: 4037
Location: vpcmpistri
bitRAKE 02 Jul 2008, 20:37
Just traced down one of those stupid typo errors to find that RegisterClassEx errors when AX is zero - I have assumed MSDN means EAX equal zero is an error:
Quote:
If the function fails, the return value is zero.
WTF, MS - thanks for wasting 30 minutes of my life. Evil or Very Mad

(Maybe someone else has other pitfalls to note?)

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 02 Jul 2008, 20:37
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 02 Jul 2008, 20:51
WinDef.h:
Code:
typedef unsigned short      WORD;
.
.
.
typedef WORD                ATOM;    


Considering that, why do you think it is a typo error from MSDN?
Post 02 Jul 2008, 20:51
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4037
Location: vpcmpistri
bitRAKE 02 Jul 2008, 21:03
Ignorantly, I didn't think of looking at the return type and assumed the return was in EAX. In this instance I wasn't using the return value. Ultimately, the error is with me because I just started adding API error checking to my code. Then I assumed it was working because of the error checking! Confused Guess it's slightly better than just assuming success on all API functions, lol.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 02 Jul 2008, 21:03
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 02 Jul 2008, 21:55
Quote:
Guess it's slightly better than just assuming success on all API functions, lol.

Congratulations Wink

Yeah, using C docs for Asm can sometimes cause problems like this. I probably wouldn't notice this one too :/
Post 02 Jul 2008, 21:55
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder 03 Jul 2008, 09:02
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:57; edited 1 time in total
Post 03 Jul 2008, 09:02
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4037
Location: vpcmpistri
bitRAKE 03 Jul 2008, 10:50
The upper word of EAX is not zero on my Windows when this API fails. Yet, the lower word is zero. YWMV (your windows may vary).

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 03 Jul 2008, 10:50
View user's profile Send private message Visit poster's website Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder 03 Jul 2008, 11:43
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:57; edited 1 time in total
Post 03 Jul 2008, 11:43
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 03 Jul 2008, 12:25
asmcoder: Don't type bullshit if you don't know. Functions that return WORD return in AX, and functions that return BYTE return in AL.
Post 03 Jul 2008, 12:25
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 03 Jul 2008, 12:55
asmcoder wrote:
what windows u have?
Irrelevant. Code properly or suffer breakage. Just because flawed code works on one windows version is no excuse to keep flawed code. (Not meant as an insult to bitRAKE, I'd probably have missed such a subtle thing for quite a while too).

_________________
Image - carpe noctem
Post 03 Jul 2008, 12:55
View user's profile Send private message Visit poster's website Reply with quote
rxantos



Joined: 19 Jul 2008
Posts: 41
rxantos 04 Aug 2008, 00:30
Thank you for pointing this out. Although this has not yet bite me, I will be more carefull when checking what a function returns.

Altough, a good design should have some consistence. Guess Windows is not a good example of a good design.
Post 04 Aug 2008, 00:30
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 04 Aug 2008, 12:45
The NT kernel is an example of decent design, the WIN32 API less so (largely because of it's WIN16 legacy). But keep in mind that the API was written with C programmers and not assembly programmers in mind - thus you don't get exact lists of what an API changes and what it doesn't, only the general "expect these registers to be modified, and you're guaranteed those registers aren't".

This also means that if only a byte or a word is returned, you should only look at that part of EAX, and consider the rest to be undefined. Use movsx/movzx if this is too horrible for you Razz
Post 04 Aug 2008, 12:45
View user's profile Send private message Visit poster's website Reply with quote
asmfan



Joined: 11 Aug 2006
Posts: 392
Location: Russian
asmfan 04 Aug 2008, 14:17
Also have you noticed that some Win builds treat BOOL as al (1 byte) other as eax (4 bytes)? As i remember i stumbled this.
Post 04 Aug 2008, 14:17
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.