flat assembler
Message board for the users of flat assembler.

Index > Windows > Creating a DLL, and have one of the functions return a chunk

Author
Thread Post new topic Reply to topic
Foxxy



Joined: 14 Jul 2014
Posts: 42
Location: Somewhere over the rainbow...
Foxxy
Hello, I am new to assembly, and I got tired of rewriting my functions. So I am going to include them all in a single DLL. One of these functions needs to return something larger than can be contained inside of a 32 bit register. For example, in the following code, I want to return 'ThisVariable'. I think I need to pass the pointer to 'ThisVariable' to the program. But where do I go from there?

Code:
format PE GUI 4.0 DLL
entry DllEntryPoint

include 'win32a.inc'

section '.text' code readable executable

proc DllEntryPoint hinstDLL,fdwReason,lpvReserved
        mov     eax,TRUE
        ret
endp 

proc AFunction thisthat:DWORD bytePtr:DWORD
;return ThisVariable (256 bytes) to calling program
endp
    
Post 16 Jul 2014, 05:13
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Foxxy,

You may pass pointer to that memory as an argument to AFunction() (along with its size for sanity check), or you can develop some kind of a protocol, in which returned pointer is expected to be allocated using predefined method, with a clear method to free that memory (e.g. HeapAlloc()/HeapFree()).
Post 16 Jul 2014, 06:35
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1409
Location: Toronto, Canada
AsmGuru62
Just put all your functions into .ASM files and then include the files as needed.
Post 16 Jul 2014, 16:50
View user's profile Send private message Send e-mail Reply with quote
Foxxy



Joined: 14 Jul 2014
Posts: 42
Location: Somewhere over the rainbow...
Foxxy
Okay, can you point me to somewhere where I can learn how to do this? Also, @baldr how would I write to the memory that the pointer is passed to the DLL function? Preferably without using an outside function. I'm sorry if this seems rude or needy, but I can't seem to find anything on the internet regarding DLL creation and large variables.
Post 16 Jul 2014, 18:56
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Foxxy,

That's simply a pointer, use it to access memory:
Code:
proc AFunction, pointer
        mov     eax, [pointer]
        mov     byte [eax], 42
        ret
endp    
Post 16 Jul 2014, 20:28
View user's profile Send private message Reply with quote
Foxxy



Joined: 14 Jul 2014
Posts: 42
Location: Somewhere over the rainbow...
Foxxy
Wonderful! Just as I was hoping it would work. Thank you.
Post 17 Jul 2014, 03:50
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 598
Roman
Code:
proc AFunction, pointer 
        mov     eax, [pointer]    

pointer like
Code:
 mov     eax, [esp+8]     


Code:
mov     eax, [esp+8] the same like  mov     eax, [pointer] 
    
Post 17 Jul 2014, 04:33
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.