delphi - what happens if you call dll explicit, without declaring in the procedure call its stdcall; -
testing this code:
procedure fii(i:integer); var hbar: thandle; foo: procedure (x: integer); //i removed stdcall here! begin hbar := loadlibrary('bar.dll'); if hbar >= 32 { success } begin foo := getprocaddress(hbar, 'foo'); ... foo(i); // if debug trace call of dll not desired value ... freelibrary(hbar); end else messagedlg('error: not find bar.dll', mterror, [mbok], 0) end.
what happen if dropped stdcall
in 32 bit or 64 bit ?
the answer , value $18f2dc
passed x
. if string, point position of $18f2dc
,and try extract string garbage there. happens because delphi pass pointer(s)
in code. changed run run , not $18f2dc
, 3 byte passed. (if pass int $18f2dc
in decimal 1635036).
does number has unique meaning? why stdcall
needed?
what happen if dropped stdcall in 32 bit?
when no calling convention specified, default of register
used. since not match true calling convention, garbage passed in parameters.
in particular case, function call expects parameters passed on stack. function therefore read integer stack. on other hand, calling code assumes register
calling convention , puts argument in eax
register. because calling code did not push argument onto stack, function gets happens on stack when function called.
to honest, there's not point in trying reasons abi(application binary interface - interface between 2 program modules) mismatches this. try reason happen if declared different number of arguments on each side of interop(interoperability - property of product or system, interfaces understood, work other products or systems) boundary, , that's little different using wrong calling convention. binary interop have make sure matching: argument types, return value types, function names, calling convention, values passed function, etc.
what happen if dropped stdcall in 64 bit?
there single calling convention windows x64 platform. calling convention directives ignored compiler.
although 64 bit compiler ignores these directives still practise include them. way code work when compile 32 bit.
Comments
Post a Comment