Author Topic: Problem passing parameter to DLL from another language  (Read 1877 times)

asm4all

  • Guest
Problem passing parameter to DLL from another language
« on: September 17, 2012, 11:59:53 PM »
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

  • Member
  • *****
  • Posts: 1454
  • The base type of a type is the type itself
    • SmplMath macros
Re: Problem passing parameter to DLL from another language
« Reply #1 on: September 18, 2012, 12:07:43 AM »
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

  • Guest
Re: Problem passing parameter to DLL from another language
« Reply #2 on: September 18, 2012, 12:28:49 AM »
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

  • Guest
Re: Problem passing parameter to DLL from another language
« Reply #3 on: September 18, 2012, 12:45:30 AM »
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--

  • Administrator
  • Member
  • ******
  • Posts: 4813
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Problem passing parameter to DLL from another language
« Reply #4 on: September 18, 2012, 01:05:38 AM »
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.

Code: [Select]
AddUp Proc LastOBC:DWORD

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

    Ret

AddUp EndP
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

asm4all

  • Guest
Re: Problem passing parameter to DLL from another language
« Reply #5 on: September 18, 2012, 03:33:20 AM »
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.