flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > DLLs

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
I'm new to assembly (and am still reading about it) so i really don't have this knowledge. Essentually, i wanna use C++ to make an emulator like environment to learn in. I know, there are output and stuff that i could use but i wanna restrict the asm code to as much of the basics as i can without those includes which are included with the assembler (so i don't become dependent on them) so i'm asking if anyone can give me an inc file or something so i can make my examples into C++ DLLs to be called. Also does anyone know how to make the LIB for it?

I know my intentions seem unusual to you, and you may be tempted to flame or such, but in reality i'm completely new to assembly and would like to learn assembly and get output to the screen via an outside application that collects data from what C++ would use as a global variable or a C++ish return statement. That way i can experiment with the output and have a file to display the output.

Thanks in advance.
Post 22 Jul 2006, 00:12
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend
Analyze the PEDEMO example program which is included with fasm's package. There you have shown how to call functions from dlls without any includes
Post 22 Jul 2006, 12:53
View user's profile Send private message Visit poster's website Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
Quote:
F:\testinggrounds\ASM>fasm test.asm
flat assembler version 1.67.6 (186882 kilobytes memory)
test.asm [12]:
library printf 'printf.dll'
INCLUDE/macro/import32.inc [7] library [2]:
if defined name#.redundant
error: extra characters on line.



THE EXE:

Code:
format PE GUI 4.0
entry start

section '.code' code readable executable

        invoke printint, 2

section '.idata' import data readable writeable

library printf 'printf.dll'

import printf,\
        printint,'printint'    


THE DLL:

Code:
#include <cstdio>

__declspec(dllexport) void printstring(char *string){
        printf("%s", string);
        return; }

__declspec(dllexport) void printint(int *inter){
        printf("%i", inter);
        return; }    


I can't tell if it's the DLL, or if i didn't write the include commands correctly... Have an idea? lol
Post 22 Jul 2006, 17:47
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
donkey7



Joined: 31 Jan 2005
Posts: 127
Location: Poland, Malopolska
donkey7
Code:
library printf 'printf.dll'
    

maybe
Code:
library printf,'printf.dll'
    

Smile
Post 22 Jul 2006, 18:19
View user's profile Send private message Visit poster's website Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
*smacks his own head off the wall*

Why coudln't i see that? XD i guess it's my fault for not using copy and paste. lol Now it's saying
Quote:
F:\testinggrounds\ASM>fasm test.asm
flat assembler version 1.67.6 (143812 kilobytes memory)
test.asm [2]:
entry start
error: undefined symbol.


O.o i don't see anything before entry start in the example codes that i don't have in my code... I take it out and it assembles fine... But now i get the following error from windows...

Quote:
The procedure entry point printint could not be located in the dynamic link library printf.dll.
Post 22 Jul 2006, 20:00
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
donkey7



Joined: 31 Jan 2005
Posts: 127
Location: Poland, Malopolska
donkey7
obviously, you must define an entrypoint Smile

usually entry point is located at the beginning of code section. your code may look like that:
Code:
format PE GUI 4.0 
entry start 

section '.code' code readable executable 

       start:
        invoke printint, 2 

section '.idata' import data readable writeable 

library printf 'printf.dll' 

import printf,\ 
        printint,'printint'
    


entry point is a place (label) where your code starts executing. maybe you've learned 16- bit .com files before, where executing starts from beginning by default Smile
Post 22 Jul 2006, 20:46
View user's profile Send private message Visit poster's website Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
F:\testinggrounds\ASM>HELLO.ASM
flat assembler version 1.67.6 (155154 kilobytes memory)
F:\testinggrounds\ASM\HELLO.ASM [7]:
invoke printint, 2
error: illegal instruction.


It said it couldn't find the entry point in the DLL. That's the problem... So i add start, then the assembler gives me the error also. What exaclty does start do, though? Since if you include many DLLs then it naturally woudln't be able to tell the difference, right? You dont' even need "start" to make a program so it can't be the C++ equivalent to main........ or is it? Not all the examples have it. I've acutally only ever used C++, PHP, ms's fake bat, and HTML, and a little java script till now. The function i'm calling is comming from "printf.dll". This is the main application, here. The problem is that the DLL is in C++.
Post 23 Jul 2006, 01:57
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
If you using the fasmw macros, you'll have to include them with:
include "win32a.inc", then invoke should work as expected.
Post 23 Jul 2006, 04:52
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
Code:
format PE GUI 4.0  
entry start  

include 'INCLUDE/win32a.inc'

section '.code' code readable executable  

       start: 
        invoke printint, 2  

section '.idata' import data readable writeable 

library printf, 'printf.dll'  

import printf,\  
        printint,'printint'    


The no entry point error, again... Like i said, i don't need the start for the examples for the exe files (in the non DLL ones) so i'm guessing it's for the DLL file, but the problem is i'm using the exe to call a function from the DLL (since that's what it's turned into, though the original plan made a DLL in ASM to call from C++, but this would work too). Basically, i'm guessing i need to specify something else to call functions from C++ DLLs, or the problem itself lies within the DLL, but if that was the case it woudln't have compiled, right? Like i said, i still have no asm knowledge, i'm trying to set this up so i can have console interger (32 bit to be exact) and char (or unicode wchar_t) array output.

Yes, i am well aware that my DLL's int function takes a pointer parameter, but i'm sure it would cause a different error (and i'll correct that error later).
Post 23 Jul 2006, 05:56
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
donkey7



Joined: 31 Jan 2005
Posts: 127
Location: Poland, Malopolska
donkey7
well, this code compiles ok for me. Confused
i've used fasmw editor with fasm 1.67.6 engine inside Smile

btw: you forgot to return to the system. place ret or invoke exitprocess,0 at the end of code.

you don't need entry point? so what, code should start executing from random address?

look at examples/dll.
Post 23 Jul 2006, 09:27
View user's profile Send private message Visit poster's website Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
the non DLL example exe files don't need the start, and the error didn't come from the missing start of the exe, but the missing start of the DLL... And the posting of the last code example i used compiled, the "The procedure entry point printint could not be located in the dynamic link library printf.dll." is from windows itself. It's not the assembler. It's the big box i get during runtime.
Post 23 Jul 2006, 14:10
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
donkey7



Joined: 31 Jan 2005
Posts: 127
Location: Poland, Malopolska
donkey7
*all exes and dlls always* needs entry point. in c++ entry point is computed automatically. in exes it's function main, in dlls function dllentrypoint is generated automatically. dll entry point is used to synchronize between diffferent threads of same library and to help with initialization of variables.

it seems that there is problem with function. precisely, i guess that procedure printint doesn't exist in printf.dll (or has different name, like _pintint - hll compilers often mangles names). or dll hasn't entry point, but it's less probable because c++ compiler should care about it.

maybe put this dll here?
Post 23 Jul 2006, 18:11
View user's profile Send private message Visit poster's website Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
Well, simply... It there must be different names for C++ functions... like somethign appended to front and/or end, and basically i need to know what is....
Post 23 Jul 2006, 19:27
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
missed the "return" error in my last post, thanks donkey7. Anyways, to call an assembly dll procedure from C or C++, you need to define the assembly procedure(s) in this way

proc FunctionName c arg1, arg2, arg3
.......code.......
endp

the c after the "FunctionName" makes the function compatible with the C/C++ calling convention. I've never tried to call an assembly dll from C or C++, I'd be interested to see how to make this work. Smile
Post 23 Jul 2006, 23:46
View user's profile Send private message Reply with quote
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi
AFAIK, usually C/C++ compilers allow you to declare a external function to use different calling convention.
Post 24 Jul 2006, 00:16
View user's profile Send private message MSN Messenger Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
madmatt wrote:
missed the "return" error in my last post, thanks donkey7. Anyways, to call an assembly dll procedure from C or C++, you need to define the assembly procedure(s) in this way

proc FunctionName c arg1, arg2, arg3
.......code.......
endp

the c after the "FunctionName" makes the function compatible with the C/C++ calling convention. I've never tried to call an assembly dll from C or C++, I'd be interested to see how to make this work. Smile


Well it seems that everyone tryign to assist me here have 2 different agendas. providing me with a DLL to call from C++, or calling a C++ DLL from assembly... o.O and i'm getting the 2 mixed up. lol

I'm trying to fiutre ouy what you're sayin, though... Is that how i'll declare a function in assembly to be called in C++? Then the question then turns to "how do i code the 'return' part?"

Quote:
AFAIK, usually C/C++ compilers allow you to declare a external function to use different calling convention.


You mean "exturn"? I tried that once with
Code:
exturn "C"    


C code didn't work. lol I don't know if assembly would work in there... Then to top it off, what would it be ASM, ASEM, ASSEMBLY asembly or what? lol
Post 24 Jul 2006, 16:10
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
donkey7



Joined: 31 Jan 2005
Posts: 127
Location: Poland, Malopolska
donkey7
post those dll and exe together with source code and we will tell you what you are doing wrong. right? we aren't prophets.

lol
this word really annoys me, because you use it too often
Post 24 Jul 2006, 20:21
View user's profile Send private message Visit poster's website Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
well, pardon my usage of "lol" considering it's become a bad habit like a caffein addiction and i just can't quit it... you'll know what program is made by me because it'll have "lol" all through it. lol Aside from that, i opened up my DLL in a hex editor and found this...

Code:
01 00 4F 55 54 50 55 54 2E 64 6C 6C 00 3F 70 72 69 6E 74 69 6E 74 40 40 59 41 58 50 41 48 40 5A 00 3F 70 72 69 6E 74 73 74 72 69 6E 67 40 40 59 41 58 50 41 44 40 5A     


If you use a hex editor on a txt or something and hex it in you'll find my function names, but... there's stuf on both sides of the names. I don't know if this is some sort of index or what... I'm guessing MS Visual Studio renames functions when it compiles... Maybe adds stuff to it, i don't know what to add to what side of the function names to call them... I can't read the EXE, (nor do i think you can either) but i posted this incase some one has tried this before and found out how... Basically, the whole purpose of this is to not only get int and char string output for my programs while i'm learning assembly, but to make programs in assembly that use C++ DLLs like FMOD.
Post 24 Jul 2006, 20:37
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi
With fast look on this topic, tells me just about nothing of what you have problems doing, is it that you want to call function of DLL-IN-FASM from PROGRAM-IN-CPP or call function of DLL-IN-CPP from PROGRAM-IN-CPP ?
Post 24 Jul 2006, 21:01
View user's profile Send private message MSN Messenger Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
To be honest with you... as i said above... There are 2 groups of people in this post... Those who think ASM DLL and those who are thinking C++ DLL... The original repliers are comming up with C++ DLL so i make my DLL in C++ instead of a C++ EXE, then it changes... IN the long run, i'm gonna need to learn how to do both, anyway, so i really don't care at this point. Problem is, if i make a ASM DLL how would i come up with the LIB to use with the C++ EXE? So until i learn the basics of assembly and the processor instructions, i don't care which happens, just that i get one of them. lol
Post 24 Jul 2006, 21:07
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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. Also on YouTube, Twitter.

Website powered by rwasa.