WinAPI in Assembler

Fragen zu allen anderen Programmiersprachen.
traumatic
Beiträge: 478
Registriert: 27.11.2004 15:42

Beitrag von traumatic »

AndyX hat geschrieben:Darf man jetzt nicht mal mehr aus Spaß irgendwas witziges proggen? :roll:
Klar darfst Du. Und selbst wenn nicht: Wer bin ich, Dir etwas verbieten zu können!? ;)
Benutzeravatar
Danilo
-= Anfänger =-
Beiträge: 2284
Registriert: 29.08.2004 03:07

Beitrag von Danilo »

AndyX hat geschrieben:
polink.exe hat geschrieben:POLINK: error: Unresolved external symbol '_Beep'.
POLINK: error: Unresolved external symbol '_AllocConsole'.
usw...
Hm ich glaube die wolln mich verarschen. :mrgreen: :|
Wie kommst Du denn darauf das es "_Beep" ist, und nicht
zum Beispiel "__Beep__"? Denkst Du Dir das selbst aus?

Mein "Calling Conventions.txt" mit ein paar Infos aus MSDN usw.:

Code: Alles auswählen

Calling Conventions used by VC++ (version 6):

All arguments are widened to 32 bits when they are passed.
Return values are also widened to 32 bits and returned in
the EAX register, except for 8-byte structures, which are
returned in the EDX:EAX register pair.
Larger structures are returned in the EAX register as
pointers to hidden return structures.
Parameters are pushed onto the stack from right to left.

If you are writing assembly routines for the floating point
coprocessor, you must preserve the floating point control word
and clean the coprocessor stack unless you are returning a
float or double value (which your function should return in ST(0)).

The compiler (VC++) generates prolog and epilog code to
save and restore the ESI, EDI, EBX, and EBP registers, if
they are used in the function.



__cdecl

   Argument-passing order:              Right to left
   Stack-maintenance responsibility:    Calling function pops the arguments
                                        from the stack
   Name-decoration convention:          Underscore character (_) is prefixed to names
   Case-translation convention:         No case translation performed



__stdcall

   The __stdcall calling convention is used to call Win32 API functions.

   Argument-passing order:              Right to left.
   Argument-passing convention:         By value, unless a pointer or reference
                                        type is passed.
   Stack-maintenance responsibility:    Called function pops its own arguments
                                        from the stack.
   Name-decoration convention:          An underscore (_) is prefixed to the name.
                                        The name is followed by the 'at' sign (@)
                                        followed by the number of bytes (in decimal)
                                        in the argument list.
                                        Therefore, the function declared as
                                        int func( int a, double b )
                                        is decorated as follows: _func@12
   Case-translation convention:         None



__fastcall

   Argument-passing order:              The first two DWORD or smaller arguments
                                        are passed in ECX and EDX registers;
                                        all other arguments are passed right to left.
   Stack-maintenance responsibility:    Called function pops the arguments
                                        from the stack.
   Name-decoration convention:          At sign (@) is prefixed to names;
                                        an at sign followed by the number of bytes
                                        (in decimal) in the parameter list is
                                        suffixed to names.
   Case-translation convention:         No case translation performed.

   Note: Future compiler versions may use different registers to store parameters.



thiscall (not a keyword)

   This is the default calling convention used by C++ member functions that
   do not use variable arguments.
   The callee cleans the stack, so the compiler makes vararg functions __cdecl,
   and pushes the this pointer on the stack last.
   The thiscall calling convention cannot be explicitly specified in a program,
   because thiscall is not a keyword.

   All function arguments are pushed on the stack.
   
   Because this calling convention applies only to C++, there is no C name
   decoration scheme.



The __pascal, __fortran, and __syscall calling conventions are
no longer supported.

You can emulate their functionality by using one of the supported
calling conventions and appropriate linker options.

WINDOWS.H now supports the WINAPI macro, which translates to the
appropriate calling convention for the target.
Use WINAPI where you previously used PASCAL or __far __pascal.



For DLLs:

  Floats, Doubles and Quads are completely pushed on *CPU* stack.
 
  Floats and Doubles are returned in ST0, like always.
  Quads are returned in EDX:EAX like always.
Da WinAPI __stdcall verwendet, solltest Du Dir jetzt mal
den Abschnitt "Name-decoration convention" davon
anschauen.

