flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
revolution 17 Apr 2013, 23:57
What is the naming convention for "C" DLLs. Do they use a leading underscore and/or a trailing parameter size?
Something like: _Start@0 BTW: fasm does not generate any of the proprietary lib formats. |
|||
![]() |
|
HaHaAnonymous 18 Apr 2013, 00:00
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 21:02; edited 1 time in total |
|||
![]() |
|
fredlllll 18 Apr 2013, 00:00
a C export just gives me the name of the function. no param list or size.
but this doesnt matter now, because visual studio just ignores my .dll so this is the problem now |
|||
![]() |
|
HaHaAnonymous 18 Apr 2013, 00:04
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 21:02; edited 2 times in total |
|||
![]() |
|
revolution 18 Apr 2013, 00:06
You will need to import a DLL, not a lib file. Perhaps the VS documentation will give you the answer?
|
|||
![]() |
|
fredlllll 18 Apr 2013, 00:24
@HaHaAnonymous: yeah i think that vs is the problem, but i want to know why??
and yes you are right... added a "retn" =) @revolution VS documentation doesnt give me much =/ it seems that i just have to recreate the dll in vs, generate an import lib file and use this file (yeah that should work, but i wanted to avoid that way) |
|||
![]() |
|
HaHaAnonymous 18 Apr 2013, 01:03
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 21:01; edited 1 time in total |
|||
![]() |
|
Walter 18 Apr 2013, 05:07
Something that I tried. Maybe works here.
Create your dll with fasm. Code: format PE GUI 4.0 DLL entry DllMain include 'win32a.inc' section '.code' code readable executable proc DllMain, hinstDll, fdwReason, lpvReserved mov eax, TRUE ret endp proc Ret42 mov eax, 42 ret endp section '.edata' export data readable export 'test.dll',\ Ret42, 'Ret42' section '.reloc' data readable discardable data fixups end data dd ? Note that this has an entry point and relocs. I think the dll example that comes with fasm is incomplete since the bug for relocs was fixed. Maybe someone that is smart around here can confirm this. Create a def file. test.def Code:
LIBRARY test
EXPORTS
"_Ret42@0"
Get def2lib tool. Run: def2lib test.def Write a C source with project that uses this new lib. Code: #include <stdio.h> int __declspec(dllimport) __stdcall Ret42(void); int main(int argc, char *argv[]) { printf("Answer: %i.\n", Ret42()); return 0; } Works for me. Maybe for you? |
|||
![]() |
|
fredlllll 18 Apr 2013, 08:37
okay i did following:
make a new project containing and exporting the same functions as the asm exports. then building this, which generates a test.lib. then link to this using #pragma comment(lib,"test.lib") and later replacing that mockup dll with the real dll from flatassembler. i had to take that reloc part into my code. didnt run without it. but it doesnt need an entry point to work. asm: Code: format PE GUI 4.0 DLL include 'win32a.inc' section '.text' code readable executable start: mov eax,2 retn section '.edata' export data readable export 'test.DLL',\ start,'Start' section '.reloc' data readable discardable data fixups end data dd ? c-header: Code: #define DllImport __declspec( dllimport ) //test.lib = lib generated with the mockup project #pragma comment(lib, "test.lib") extern "C"{ //extern C so we dont have to mangle the name in flat assembler. DllImport int Start(); } and now replace the mockup dll with the assembler one and yay it works thanks for your help |
|||
![]() |
|
revolution 18 Apr 2013, 08:46
fredlllll wrote: ... but it doesnt need an entry point to work. |
|||
![]() |
|
fredlllll 18 Apr 2013, 09:22
why doesnt it restore the stack properly??
|
|||
![]() |
|
revolution 18 Apr 2013, 09:28
Windows calls the entry point ("start" in your case) with three parameters pushed into the stack. Since Windows uses sdtcall convention it is the called function that is supposed to pop those parameters off the stack during return. Hence the requirement for retn 12.
Also note that declaring your functions as "C" in VS will mean that your must write those functions to use the ccall convention. So your entry point function, called by Windows, must be stdcall compliant. And the exported functions, called by the VS code, must be ccall compliant. In the code above your "start" function gets called both by Windows and by the VS code and each caller expects a different calling convention. |
|||
![]() |
|
fredlllll 18 Apr 2013, 09:32
ohh okay.
popping 3 elements from stack, got it and retn increments the stack pointer by 12? and what are the 3 things pushed to the stack by windows (im new to x86 asm) |
|||
![]() |
|
typedef 18 Apr 2013, 10:41
fredlllll wrote: ohh okay. Hello. Welcome, read this and learn some more !! http://stackoverflow.com/questions/3699283/what-is-stack-frame-in-assembly http://en.wikibooks.org/wiki/X86_Disassembly/Functions_and_Stack_Frames |
|||
![]() |
|
revolution 18 Apr 2013, 10:57
fredlllll wrote: and what are the 3 things pushed to the stack by windows (im new to x86 asm) Walter wrote:
|
|||
![]() |
|
fredlllll 18 Apr 2013, 11:32
okay thx. now i know how the calling works
revolution wrote:
but this doesnt tell me anything ![]() /edit: oops http://msdn.microsoft.com/en-us/library/windows/desktop/ms682583(v=vs.85).aspx that explains that thx |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.