flat assembler
Message board for the users of flat assembler.
![]() Goto page 1, 2 Next |
Author |
|
Reverend 22 Jul 2006, 12:53
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
|
|||
![]() |
|
kohlrak 22 Jul 2006, 17:47
Quote: F:\testinggrounds\ASM>fasm test.asm 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 |
|||
![]() |
|
donkey7 22 Jul 2006, 18:19
Code:
library printf 'printf.dll'
maybe Code: library printf,'printf.dll' ![]() |
|||
![]() |
|
kohlrak 22 Jul 2006, 20:00
*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 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. |
|||
![]() |
|
donkey7 22 Jul 2006, 20:46
obviously, you must define an entrypoint
![]() 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 ![]() |
|||
![]() |
|
kohlrak 23 Jul 2006, 01:57
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++. |
|||
![]() |
|
madmatt 23 Jul 2006, 04:52
If you using the fasmw macros, you'll have to include them with:
include "win32a.inc", then invoke should work as expected. |
|||
![]() |
|
kohlrak 23 Jul 2006, 05:56
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). |
|||
![]() |
|
donkey7 23 Jul 2006, 09:27
well, this code compiles ok for me.
![]() i've used fasmw editor with fasm 1.67.6 engine inside ![]() 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. |
|||
![]() |
|
kohlrak 23 Jul 2006, 14:10
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.
|
|||
![]() |
|
donkey7 23 Jul 2006, 18:11
*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? |
|||
![]() |
|
kohlrak 23 Jul 2006, 19:27
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....
|
|||
![]() |
|
madmatt 23 Jul 2006, 23:46
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. ![]() |
|||
![]() |
|
okasvi 24 Jul 2006, 00:16
AFAIK, usually C/C++ compilers allow you to declare a external function to use different calling convention.
|
|||
![]() |
|
kohlrak 24 Jul 2006, 16:10
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 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 |
|||
![]() |
|
donkey7 24 Jul 2006, 20:21
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 |
|||
![]() |
|
kohlrak 24 Jul 2006, 20:37
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. |
|||
![]() |
|
okasvi 24 Jul 2006, 21:01
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 ?
|
|||
![]() |
|
kohlrak 24 Jul 2006, 21:07
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
|
|||
![]() |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.