I had a DLL written in Assembly,But i can't call it through VB.An error ?Bad DLL calling
convention? is displayed.
Why so .?. I think VB can only handle _stdcall or _fastcall.
If then,How could the above mentioned DLL can be turned into a _stdcall or _fastcall
Style?

The DLL code Starts as,


DllEntry PROC hInst:DWORD,reason:DWORD,reserved1:DWORD

.if reason == DLL_PROCESS_ATTACH
push hInst ;save the hModule of this DLL when dll loaded
pop hInstance
.endif

mov eax,TRUE
ret
DllEntry ENDP


And the EXPORTED Function is As below


MyFunction PROC
.........
......... ASM Code here
...........
MyFunction ENDP
Posted on 2003-10-20 12:45:14 by zakham
Hi,

here is an example with one little, stupid function, adding two dw's:

.386

.model flat, stdcall

option casemap :none ; case sensitive

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc
include \masm32\include\winmm.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\winmm.lib


.code

LibMain proc hInstDLL:DWORD, reason:DWORD, unused:DWORD ;Start-Einsprungspunkt der DLL

mov eax,1
ret

LibMain Endp


Addieren proc ;#################################################################################################
push ebp
mov ebp,esp

mov eax,[ebp+8] ;Para 1
add eax,[ebp+12] ;Para 2



pop ebp
ret 8 ;Returncounter = Number of paras x 4
Addieren endp


End LibMain


Greetings,
Nordwind64
Posted on 2003-10-20 13:17:52 by Nordwind64
Thanx,That's really good tip
Posted on 2003-10-20 13:38:42 by zakham
When you create the dll you need to make sure the exported function names are not decorated or mangled (for that i use a def file). Also, it would be helpful if you posted your VB declares, as that may be where you problem is.
Posted on 2003-10-22 16:10:52 by sluggy
The function must be stdcall and you MUST at least save/restore the ebx register.

h.
Posted on 2003-10-23 10:58:48 by hitchhikr
Hi there.

I think sluggy is correct here. I have created a small DLL in the past that exported 1 procedure, for which I created a .DEF file. I did not have to use any special technique for calling the procedure from Visual Basic, I simply typed the usual:

Private Declare Sub Test Lib "C:\Test.Dll"

Try creating a .DEF file for your Dll, an example DEF file can be found in the DLL sample project that comes with Masm.

Jas.
Posted on 2003-10-24 03:25:27 by MrClyfar