flat assembler
Message board for the users of flat assembler.

Index > Windows > Calling DLL functions?

Author
Thread Post new topic Reply to topic
MickyD



Joined: 01 May 2008
Posts: 2
MickyD
Sorry if this has been asked before, but I'm pretty new to FASM, and I have searched but nothing seems to be what I'm after.

Basically, I have a ton of DLL's which I've wrote myself over the years, and have used them in another language to plug the holes, and a load of them I dont intend to rewrite.

So is it possible, say, if I had a DLL called "printer.dll" (Written in C++) and a function named "OpenPrinter()" which returns a boolean value depending if the file has been created or not... Something like:-

Code:
//Printer.DLL

//Globals
PRINTDLG pd;
DOCINFO di;
ULONG_PTR gdiToken;

#define MYDECL extern "C" _declspec(dllexport)
#define MYCALL _stdcall

MYDECL bool MYCALL _OpenPrinter(void)
{
   GdiplusStartupInput gdiplusStartupInput;
   GdiplusStartup(&gdiToken, &gdiplusStartupInput, NULL);

   
   ZeroMemory(&di, sizeof(di));
   di.cbSize = sizeof(di);
   di.lpszDocName = "New Doc";
   
   ZeroMemory(&pd, sizeof(pd));
   pd.lStructSize = sizeof(pd);
   pd.Flags = PD_RETURNDC;

   if(!PrintDlg(&pd))
   {
       return(false);
   }
    
       return(true);
}
    


After decoration, we'll have something like "_OpenPrinter@0" or along them lines... So the question is, how would I access this through FASM (In code)

Thanks for any help in advance!
Post 01 May 2008, 19:56
View user's profile Send private message Reply with quote
asmhack



Joined: 01 Feb 2008
Posts: 431
asmhack
Code:
format PE GUI 4.0
entry start

include 'win32a.inc'

section '.code' code readable executable

  start:
        call  [_OpenPrinter] ;call your function from the dll (no arguments)
        cmp eax,0 ;check the return value
       ;...
        invoke  ExitProcess,0

section '.idata' import data readable writeable

  library kernel32,'kernel32.dll',\
          printer,'printer.dll'

  import kernel32,\
         ExitProcess,'ExitProcess'

  import printer,\
         _OpenPrinter,'_OpenPrinter'      


hope this will help you
Post 02 May 2008, 02:00
View user's profile Send private message Reply with quote
MickyD



Joined: 01 May 2008
Posts: 2
MickyD
Thank you asmhack, really appreciated! Smile
Post 02 May 2008, 05:10
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.