Hi
Ich hab in fasm eine dll geschrieben:
fcf.asm
fcf.inc
und mein Aufruf in C++
Mein Problem:
Die *.dll lässt sich Compilieren, und Laden. Wenn ich die Funktion aber aufrufe, stürtzt das Test-Programm ab:
DLL_TEST verursachte einen Fehler durch eine ngültige Seite in Modul FCF.DLL bei 01b7:00c7100f.
Der C - Code sollte richtig sein, da bei einem ähnlichen code, (den ich irgendwo gefunden habe) das selbe Problem auftritt.
Frage:
Was ist an dem fasm - Code falsch?? Hab schon im fasm-forum nachgefragt, aber da konnte man mir auch nicht wirklich helfen.
Ich hab in fasm eine dll geschrieben:
fcf.asm
Code:
format PE GUI 4.0 DLL
entry DllEntryPoint
include 'd:\fasm\include\win32a.inc'
include 'fcf.inc'
section '.code' code readable executable
proc DllEntryPoint hinstDLL,fdwReason,lpvReserved
mov eax,TRUE
ret
endp
;void color(WORD color);
cproc _color hWnd,wcolor
csbi CONSOLE_SCREEN_BUFFER_INFO
invoke GetConsoleScreenBufferInfo,[hWnd],[csbi]
lea ax,[csbi.wAttributes]
or ax,0xFF
xor ax,0xFF
or ax,WORD[wcolor]
mov [csbi.wAttributes],ax
invoke SetConsoleTextAttribute,[hWnd],[csbi]
invoke LocalFree,[csbi]
cret 0
endp
;---
section '.idata' import data readable writeable
library kernel,'KERNEL32.DLL',\
user,'USER32.DLL'
import kernel,\
GetStdHandle,'GetStdHandle',\
GetConsoleScreenBufferInfo,'GetConsoleScreenBufferInfo',\
SetConsoleTextAttribute,'SetConsoleTextAttribute',\
LocalFree,'LocalFree'
; import user,\
section '.edata' export data readable
export 'FCF.DLL',\
_color,'_color'
section '.reloc' fixups data discardable
fcf.inc
Code:
struct CONSOLE_SCREEN_BUFFER_INFO
dwSize dd ?
dwCursorPosition dd ?
wAttributes dw ?
srWindow dd ?
dwMaximumWindowSize dd ?
ends
macro cproc [params] ; define CDECL procedure
{ common
local args,size,current
match name arg, params
\{ if used name
name:
virtual at ebp+8
match =uses regs=,args, arg \\{ defargs@proc args
regs@proc equ regs \\}
match =,args, arg \\{ defargs@proc args \\}
match =args@proc, args@proc \{ defargs@proc arg \\}
args = $ - (ebp+8)
end virtual \}
match =args@proc, args@proc
\{ if used params
params:
args = 0
args@proc equ \}
match =regs@proc, regs@proc
\{ regs@proc equ \}
all@vars equ
current = 0
if args | size
push ebp
mov ebp,esp
if size
sub esp,size
end if
end if
match regs, regs@proc
\{ push regs
defpop@proc regs \}
match , regs@proc
\{ pop@proc equ \}
macro locals
\{ virtual at ebp-size+current
macro label . \\{ deflocal@proc .,:, \\}
struc db val \\{ deflocal@proc .,db,val \\}
struc dw val \\{ deflocal@proc .,dw,val \\}
struc dp val \\{ deflocal@proc .,dp,val \\}
struc dd val \\{ deflocal@proc .,dd,val \\}
struc dt val \\{ deflocal@proc .,dt,val \\}
struc dq val \\{ deflocal@proc .,dq,val \\}
struc rb cnt \\{ deflocal@proc .,rb cnt, \\}
struc rw cnt \\{ deflocal@proc .,rw cnt, \\}
struc rp cnt \\{ deflocal@proc .,rp cnt, \\}
struc rd cnt \\{ deflocal@proc .,rd cnt, \\}
struc rt cnt \\{ deflocal@proc .,rt cnt, \\}
struc rq cnt \\{ deflocal@proc .,rq cnt, \\} \}
macro endl
\{ purge label
restruc db,dw,dp,dd,dt,dq
restruc rb,rw,rp,rd,rt,rq
restruc byte,word,dword,pword,tword,qword
current = $-(ebp-size)
end virtual \}
macro cret retval
\{ pop@proc
if ~ retval eq
mov eax, retval
end if
if args | size
leave
end if
retn \}
macro finish@proc \{ size = (((current-1) shr 2)+1) shl 2
end if \}
}
und mein Aufruf in C++
Code:
#include <windows.h>
#include <stdio.h>
void Error(int point);
void (*color)(HWND,WORD);
int main()
{
HINSTANCE hdll = (HINSTANCE) LoadLibrary(TEXT(".\\fcf.DLL"));
if(hdll == NULL) Error(1);
else
{
color = (void(*)(HWND,WORD)) GetProcAddress(hdll, TEXT("_color"));
if(color == NULL) Error(2);
else
{
HWND hWnd = (HWND)GetStdHandle(STD_OUTPUT_HANDLE);
color(hWnd,0xcf);
printf("IT WORKS!!");
}
FreeLibrary(hdll);
}
system("PAUSE");
return 0;
}
void Error(int point)
{
printf("Fehler an Punkt %i: %i\n",point,GetLastError);
}
Mein Problem:
Die *.dll lässt sich Compilieren, und Laden. Wenn ich die Funktion aber aufrufe, stürtzt das Test-Programm ab:
DLL_TEST verursachte einen Fehler durch eine ngültige Seite in Modul FCF.DLL bei 01b7:00c7100f.
Der C - Code sollte richtig sein, da bei einem ähnlichen code, (den ich irgendwo gefunden habe) das selbe Problem auftritt.
Frage:
Was ist an dem fasm - Code falsch?? Hab schon im fasm-forum nachgefragt, aber da konnte man mir auch nicht wirklich helfen.