News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Problem passing parameter to DLL from another language

Started by asm4all, September 17, 2012, 11:59:53 PM

Previous topic - Next topic

asm4all

I've written a very simple DLL to call from another language.  The parameter LastOBC is passed as a pointer to a 10-element array, but this DLL treats it as a single value, not an array.  My parameter LastOBC:PTR DWord is apparently not correct.  Can anyone tell me what the proper syntax is for passing an array pointer?  Here's the relevant code segment:

**********

AddUp Proc USES ebp LastOBC:PTR DWord

mov ebp,LastOBC
mov eax,[ebp]
mov ebx,10
add eax,ebx

Ret

AddUp EndP

**********

Thanks very much for any help. 


qWord

You should be more specific - which HLL are you using? The pointer declaration (pointer to array of unsigned long) is correct.
Using EBP that way is a bad idea, because it is used for the stack frame. EBX should be saved.
MREAL macros - when you need floating point arithmetic while assembling!

asm4all

Thanks for your reply.

The high level language is APL.  As you say the pointer declaration is correct, then it looks like the problem is in the call from APL. 

Thanks again.


Ryan

If you want to access different elements in the array, you will need to have an offset with ebp.

Assuming your parameter is a pointer to an array of 4-byte elements, you would change [ebp] to [ebp+4], [ebp+8], etc.

hutch--

Try something like this, you can use EAX, ECX and EDX without having to preserve them. If you need to use EBX, ESI or EDI you should preserve and restore them in the procedure.


AddUp Proc LastOBC:DWORD

    mov ecx,LastOBC
    mov eax,[ecx]
    mov edx,10
    add eax,edx

    Ret

AddUp EndP

asm4all

Thanks for all the replies. 

The answer turned out to be this:  when calling from APL, I need to pass two parameters, the pointer and the length of the array.  As I am passing fixed length arrays, my program doesn't need to know the length, but apparently the DLL needs that information in order to treat it as an array. 

Thanks to Hutch for the indexing tips -- when calling from this language, the USES directive will preserve the values of the pointer registers, but I prefer not to use them in mixed-language programming.  I've found that push and pop can cause problems on return to the APL interpreter; it's a bit tricky. 

Thanks again.