Hi People: I want to request you an answer for the follow question. I am building a program in Visual Basic and the main part of it in assembler (using masm32v6). The question: I have programmed a DLL that pass data from and to function in VB. Eg: VB program send a number to a proc. in my DLL and this proc. in the DLL must to send back the result: number + 3. I don't know how the DLL takes the data sent by VB routine and how VB routine takes the result sent back from DLL. I suppose that is by stack but not know how it is. I have looking for an example in your tutorial set of tutorial-routines cannot I cannot find it. An error message occur: "The convention call is not correct". If I try call the same DLL but with a "sub" declare and "call summa" from VB code the error message do not occur but, obviously, I do not get the result that I want to get because the idea is that proc. in DLL give to VB the number + 3 result. This is the declare in the module of VB program Declare Function summa Lib "PATH TO DLL FOLDER" (ByRef play As Single) The calling sub looks like this: ;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Private Sub Command1_Click() play = 1000 x = summa(play) Label1.Caption = Str(x) End Sub ;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Thanks Very much. JR
Posted on 2000-12-16 10:18:00 by JR
This isn't hard to do, let's go thru it step by step. VB passes variables 2 different ways. ByRef, and ByVal. ByVal pushes the VALUE of a variable onto the stack for the dll, allowing the sub access to the variable itself. ByRef pushes the ADDRESS of the variable, thus just passing a copy of the data. Obviously, since you wish to change the value on return, you need to pass it ByRef. Variables are typically passed ByVal when you do not want to dll to change the orgional variable's value. So, now we can proto our function. In MASM: BumpVal PROC pLong:DWORD In VB: Declare Sub BumpVal Lib "MyOwn.DLL" (ByRef value As Long) (It is a Sub since we will not return a value. For a Function, as usual put the return value in eax.) This procedure is fairly trivial to impliment: BumpVal PROC pLong:DWORD mov eax, pLong ; get the variable pointer add , 3 ; add 3 to that address ret BumpVal ENDP Check Icz's tut #17 on dll's to see how to put this procedure into a dll and export it. You'll need (as a min) a .def file to name the export, and the link options to get a .dll
Posted on 2000-12-16 20:59:00 by Ernie
Ernie, everyth. is right except You don't really need a .def to make a DLL! MASM can happily create a COFF object with exported symbol which can be linked then by MS link.exe. MyProc PROC EXPORT par1:DWORD <--This would be exported. ;... MyProc ENDP I learned this stuff from ELicZ's wonderful site : elicz.cjb.net
Posted on 2000-12-18 11:44:00 by AndyCar