Bei Masm32 sind auch ein paar Hilfedateien dabei die Du
sicher gebrauchen kannst.
Zum Beispiel welche Register bei WinAPI-Funktionen gesichert
werden etc...
cya,
...Danilo
"Ein Genie besteht zu 10% aus Inspiration und zu 90% aus Transpiration" - Max Planck
Benutzeravatar
AndyX
Beiträge: 1272
Registriert: 17.12.2004 20:10
Wohnort: Niederösterreich
Kontaktdaten:

Beitrag von AndyX »

Ne das Problem mit den Funktionen hat sich jetzt erledigt.

Greetz
Benutzeravatar
Danilo
-= Anfänger =-
Beiträge: 2284
Registriert: 29.08.2004 03:07

Beitrag von Danilo »

AndyX hat geschrieben:Ne das Problem mit den Funktionen hat sich jetzt erledigt.
OK, dann möchte ich mich hiermit für meinen Beitrag entschuldigen.

Du machst das schon, Meister! :allright:
cya,
...Danilo
"Ein Genie besteht zu 10% aus Inspiration und zu 90% aus Transpiration" - Max Planck
Benutzeravatar
remi_meier
Beiträge: 1078
Registriert: 29.08.2004 20:11
Wohnort: Schweiz

Beitrag von remi_meier »

Lass sonst halt mal den Linker weg...
Ändere "format MS COFF" in z.B. "format PE console" und dann kann dir
Fasm ne Exe liefern...
Benutzeravatar
AndyX
Beiträge: 1272
Registriert: 17.12.2004 20:10
Wohnort: Niederösterreich
Kontaktdaten:

Beitrag von AndyX »

PE console da wär ich auch nich draufgekommen :allright: THX probier ich gleich <)

EDIT: @Danilo:

Das _Beep stand im AsmOutput. Hab das nämlich ausprobiert, standn _ davor. Dasselbe bei Sleep und AllocConsole usw. Es fehlte halt dann nur noch das "@nummer" also die Stackreservierung, also ich mein wieviel Bytes Stack reserviert werden sollen.

Greetz,
AndyX
Benutzeravatar
AndyX
Beiträge: 1272
Registriert: 17.12.2004 20:10
Wohnort: Niederösterreich
Kontaktdaten:

Beitrag von AndyX »

Ne Moment mal FASM gibt doch nur Object Files zurück, also kann der doch keine EXE erstellen. :? Ne ich mach das lieber übern Linker.

Greetz
Benutzeravatar
remi_meier
Beiträge: 1078
Registriert: 29.08.2004 20:11
Wohnort: Schweiz

Beitrag von remi_meier »

Wenn du meinst /:->
traumatic
Beiträge: 478
Registriert: 27.11.2004 15:42

Beitrag von traumatic »

Nein nein, FASM kann keine PEs erzeugen...
...wäre ja ganz was neues...
http://flatassembler.net/docs.php?article=manual
Benutzeravatar
Danilo
-= Anfänger =-
Beiträge: 2284
Registriert: 29.08.2004 03:07

Beitrag von Danilo »

AndyX hat geschrieben:Es fehlte halt dann nur noch das "@nummer" also die Stackreservierung,
also ich mein wieviel Bytes Stack reserviert werden sollen.
Die Nummer gibt an wie groß die Argumente alle zusammen sind.
Mit Stackreservierung hat das nichts zu tun, d.h. es wird dadurch
kein Stack reserviert. Die Funktion kann auch nicht auf diese Zahl
zugreifen, da es nur ein Name ist der zur Laufzeit nicht direkt
bekannt ist.

Du könntest in Deinem Compiler damit, zumindest eingeschränkt,
Funktionen überladen:

Code: Alles auswählen

Procedure Error(message$)
  MessageBox_(0,message$,"ERROR",#MB_ICONERROR)
Endprocedure

Procedure Error(title$,message$)
  MessageBox_(0,message$,title$,#MB_ICONERROR)
Endprocedure
Dein Compiler generiert nun 2 Funktionen:

Code: Alles auswählen

_Error@4
_Error@8
Das ist aber nur sehr eingeschränkt möglich, weshalb sich das
nicht durchgesetzt hat:

Code: Alles auswählen

Procedure xyz(x.l, y.d)      ; long, double
Procedure xyz(x.l, y.l, z.l) ; long, long, long
Hier hättest Du z.B. 2 mal '@12', was zum Konflikt führt.
cya,
...Danilo
"Ein Genie besteht zu 10% aus Inspiration und zu 90% aus Transpiration" - Max Planck
Antworten