flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
Reverend 03 Apr 2005, 13:45
I'll use an example dll from fasm package. It exports ShowLastError, which gets one parameter, handle of window. So in your cpp file:
a) declare prototype: ('void' since the return value is meaningless for us in this case) Code: void STDCALL ShowLastError(HWND) b) change a dll file with a special tool, unfortuantely I don;t have it, but it was surely in MASM package and should be in vc++ package too. Should be named like 'dll2lib.exe' or somewhat like this c) add the created .lib file to linked libraries in options in vc++ d) use the function normally like: Code: MessageBox(hWnd,"Nice text","Nic text too",MB_OK); ShowLastError(hWnd); |
|||
![]() |
|
Giedrius 03 Apr 2005, 20:00
I've downloaded MASM32, because I haven't found the tool in VC++, and I can't find that tool neither in there
![]() _________________ Better to rule in hell, than to be a slave in heaven... |
|||
![]() |
|
Reverend 04 Apr 2005, 16:50
Shit, I made a mistake. Sorry for misleading you. There's no such tool (btw: I don't know why?). So the only solutions I see now is to compile the file as MS COFF (but it needs some changes in source file) or to write such a tool
![]() I guess you'll have to read much about .lib file before. I may start to write such a tool (as it sounds interesting and useful), but I have a lack of time, so I don;t think I'd be able to do it. There's also another soultion. There is a tool that creates static library out of .dll file. You wouldn't need then to import any function, all code will be pasted directly to executable file. Unfortunately it cost 300$ ![]() |
|||
![]() |
|
Giedrius 04 Apr 2005, 17:51
So there is no way (without those two) of making fasm and VC++ to be friends?
![]() |
|||
![]() |
|
r22 05 Apr 2005, 04:56
Why won't C++ let you use the LoadLibrary api and GetProcAddress ?
C++ had to try really really hard to make itself less useful. |
|||
![]() |
|
f0dder 05 Apr 2005, 07:47
Of course C++ lets you use LoadLibrary and GetProcAddress, but it's often more useful to have implicit linkage...
|
|||
![]() |
|
r22 06 Apr 2005, 00:25
I'm sorry I was being sarcastic.
It really is a problematic issue in c++, unless someone can come up with a converter that turns a fASM source file into something c++'s inline assembler can use or improve the inline assembly feature in c++ all together.. |
|||
![]() |
|
Giedrius 06 Apr 2005, 05:59
Visual C++ inline assembler is very simple and almost the same as fasm. You can just write:
int asdf; void function() { _asm { mov asdf,5 } //now asdf contains 5 } _________________ Better to rule in hell, than to be a slave in heaven... |
|||
![]() |
|
f0dder 06 Apr 2005, 07:43
I'm considering writing a little tool that will build import libraries from a .txt file containing DLL-name and a list of exports, which would let you easily build import libraries for FASM .dll's. It shouldn't be too hard a task, unfortunately I don't have much spare time at the moment :/
|
|||
![]() |
|
Reverend 06 Apr 2005, 12:54
f0dder wrote: I'm considering writing a little tool that will build import libraries from a .txt file containing DLL-name and a list of exports, which would let you easily build import libraries for FASM .dll's. Quote: It shouldn't be too hard a task, unfortunately I don't have much spare time at the moment :/ Btw. How to call a procedure in C++ using a pointer returned by GetProcAddress ? |
|||
![]() |
|
f0dder 06 Apr 2005, 13:28
Quote:
I'm planning that, too - initially I want to concentrate on building the import libraries, though... and parsing a .txt is less work than parsing a .dll ![]() Quote:
It's not too bad. Microsoft has it documented in the "pecoff" document - google for "pecoff site:msdn.microsoft.com". Quote:
You need some typecasting magic. This looks *extremely* ugly, and thus the best thing to do is adding some typedefs. Something like this: Code: #include <stdio.h> typedef int (*funcptr_t)(int,int,int); int myfunc(int a, int b, int c) { return a+b+c; } int main(void) { funcptr_t func = &myfunc; printf("func(10,20,30): %d\n", func(10,20,30)); return 0; } |
|||
![]() |
|
Vortex 06 Apr 2005, 17:45
Hi f0dder,
Pelle's librarian Polib is able to create import libraries from DLLs. These import libraries are just usefull to work with Fasm. Quote:
The zip file below contains an example for Fasm: http://vortex.masmcode.com/files/implib.zip _________________ Code it... That's all... |
|||
![]() |
|
f0dder 06 Apr 2005, 17:55
cute
![]() I'm still gonna do my tool anyway, as a nice excercise in multiple things. (PS: does polib do it directly, or does it depend on an assembler or similar lameness?) |
|||
![]() |
|
Vortex 06 Apr 2005, 19:52
f0dder wrote: cute No, Polib doesn't depend on an assembler: Code: polib /nound /out:kernel32.lib \windows\system32\kernel32.dll polib /nound /out:user32.lib \windows\system32\user32.dll polib /nound /out:gdi32.lib \windows\system32\gdi32.dll The nound option creates import libraries with no decoration. _________________ Code it... That's all... |
|||
![]() |
|
Vortex 06 Apr 2005, 20:00
Hi Giedrius,
Here is a simple example for you : An autotyping application Code: #define WIN32_LEAN_AND_MEAN #include <windows.h> BOOL APIENTRY DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved) { return TRUE; } void WINAPI Autotype(char* message) { HWND hWnd=FindWindowEx(FindWindow("Notepad",0),0,"Edit",0); while (*message) { SendMessage(hWnd,WM_CHAR,(WPARAM)*message,0); Sleep(200); ++message; } } Code: format PE GUI 4.0 entry start Include '%fasminc%\win32a.inc' Include '%fasminc%\macro\if.inc' section '.data' data readable writeable notepad db "Notepad.exe",0 msg db "Hello friends!",13,10,"This is an example of autotyping. :)",0 section '.text' code readable executable start: invoke WinExec,notepad,SW_SHOW invoke Autotype,msg invoke ExitProcess,0 section '.idata' import data readable writeable library kernel32,'kernel32.dll',\ small,'small.dll' import kernel32,\ ExitProcess,'ExitProcess',\ WinExec,'WinExec' import small,\ Autotype,'Autotype'
_________________ Code it... That's all... |
|||||||||||
![]() |
|
Giedrius 07 Apr 2005, 12:50
Thanks
![]() _________________ Better to rule in hell, than to be a slave in heaven... |
|||
![]() |
|
Vortex 07 Apr 2005, 18:55
Giedrius,
The critical problem to use Fasm DLLs with VC++ is to create import libraries for MS link.exe I coded a tool converting Masm include files to MS COFF import libraries. Quote:
Assume that your Fasm DLL exports these functions belows: Code: func1 takes one parameter func2 takes two paramaters func3 takes four parameters func4 has no parameters Creating the Masm include file is easy , dllname.inc func1 PROTO :DWORD ; one parameter func2 PROTO :DWORD,:DWORD ; two parameters func3 PROTO :DWORD,:DWORD,:DWORD,:DWORD func4 PROTO ; no any paramaters To get the import library: Code: inc2lib dllname.inc Include to library file converter V1.1 http://vortex.masmcode.com/files/i2l11.zip
_________________ Code it... That's all... |
|||||||||||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.