News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

MASM32DLL used in C++,VB, Delphi

Started by Ar-ras, April 19, 2006, 01:23:54 AM

Previous topic - Next topic

Ar-ras

Hello
I started to write a dll.
procedures are working fine, but I dont know how functions work
How can I send the the result to the calling program?

thx Ar-ras

hutch--

With the exception of floating point data, the normal return value for almost all languages in 32 bit is EAX so as long as you place the value you want to return in EAX, it should work fine.


YourProc proc args etc ....

  ; code

    mov eax, your_return_value
    ret

YourProc endp
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Ar-ras


zooba

VB can get more complicated if you're returning thing other than 8-, 16- or 32-bit integers.

Just yell if you're returning something more complex (like a structure or string) :U

Cheers,

Zooba

eliran

zooba I loved the attitude  :thumbu  :wink

asmfan

Try to look at Agner Fog site (agner.org) calling conventions and other documets, that describe how procedure should correctly return different values
Russia is a weird place

Ar-ras

Now I have a different question
How can I input structures?
like
RECT STRUCT
x     DWORD  ?
y     DWORD  ?
RECT ENDS

test proc Var1:int, Var2:RECT
.
.
.
test endp

is this correct?

EDIT:
What means in asm the $ in Variable$ ?

hutch--

You can pass structure in a couple of different ways. If you pass the data type as a structure,

tstproc proc var:DWORD,items:RECT    etc ....


items is effectively 4 * DWORD arguments passed on the stack.

The alternative is to pass the ADDRESS of the structure as a single DWORD argument on the stack which involves a bit more work in dereferencing it within the proc but the structure remains after the proc has closed. This is typically how you get a number of return values from a procedure.

MASM has no intrinsic data type by trailing designation, the var$ is simply what you attribute to it as a normal variable. I have personally used such names as string variables and procedures and macros because it is easily recognised by many higher level programmers as a string.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Ar-ras

Quote from: hutch-- on April 21, 2006, 12:40:08 AM
The alternative is to pass the ADDRESS of the structure as a single DWORD argument on the stack which involves a bit more work in dereferencing it within the proc but the structure remains after the proc has closed. This is typically how you get a number of return values from a procedure.

how can i do this ?

MichaelW

There are probably other methods of doing this, but the two that occur to me are to place the pointer in a register and use the structure as a template, or place the pointer in a register and use ASSUME to specify the register as a pointer to the structure. For the second method you need to remember to cancel the assumption when it is no longer needed.

testproc proc uses ebx pRECT:DWORD
    mov   ebx, pRECT

    print ustr$([ebx].RECT.left),13,10
    print ustr$([ebx].RECT.top),13,10
    print ustr$([ebx].RECT.right),13,10
    print ustr$([ebx].RECT.bottom),13,10

    ASSUME ebx:PTR RECT
    print ustr$([ebx].left),13,10
    print ustr$([ebx].top),13,10
    print ustr$([ebx].right),13,10
    print ustr$([ebx].bottom),13,10
    ASSUME ebx:NOTHING

    ret
testproc endp


If you are passing the structure from a HLL, depending on the structure you may need to consider how the HLL aligns, pads, or packs the structure or union members.

Windows Data Alignment


eschew obfuscation