flat assembler
Message board for the users of flat assembler.

Index > Windows > fasm object to use with C that uses dlls

Author
Thread Post new topic Reply to topic
Fungos Bauux



Joined: 19 Jan 2005
Posts: 31
Location: CWB
Fungos Bauux
I already searched forums and looked that sample on examples page. But I haven't found how to implement a object in fasm to use in C that uses some system dlls.

This is what I'm trying:
Code:
include 'win32a.inc'

format MS COFF
public  Init         as      '_Init@0'

section '.text' code readable executable
proc Init
     invoke     MessageBox, 0, [String], [String], 0
     ret
endp

section '.data' data readable writeable
String        db      'Message', 0

section '.idata' import data readable writeable
        library user, 'USER32.DLL'
        import user,\
               MessageBox, 'MessageBoxA'
    

I aways get: "Error: extra characters on line." at '.idata' section.
Any suggestion?
Post 12 Jun 2007, 00:23
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
The MS COFF format lacks of import section, you have to use the keyword "extrn" instead.

Here the example that comes with fasm package
Code:
; example of making Win32 COFF object file

format MS COFF

extrn '__imp__MessageBoxA@16' as MessageBox:dword

section '.text' code readable executable

 public _demo

 _demo:
        push    0
        push    _caption
        push    _message
        push    0
        call    [MessageBox]
        ret

section '.data' data readable writeable

 _caption db 'Win32 assembly',0
 _message db 'Coffee time!',0    
Post 12 Jun 2007, 01:09
View user's profile Send private message Reply with quote
Fungos Bauux



Joined: 19 Jan 2005
Posts: 31
Location: CWB
Fungos Bauux
Ok. Now i have this:

asm.asm (code taken from samples)
Code:
include 'win32a.inc'
format MS COFF

public  Test         as      '_Test'

extrn   '__imp__LoadLibraryA@4' as LoadLibrary:dword
extrn   '__imp__GetProcAddress@8' as GetProcAddress:dword
extrn   '__imp__MessageBoxA@16' as MessageBox:dword

section '.text' executable

proc Test c num1, num2
local loc1 dd ?
local loc2 dd ?
        mov     eax, [num1]
        add     eax, [num2]
        rcr     eax, 1
        ret
endp
    


test.cpp:
Code:

unsigned int Test(unsigned int, unsigned int);

int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{
       ...
       RunTest();
       ...
}

void RunTest()
{
   int i = Test(1, 1);
}

    


Compilation with dev-cpp/g++:
Code:
windres.exe -i test_private.rc --input-format=rc -o test_private.res -O coff 
g++.exe -D__DEBUG__ main.o test_private.res -o "test.exe" -L"lib" -mwindows asm.obj  -g3 -march=i686 

main.o(.text+0x16): In function `Z7RunTestv':
C:/Dev/main.cpp:27: undefined reference to `Test(unsigned int, unsigned int)'
collect2: ld returned 1 exit status
    


It looks like something is wrong on linking asm.o object with my cpp project. Anybody has some dev-cpp/g++ sample working?
Post 12 Jun 2007, 03:02
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
you should enclose declaration of "Test" in "extern C" block.

Something like this: (not sure about how is "__stdcall" used in gcc)
Code:
extern "C" {
  unsigned __stdcall int Test(unsigned int, unsigned int);
}    
Post 12 Jun 2007, 03:22
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Fungos Bauux



Joined: 19 Jan 2005
Posts: 31
Location: CWB
Fungos Bauux
This is what I'm doing: C++ <-> Fasm MS COFF .obj <-> external .DLL program.
But when Im compiling the C++, the linker says it cannot find dll exports. The C++ and DLL doesn't communicate directly. What I need to do to get this working?
Post 03 Jul 2007, 00:01
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Post complete command line and error message from compiler.

Maybe you have to create .lib file for the DLL?
Post 03 Jul 2007, 00:08
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Fungos Bauux



Joined: 19 Jan 2005
Posts: 31
Location: CWB
Fungos Bauux
Code:
g++.exe main.o -o "test.exe" -mwindows fasm.obj
fasm.obj(.text+0x12): undefined reference to `GFXDllCreateObject@12'
collect2: ld returned 1 exit status.
    


I'm using Dev-C++.
The DLL that I'm trying to use came with an application and I haven't any lib and even .h to use it.
Post 03 Jul 2007, 00:30
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
There are some tools that can spit out LIB from DLL file. I am pretty sure you can find them somewhere in MASM32, but i don't recall how it is called. Someone else may help.

meanwhile, you could browse MSDN about "__declspec(dllimport)", and about Module Definiton (.DEF) files
Post 03 Jul 2007, 00:40
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Fungos Bauux



Joined: 19 Jan 2005
Posts: 31
Location: CWB
Fungos Bauux
thanks. worked. dlltool from devcpp does the job.
Post 03 Jul 2007, 02:33
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
hologram



Joined: 26 Jun 2007
Posts: 4
hologram
How ? Im using devcpp and need to use a dll without any headers and libs
Post 06 Jul 2007, 16:53
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.