Advertisement

ASM and VB

Started by September 13, 2000 02:12 PM
2 comments, last by Milos 24 years, 3 months ago
Anybody there has experience with DLLs & VB? I have got (another) problem, this time a strange one. The DLL, whose code is below, works fine if ran from another ASM program, but behaves very strange within VB. The return value is not even close to the original. I think that VB is changing the value of EAX before the function returns(I''ve tested this with an .IF statement jsut above the RET mnemonic). Is there any solution to this problem? (Don''t say this DLL is pointless, I know it is, it''s just a simple test) Thanks.
    
;<<***EXCLUDES Rgb2***>>

    .386
    .model flat, stdcall
    option casemap :none
;=================================================
    include    \masm32\include\windows.inc
;=================================================
    return MACRO arg
       mov eax, arg
       ret
    ENDM
;=================================================
.code
start:
;=================================================
LibMain     PROC        hInstance :DWORD,
                        Reason    :DWORD,
                        pReserved :DWORD

    mov eax, 1
    ret
LibMain ENDP
;=================================================
Rgb2    PROC    red   :BYTE, 
                green :BYTE, 
                blue  :BYTE

    xor eax, eax
    mov ah, blue
    shl eax, 8
    mov ah, green
    mov al, red

    ret
Rgb2   ENDP
;=================================================
end start
    
-Milos
-Milos
Hi.

Visual Basic by default sends all function parameters by reference. SO, your ASM function is receiving *POINTERS* to RGB values instead of the actual values. That explains why the Visual Basic caller receives crap as return value. On the other hand, on C are by default sent by value, and that's why the C caller gets the correct results.

Make sure you declare the ASM function like this:

public declare function Rgb2 lib "dll path" (byval Red as long, byval Green as long, byval Blue as long) as long

Hope this helps,

Topgoro

PS: Your DLL is not pointless, a function to pack 3 RGB values onto a dword can be indeed useful, especially from BASIC. Besides, "Hello world" is even more pointless and everybody starts by writting such a program, right?

;You are not a real programmer until you start all your sentences with a semicolon

Edited by - Topgoro on September 13, 2000 5:37:21 PM
We emphasize "gotoless" programming in this company, so constructs like "goto hell" are strictly forbidden.
Advertisement
Hey thanks, that helped!!

-Milos
-Milos
quote: Original post by Milos

Hey thanks, that helped!!

-Milos
You welcome

;You are not a real programmer until you start all your sentences with a semicolon
We emphasize "gotoless" programming in this company, so constructs like "goto hell" are strictly forbidden.

This topic is closed to new replies.

Advertisement