Click to See Complete Forum and Search --> : call a .DLL in a VB form


ariel_au
April 16th, 2001, 11:20 AM
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.

coolbiz
April 16th, 2001, 12:04 PM
Try debugging the value of Cproduct. Then it might tell you why Cproduct mod 2 <> 0.

-Cool Bizs

ariel_au
April 16th, 2001, 12:17 PM
hi cool Bizs, u in the same time zone as me?

sotoasty
April 16th, 2001, 12:37 PM
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

coolbiz
April 17th, 2001, 10:45 AM
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