flat assembler
Message board for the users of flat assembler.
Index
> Windows > Using Assembly DLL files created with FASMW in c++ |
Author |
|
madmatt 13 Apr 2004, 00:22
How would you load and use a dll file created with FASMW in a c++ program? Has anyone tried this before?
|
|||
13 Apr 2004, 00:22 |
|
comrade 13 Apr 2004, 02:42
same way as you do with any other DLL
its all standard |
|||
13 Apr 2004, 02:42 |
|
madmatt 13 Apr 2004, 21:26
The reason I want to know is that I going full speed ahead with learning c++, and sometime in the future will purchase the Microsoft Visual C++ standard edition, but would still like to be able to use assembly when I need it. So I guess the better question would be, is it difficult to use an external assembly dll (made with FASMW) in c++?
|
|||
13 Apr 2004, 21:26 |
|
zenek_tm 13 Apr 2004, 21:35
Just to make it clear. In c/c++ to statically import from library you need a header file with imported function prototypes marked as imported and a lib file, which propably contains names and addresses of functions in this dll. The lib file can be generated using some utils. however I don't know any except one. Borland is, at least used to, distribute along with his c++ compilers such util since Borland lib is not compatible with MS lib file.
In Object Pascal compilers, such as Delphi, there is only one pas file. In this file in interface section there are function prototypes and in implementation section function prototypes are repeated and marked as external followed by information in which dll this function is. So Delphi evaluates the addresses of dll functions during compilation time. At least I think so. So if You want to use a dll in c++ app either use dynamic linking or somehow generate the lib file. In Delphi it's far more easier |
|||
13 Apr 2004, 21:35 |
|
f0dder 13 Apr 2004, 21:54
No, it's not difficult at all - you just need to know a few things about the tools you use
For instance, with C/C++, you need some function prototypes. It's a good idea to put these in a .h file, and if you want to be able to use your asm funcs from both C and C++, it will look something like this: Code: #ifdef __cplusplus extern "C" { #endif // prototypes go here #ifdef __cplusplus } #endif This part is generic for all compilers. Next, the prototypes themselves. If you just do a normal "void asmfoobar(void);", it will be C calling convention, and most compilers will expect the decorated name of the function to be "_asmfoobar". The STDCALL convention is imho a bit nicer, but it waries a bit from compiler to compiler how to add it. "void __stdcall asmfoobar(void);" in Visual C++, for instance. Compiler specifics can usually be handled by some preprocessor stuff, like "#define STDCALL __stdcall", then you use STDCALL instead of __stdcall, and only need to change the definition at the top of your header file. However, STDCALL calling convention also changes the name decoration rules. VC++'s name decoration rule for STDCALL is to prefix the name with an underscore, and append '@' + the bytesize of the arguments. Thus, void asmfoobar(void) would be _asmfoobar@0 . Okay, libraries. Make fasm (or another assembler, if you so choose) output to MS COFF format. Doing a static library is easy - you just add all your .obj files to a .lib with the use of a librarian (for vc++ it's lib.exe, which is really just a wrapper around link.exe). For DLL's it requires a bit more, like writing a .def file. It's been a while since I've messed with DLLs, so I can't remember that stuff off top of my head, but iirc it's as simple as: Code:
LIBRARY mydll
EXPORTS
myfunc1
myfunc2=_RenamedFromThis
et cetera. It should be easy to google up some more information if nobody else has anything to add. Oh, I think there was some utility to directly generate import libraries from a dll without the use of any intermediate tools or whatever... perhaps it was alib from the alink package? (google). |
|||
13 Apr 2004, 21:54 |
|
madmatt 14 Apr 2004, 08:06
looks a bit more involved than what I thought. I knew you needed a header file, but didn't know you had to generate a library for the dll file. Looks like i'll have to wait to get the VC++ compiler so I can inline the assembly code.
|
|||
14 Apr 2004, 08:06 |
|
coconut 14 Apr 2004, 10:29
the masm32 package from http://www.masm32.com has a few utils which can help you generate .lib files. check out their boards at http://www.masmforum.com the author of one of those tools posts regularly there and can help ya out
|
|||
14 Apr 2004, 10:29 |
|
f0dder 14 Apr 2004, 15:30
madmatt, it's not bad once you get used to it, and a lot of it can be automated
|
|||
14 Apr 2004, 15:30 |
|
madmatt 14 Apr 2004, 21:48
I do have the Masm package, along with the Fasm and free borland 5.5 package. I guess this is one of those things that once you get past the blood, sweat, and tears, in the end you'll be grateful that you learned this, much like working on your car or truck! (just changed the starter on my truck, and it went more smoothly than I ever thought it would! I like it when things work out that way!! ) Ok, thanks guys (gals?) for your help, I'll look into this further. Two more questions, Which would be better to learn first, how to link in an object file (.obj) or how to use a dll? and can fasm create an obj. file?
|
|||
14 Apr 2004, 21:48 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.