CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2001
    Posts
    44

    call a .DLL in a VB form

    i created a .DLL named (dlldemo.dll) using MS visual C++
    below is my DLL function in C++.

    #include <windows.h>

    void __stdcall Multiply(int Cheight, int Cwidth, int Cproduct)
    {

    Cproduct = Cheight * Cwidth;

    return;
    }



    well, what my DLL does is that it computes the Cproduct from input Cheight and Cwidth of a form.

    below in my VB form that calls the .DLL

    option Explicit
    private Declare Sub Multiply Lib "C:\dlldemo.dll" (Cheight as Integer, Cwidth as Integer, Cproduct as Integer)
    '-------------------------------------------------------------------
    'In my form, upon OK button is clicked....
    private Sub CmdOk_Click()

    Dim Cheight as Integer, Cwidth as Integer, Cproduct as Integer

    Cheight = Val(txtHeight.Text) 'input height from textbox
    Cwidth = Val(txtWidth.Text) 'input width from textbox

    Multiply Cheight, Cwidth, Cproduct ' call DLL

    If Cproduct Mod 2 <> 0 then 'return(Cproduct) the computed value in .DLL to here...

    'POP up a msgbox if the computed Cproduct is an odd num...
    MsgBox "The values generate an odd number of icons." & vbCrLf & _
    "Change Width and/or Height so that their product " & vbCrLf & _
    "is an even number.", vbInformation, "Change Width and/or Height"

    Exit Sub
    :
    :
    :



    well, i my problem is that my msgBox does not pop-up if the Cproduct is an odd number.

    i think that something is wrong in my .DLL or maybe the way i call my DLL is incorrect.. anyone noes where is the problem?? pls reply, thank you.





  2. #2
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    Re: call a .DLL in a VB form

    Try debugging the value of Cproduct. Then it might tell you why Cproduct mod 2 <> 0.

    -Cool Bizs

    Good Luck,
    -Cool Bizs

  3. #3
    Join Date
    Mar 2001
    Posts
    44

    Re: call a .DLL in a VB form

    hi cool Bizs, u in the same time zone as me?


  4. #4
    Join Date
    Sep 2000
    Location
    FL
    Posts
    1,452

    Re: call a .DLL in a VB form

    Try this.


    #include <windows.h>
    LONG __stdcall Multiply(int Cheight, int Cwidth)
    {
    INT CProduct;

    Cproduct = Cheight * Cwidth;
    return CProduct;
    }




    Then in the VB Program

    option Explicit
    private Declare Sub Multiply Lib "C:\dlldemo.dll" (byval Cheight as Integer, byval Cwidth as Integer) as long

    '-------------------------------------------------------------------
    'In my form, upon OK button is clicked....

    private Sub CmdOk_Click()
    Dim Cheight as Integer, Cwidth as Integer, Cproduct as Long

    Cheight = Val(txtHeight.Text) 'input height from textbox
    Cwidth = Val(txtWidth.Text) 'input width from textbox
    cProduct = Multiply(Cheight, Cwidth) ' call DLL
    If Cproduct Mod 2 <> 0 then 'return(Cproduct) the computed value in .DLL to here...
    'POP up a msgbox if the computed Cproduct is an odd num...
    MsgBox "The values generate an odd number of icons." & vbCrLf & _ "Change Width and/or Height so that their product " & vbCrLf & _ "is an even number.", vbInformation, "Change Width and/or Height"

    Exit Sub




    Hope this helps



  5. #5
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    Re: call a .DLL in a VB form

    Well .. I live in Malaysia (for another 2 weeks) and will be back in Stamford CT USA after that. Where are you from?

    -Cool Bizs

    Good Luck,
    -Cool Bizs

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured