flat assembler
Message board for the users of flat assembler.
Index
> Windows > Problem mit DLL und CONSOLE_SCREEN_BUFFER_INFO |
Author |
|
RedEagle 07 Oct 2005, 15:10
This is the new code:
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); proc _color color ;local csbi:CONSOLE_SCREEN_BUFFER_INFO ;local hout:HANDLE csbi CONSOLE_SCREEN_BUFFER_INFO hout dd ? ;HANDLE invoke GetStdHandle,STD_OUTPUT_HANDLE mov [hout],eax invoke GetConsoleScreenBufferInfo,[hout],[csbi] mov ax,[csbi.wAttributes] or ax,0xFF xor ax,0xFF or ax,WORD[color] mov [csbi.wAttributes],ax invoke SetConsoleTextAttribute,[hout],[csbi] ;invoke LocalFree 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 now, I can compile it, but how can I use it in my C/C++ programms?? I tryed it with "GetProcAddress" but it doesn't work: Code: #include <windows.h> #include <stdio.h> void Error(int point); int main() { HINSTANCE hdll = (HINSTANCE) LoadLibrary(TEXT(".\\fcf.dll")); if(hdll == NULL) Error(1); else { FARPROC fproc = (FARPROC) GetProcAddress(hdll, TEXT("color")); if(fproc == NULL) Error(2); } system("PAUSE"); return 0; } void Error(int point) { printf("Fehler an Punkt %i: %i\n",point,GetLastError); } I can load the DLL with LoadLibrary, but GetProcAddress returns NULL. GetLastError returs 4215440. But there exists no Error with this number. Last edited by RedEagle on 07 Oct 2005, 15:33; edited 1 time in total |
|||
07 Oct 2005, 15:10 |
|
decard 07 Oct 2005, 15:19
sorry, could you write in English?
|
|||
07 Oct 2005, 15:19 |
|
RedEagle 07 Oct 2005, 15:48
OK, now (I think) I can load the function:
Code: #include <windows.h> #include <stdio.h> void Error(int point); void (*color)(int); int main() { HINSTANCE hdll = (HINSTANCE) LoadLibrary(TEXT(".\\fcf.dll")); if(hdll == NULL) Error(1); else { color = (void(*)(int)) GetProcAddress(hdll, TEXT("_color")); if(color == NULL) Error(2); else { color(0xcf); //Here it crashes printf("IT WORKS!!"); } } system("PAUSE"); return 0; } But if I call the function, the programm crashes: DLL_TEST caused an error by an invalid page in module FCF.DLL at 01b7:00c7100f. (translated by Google) What's worng?? |
|||
07 Oct 2005, 15:48 |
|
james 08 Oct 2005, 00:03
Try looking at the dll example in fasm examples called DLL.
Modify this as it works. Add your function and slowly take away the other code. |
|||
08 Oct 2005, 00:03 |
|
RedEagle 08 Oct 2005, 07:07
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); proc _color hWnd,wcolor local 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] ret 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 I've taken the code of the Example DLL.... I've change some things, and now, I can load and use the function. BUT I get two Bluescreens AND it's another color, and not the color, I want. AND the system crashs after a few secounds |
|||
08 Oct 2005, 07:07 |
|
decard 08 Oct 2005, 07:24
What about calling convetion? Maybe your C code assumes that imported function is a C function?
|
|||
08 Oct 2005, 07:24 |
|
madmatt 08 Oct 2005, 09:12
try using the cproc macro to define a function in your dll.
|
|||
08 Oct 2005, 09:12 |
|
RedEagle 08 Oct 2005, 10:00
I don't find the cproc macro
Where can I download the *.inc - file?? |
|||
08 Oct 2005, 10:00 |
|
decard 08 Oct 2005, 13:04
in updated macro package proc syntax is different. Try:
Code: proc _color c, hWnd,wcolor |
|||
08 Oct 2005, 13:04 |
|
james 08 Oct 2005, 22:44
to test out if the bug is a calling convention issue, try using invoke and then try ccall.
also, you might try asking the same question in the masm forum as they concentrate on win32 more then this forum. |
|||
08 Oct 2005, 22:44 |
|
madmatt 09 Oct 2005, 09:54
RedEagle:
Your right, sorry about that, it's not in the latest release. but It WAS in an earlier release. Tomasz you need to return this macro define with the current release. Here is the macro, don't know if it will work though. Use like this: cproc function arg1, arg2, arg3 mov eax, [arg1] mov ecx, [arg2] mov edx, [arg3] cret 0 endp and to call it: cinvoke function, 1, 2, 3 Code: 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 \} } |
|||
09 Oct 2005, 09:54 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.