*** How to call a VC++4 DLL from VB4 (w/source eg:) 
Author Message
 *** How to call a VC++4 DLL from VB4 (w/source eg:)


I had to suffer over this nuance as a recent convertee from a
competitor's compiler (boy, how religeous affiliations can
change...kinda like the saying 'NEVER gamble with a Sicillian when DEATH
is on the line').

Well, since I kept seeing calls for help and no answers, so I grunted
this out since I bought the VC++4 CD today. This is based on a .DLL from
C with the CPP version left as an exercise (don't you just HATE that
kinda talk?).

Having read my License agreements dutifully, it seems that this is okay
to do (although I hold MS harmless and can't claim any Patents from this
code...big deal!).

This example should serve as a verbose correction to the VB4 Unleashed
book whose examples seem to be a bit VB2'ish at times. Admittedly, VC++4
could be the culprit (out after the book no doubt).

Comments and corrections welcome, copyrights still belong to those who
own them, and my humble contribution is for free. Best viewed with full
80 columns (ain't proportional fonts a gas?), here is one for the new pot
'o wisdom....


*************** C code from here to the end ********************

 * SCALC_32.C *

        Create a 32-bit DLL callable from VB 4.0 using
        standard C code.

        The following is based the paper at Microsoft on the WWW in


        Although shown in VB 4 Unleashed, this won't work with VC++ 4

                __declspec(dllexport) int SimpleCalc(int Parm1, int

        Turns out this isn't used/needed, either        

                #include "stdarg.h

        The help screen that enumerates __stdcall explains the rest

int  __stdcall
SimpleCalc(int Parm1, int Parm2)
      return (Parm1 * Parm2);


        Their example used in the paper uses call ByRef (while my
        mod used call ByVal) which also works. The leading
        understores aren't necessary in the function name either
        if the .DEF file matches. These are more conventional in
        ANSI C, but we are doing cross-language communications
        here and leading underscores aren't pretty or even used
        in VB)....

                long __stdcall _lDouble(long *lValue)
                return *lValue + *lValue;

        The whole thing rests on using __stdcall and a .DEF file to
        produce linker constructions that VB can link to at runtime.

        The .DEF file follows:

                LIBRARY        SCALC_32
                DESCRIPTION    'VB 4 -> VC 4 Demo DLL for Windows NT'

                HEAPSIZE       1024

        The VB code to declare this (in a Form as a General
        Declaration) is:

                Private Declare Function SimpleCalc Lib
                (ByVal Parm1 As Integer, ByVal Parm2 As Integer) As

        Add a couple of Text boxes, a Label (for output), and a Command
        button to the Form. Then, in the Click() for the Command button,
        add the following:

                Dim Parm1 As Integer
                Dim Parm2 As Integer

                Parm1 = Val(Text1.Text)
                Parm2 = Val(Text2.Text)

                Label1.Caption = Format$(SimpleCalc(Parm1, Parm2))

  Run it and, if all goes well, you can type two values whole product
  is < 32767 (result is returned as a signed int from C) and the result
  should land in Label1.


Sun, 14 Jun 1998 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Call VC prog. in VB4

2. VB 3.0 Source to VC 2.0 Source

3. vb calls vc dll and strings get chopped

4. Try to call a VC.DLL from VB6

5. Problems calling a VC DLL from VB

6. calling VC DLL from VB

7. Calling VC++ programs and VC created dlls from VB

8. call VC DLL with structure contains pointer of the structure to next

9. Calling C DLLs with VB/VC 5

10. VB5 Bad Calling Convention on VC DLL

11. Calling VB DLLs from VC/C++

12. can you create a dll in VB and call in VC


Powered by phpBB® Forum Software