flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
typedef 11 Nov 2015, 21:58
Either statically or dynamically import. I'd chose the first one.
https://en.wikipedia.org/wiki/Dynamic-link_library#C Also, the thread function expects one parameter. |
|||
![]() |
|
revolution 11 Nov 2015, 23:27
You need to export your functions with the export macro.
The following is the example DLL in the fasm download. Notice the use of 'export': Code: ; DLL creation example format PE GUI 4.0 DLL entry DllEntryPoint include 'win32a.inc' section '.text' code readable executable proc DllEntryPoint hinstDLL,fdwReason,lpvReserved mov eax,TRUE ret endp ; VOID ShowErrorMessage(HWND hWnd,DWORD dwError); proc ShowErrorMessage hWnd,dwError local lpBuffer:DWORD lea eax,[lpBuffer] invoke FormatMessage,FORMAT_MESSAGE_ALLOCATE_BUFFER+FORMAT_MESSAGE_FROM_SYSTEM,0,[dwError],LANG_NEUTRAL,eax,0,0 invoke MessageBox,[hWnd],[lpBuffer],NULL,MB_ICONERROR+MB_OK invoke LocalFree,[lpBuffer] ret endp ; VOID ShowLastError(HWND hWnd); proc ShowLastError hWnd invoke GetLastError stdcall ShowErrorMessage,[hWnd],eax ret endp section '.idata' import data readable writeable library kernel,'KERNEL32.DLL',\ user,'USER32.DLL' import kernel,\ GetLastError,'GetLastError',\ SetLastError,'SetLastError',\ FormatMessage,'FormatMessageA',\ LocalFree,'LocalFree' import user,\ MessageBox,'MessageBoxA' section '.edata' export data readable export 'ERRORMSG.DLL',\ ShowErrorMessage,'ShowErrorMessage',\ ShowLastError,'ShowLastError' section '.reloc' fixups data readable discardable |
|||
![]() |
|
dromenox 12 Nov 2015, 11:24
Thank you! But you do not understand me:
I want to call C from FASM and not vice versa. |
|||
![]() |
|
revolution 12 Nov 2015, 11:34
There are two ways to call C functions.
If it is a DLL you call then use 'cinvoke'. This is when you use the import as one does with the WIndows DLLs. Exactly the same usage as wsprintf. If it is statically linked then use 'ccall'. This is where you use extrn and use a linker to make the exe file. |
|||
![]() |
|
dromenox 12 Nov 2015, 11:43
revolution wrote: There are two ways to call C functions. I want to do just the DllEntryPoint with FASM and the rest of the code in C. I need to link the .OBJ files? |
|||
![]() |
|
revolution 12 Nov 2015, 11:48
dromenox wrote: I want to do just the DllEntryPoint with FASM and the rest of the code in C. I need to link the .OBJ files? |
|||
![]() |
|
l_inc 12 Nov 2015, 11:48
dromenox
Yes, if you want both C and fasm to be compiled into a single dll. _________________ Faith is a superposition of knowledge and fallacy |
|||
![]() |
|
knell 12 Nov 2015, 16:57
I'm newbie about linker, dynamic/static library and such, so correct me if I'm wrong, did Dromenox want it like this?
Code: start: ... ... cinvoke printf, stringFormat, message ... ... section '.imports' import data readable library msvcrt, 'msvcrt' import msvcrt,\ printf, 'printf' .... As I know, to make a shared dll using gcc is simply done like this: Code: $ gcc -shared thecodes.c -o theout.dll And to use function that defined in theout.dll in fasm is simply done like example above. (Edit: corrected to use cinvoke) Last edited by knell on 12 Nov 2015, 22:32; edited 1 time in total |
|||
![]() |
|
AsmGuru62 12 Nov 2015, 17:58
I think you need cinvoke here.
|
|||
![]() |
|
knell 12 Nov 2015, 22:31
Thanks for correction. I was going to ask what the different between invoke and cinvoke, but found it in docs.
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.