Hi there!
I've coded a nice dll in win32asm but I don't know how to declare that a function has a returnvalue or not :(
When I wanna return a value I just put it into EAX and do a RET, if not I just don't care bout EAX and do a RET...
The problem is that I receive GPFs when I try to use the functions with a returnvalue! Please help me out and tell my how to write such function and how to call them from C++ (header/prototype/code) or VB (yeah I know)...

Thanks in advance!


; Function with returnvalue
testFunc proc inParam:DWORD
mov eax,inParam
testFunc endp

; Function with returnvalue
testFunc proc inParam:DWORD
testFunc endp
Posted on 2001-09-22 09:01:51 by paradiza
You probably have a calling convention problem. The easy way :)
to solve this is to declare your proc as

testFunc proc [B]C[/B] inParam:DWORD
mov eax,inParam
testFunc endp

the C tells masm that this function will be using the C calling convention.
You could also use STDCALL (which is the default if you use a "normal"
masm32 setup), but that requires some changes to your C source
code, and is (afaik) "sort of" compiler dependant.

Also, you must remember that if you use EBX/ESI/EDI, they must
be preserved by your asm proc (add a USES clause).
Posted on 2001-09-22 09:55:07 by f0dder
I can help you in VB:

If you declare as a function an assembly proc that doesn' t return any value then you obtain an unpredictable value from eax but you don't get an error from VB. For your commodity you had better declare as Subs those procedures.

in a module.bas type :

Declare Function testFunc Lib "MYDLL.dll" (ByVal inParam As Long) As Long

It is the same than declaring an API of Windows.

Posted on 2001-09-24 01:45:53 by fooCoder

a dll for vb is provided with masmed
if u're intererested to see a (lame) example.

Posted on 2001-09-24 03:48:01 by hitchhikr
A couple of things, in VB you will probably need the ALIAS keyword otherwise you will get an EXPORT error. Basic is not case sensitive so it needs the ALIAS keyword.

Basic is native STDCALL, I forget if VB has the option to call a C calling convention function. Also you will need to know the difference between ByVal and ByRef parameter passing, Basic does both. To translate this to assembler, a parameter passed as ByRef arrives at the ASM end as an address, if its passed ByVal it arrives there as a VALUE so be careful about how and what you pass.

The return value does not matter in normal integer registers (EAX etc ...), if you need a return value, put it in EAX and use RET, else just use XOR EAX, EAX and ret.


Posted on 2001-09-24 08:02:37 by hutch--
Wah, shame on me :)
I just forgot to declare the USES which messed up my stack... Now the DLL works just fine and is callable from C++ without any probs!

Thanks for all your kind response!

Calling the functions from VB doesn't work but I'll figure that out, too... ALIAS didn't help out - maybe I define an internal name in my def-file.

I'll keep you up to date!

Regards, Para
Posted on 2001-09-24 10:34:42 by paradiza