Getting a return value from a DLL in (N)ASM

This is a discussion on Getting a return value from a DLL in (N)ASM within the C++ Programming forums, part of the General Programming Boards category; Hi everyone (sorry im not sure where to put this topic since it pertains to ASM, but the DLL is ...

  1. #1
    Registered User dirkduck's Avatar
    Join Date
    Aug 2001
    Posts
    428

    Getting a return value from a DLL in (N)ASM

    Hi everyone (sorry im not sure where to put this topic since it pertains to ASM, but the DLL is in C++...). Anywho, i'm trying to return a value from a function in a DLL called by an ASM (using NASM as the assembler) program. Anyways, I've tried pop(ing) off all the values that I pushed on previous to the call (the parameters), then popping one more value into a register, assuming that was the return value, which it wasnt. For instace, if the function in the DLL took two parameters then I'd do this:

    push eax //parameter 2
    push ebx //parameter 1
    call [function]
    pop eax //pop off the parameter pushed on earlier
    pop eax //and the other one
    pop edx //wouldnt this be the value returned from "function"?

    So can anyone tell me what to do to get a return from a function in a DLL? Thanks.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    I do this all the time in MASM.....

    Functions have different calling conventions......There's the "C" calling convention (__cdecl in VC++) where you push the params on the stack....make the call ....then pop them all back off again..........The windows API - wsprintf() uses this, and most compilers like VC++ use this by default when calling (unless told otherwise)...


    Then there's the PASCAL calling convention (often implemented __stdcall in VC++) where stack balancing is done inside the function.....therefore you dont need to pop....99% of Win32 system calls use this........

    As to return value.........this is usually put in the EAX register.....that register is 32Bit so it can hold a pointer or any value equal to or less than 32Bit.......

    If you passed a pointer to a function you already know this value when making the call....therefore there's no need to be reminded...

  3. #3
    Registered User dirkduck's Avatar
    Join Date
    Aug 2001
    Posts
    428
    Thanks for the info, got it working with eax.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to combine these working parts??
    By transgalactic2 in forum C Programming
    Replies: 0
    Last Post: 02-01-2009, 08:19 AM
  2. opengl help
    By heat511 in forum Game Programming
    Replies: 4
    Last Post: 04-05-2004, 02:08 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 07:48 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21