flat assembler
Message board for the users of flat assembler.
Index
> Windows > Question about DLL linking... (newbie ;)) |
Author |
|
decard 13 Sep 2004, 14:54
Hi denial,
In PEDLL import section is just simply built manually. You simply don't need to understand what are those zeroes Try this example: Code: format PE DLL entry DLLEntryPoint include "%fasminc%/win32a.inc" ; data section section '.data' data readable writeable szTitle db "DLL example", 0 szText db "Hello form DLL!", 0 ; code section section '.code' code readable executable proc DLLEntryPoint, hinstDLL,fdwReason,lpvReserved enter mov eax,1 return endp proc Hello enter invoke MessageBox, HWND_DESKTOP,szText,szTitle,MB_OK+MB_ICONINFORMATION return endp ; imports section '.idata' import data readable library user32,"USER32.DLL" import user32,\ MessageBox,"MessageBoxA" ; exports section '.edata' export data readable export "SIMPLEDLL.DLL",\ Hello,"Hello" ; fixup section - needed in DLL section '.reloc' fixups data discardable |
|||
13 Sep 2004, 14:54 |
|
denial 13 Sep 2004, 15:10
Thank you for your answer,
but if I'm not confused about your example now, I think you got me wrong This is an example how to write a DLL in FASM isn't it? What I need is more information about use a DLL in FASM written in another language, Visual C++ for example. Maybe you or somebody help can help me? |
|||
13 Sep 2004, 15:10 |
|
JohnFound 13 Sep 2004, 15:20
You can import functions from any dll, exactly the way you do it for Windows system dll's (user32.dll for example). You have to create import section (or "data import..." block in any other section and write there the libraryes and functions you want to import. See the syntax of "library" and "import" macroses (include/macro/import.inc file), they are pretty clear (IMHO).
Don't be afraid to import all functions from the DLL in one block (better create one big .inc file for the whole DLL) - FASM will include in import data only the functions you use in your program. See for example the include files for Windows system dll's: include/apia/user32.inc Regards. P.S. Of course you can load dll's dynamicaly using Windows API functions: LoadLibrary, LoadLibraryEx, GetProcAddress, FreeLibrary. Read Win32 API guide for details. |
|||
13 Sep 2004, 15:20 |
|
denial 13 Sep 2004, 16:21
Thank you
Could you explain the parameters for these two macros (import, library)? macro library [name,string] name is of course the file, but what is string? macro import name,[label,string] name is here the name of the function... What is label and string for? Thank you again |
|||
13 Sep 2004, 16:21 |
|
decard 13 Sep 2004, 16:33
see an example:
Code: library kernel32,"KERNEL32.DLL" name (kernel32) is just some name (that will be used with import macro) and "string" is actual DLL file name. Code: import kernel32,\ ExitProcess,"ExitProcess" with import macro we specify which functions to load from a DLL. In this case we import ExitProcess from kernel32.dll. "name" is the same name that you specified as first parameter of library macro. Then "label" is a name that you will refer to when calling given function; and finally "string" is a function name in a DLL. Hope my description was clear enough |
|||
13 Sep 2004, 16:33 |
|
JohnFound 13 Sep 2004, 17:34
Code: ; In you import section ; Also, you can specify more than one library: library library1, 'mylib1.dll', library2, 'yourlib2.dll' ;... or better (more readable): library library1, 'mylib1.dll', \ library2, 'yourlib2.dll' ;...and more that one function per "import" statement... import library1, \ Function1, 'SomeFunctionName', \ Function2, 'SomeOtherFunction', \ TheBestFunc, 'SlowCPPFunc' ; Note - it is not obligatory to use the same names for functions as they are defined in the dll. ; In your code section ; call these functions this way: invoke Function1, arg1, arg2 ; macro "invoke" ; or: stdcall [Function2], arg1, arg2 ; macro "stdcall" with indirect addressing. ; or even: push arg2 push arg1 call [TheBestFunc] ; instruction "call" Regards |
|||
13 Sep 2004, 17:34 |
|
denial 13 Sep 2004, 17:43
Thank you very, very much for your help... Now I understood everything.
It's a great bord here - the support is fast and friendly. Regards denial |
|||
13 Sep 2004, 17:43 |
|
denial 13 Sep 2004, 18:38
Oh I got one more problem I posted but I solved it myself now. Thank you.
|
|||
13 Sep 2004, 18:38 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.