Jump to content
Sign in to follow this  
chadiz

DLLCALL

Recommended Posts

chadiz

Hi all, I have this code working in C win32 , (and also VB.NET )

but I cant get my DLLCALLs to work

i have .lib file for the c code and dll file for calling win32 functions

this code configures Digital IO ports on a usb DAQ from mcc (usb 1208-FS )

C code:

ULStat = cbDConfigPort (BoardNum, PortNum, Direction);

ULStat = cbDBitOut (BoardNum, PortType, BitNum, BitValue);

so I used the same exact parameter values as in the C code .. yet the config port return successful.. but the BitOut code returns error: port not configured correctly

autoIt code:

$return = DllCall ( "cbw32.dll", "int", "cbDConfigPort", "int", $Board_number, "int", $Port_Number, "int", $IO_Direction)

$return = DllCall ( "cbw32.dll", "int", "cbDBitOut", "int", $Board_number, "int", $Port_Number, "int", $Bit_Number, "ushort", $Bit_Value)

ANY ideas why the calls dont work the same? is there any timing or reset involved with this?

Thanks

Share this post


Link to post
Share on other sites
BrettF

Hi all, I have this code working in C win32 , (and also VB.NET )

but I cant get my DLLCALLs to work

i have .lib file for the c code and dll file for calling win32 functions

this code configures Digital IO ports on a usb DAQ from mcc (usb 1208-FS )

C code:

ULStat = cbDConfigPort (BoardNum, PortNum, Direction);

ULStat = cbDBitOut (BoardNum, PortType, BitNum, BitValue);

so I used the same exact parameter values as in the C code .. yet the config port return successful.. but the BitOut code returns error: port not configured correctly

autoIt code:

$return = DllCall ( "cbw32.dll", "int", "cbDConfigPort", "int", $Board_number, "int", $Port_Number, "int", $IO_Direction)

$return = DllCall ( "cbw32.dll", "int", "cbDBitOut", "int", $Board_number, "int", $Port_Number, "int", $Bit_Number, "ushort", $Bit_Value)

ANY ideas why the calls dont work the same? is there any timing or reset involved with this?

Thanks

Hi,

Welcome to the forums <_<

Can we please see your VB.net code (Might be easier)? What are the variables declared as?

Share this post


Link to post
Share on other sites
chadiz

Hi,

Welcome to the forums <_<

Can we please see your VB.net code (Might be easier)? What are the variables declared as?

thanks Bert,

here is the VB code that creates an object and calls similar methods:

DaqBoard = New MccDaq.MccBoard(BoardNum) '<======this is the default board number

PortNum = MccDaq.DigitalPortType.FirstPortA

Direction = MccDaq.DigitalPortDirection.DigitalOut

ULStat = DaqBoard.DConfigPort(PortNum, Direction)

...

... partial code

Dim ULStat As MccDaq.ErrorInfo

Dim BitValue As MccDaq.DigitalLogicState

Dim BitNum As Integer

Dim PortType As MccDaq.DigitalPortType

' Write to the bits of FirstPortA and FirstPortB digital outputs

'NOTE that the port name for all the bits wrote during the DBitOut is

'ALWAYS FirstPortA

PortType = MccDaq.DigitalPortType.FirstPortA

' From checkbox

BitNum = Index

If (chkSetBit(Index).Checked) Then

BitValue = MccDaq.DigitalLogicState.High

Else

BitValue = MccDaq.DigitalLogicState.Low

End If

ULStat = DaqBoard.DBitOut(PortType, BitNum, BitValue)

function prototypes :

Public Function DConfigPort(ByVal portNum As MccDaq.DigitalPortType

, ByVal direction As MccDaq.DigitalPortDirection) As MccDaq.ErrorInfo

' Digital output

Public Function DBitOut(ByVal portType As MccDaq.DigitalPortType ,

ByVal bitNum As Integer, ByVal bitValue As MccDaq.DigitalLogicState

) As MccDaq.ErrorInfo

also I like to call this Analog input that uses reference

Public Function AIn(ByVal channel As Integer, ByVal range As

MccDaq.Range , ByRef dataValue As Short) As MccDaq.ErrorInfo

I could call .NET methods from .NET DLL

so my question: how can I create VB.NET object and use reference parameters?

Share this post


Link to post
Share on other sites
BrettF

Goto run, and then try this:

regsvr32 <path & filename of dll>

And then see what happens if you try this:

$oOBJ = ObjCreate("MccDaq.MccBoard")
If Not IsObj($oOBJ) Then
    MsgBox(0, "", "Error")
Else
    MsgBox(0, "", "Success!")
EndIf

Share this post


Link to post
Share on other sites
chadiz

Goto run, and then try this:

regsvr32 <path & filename of dll>

And then see what happens if you try this:

$oOBJ = ObjCreate("MccDaq.MccBoard")
If Not IsObj($oOBJ) Then
    MsgBox(0, "", "Error")
Else
    MsgBox(0, "", "Success!")
EndIf

I got Error.. and couldnt register the dll.. anything i could do?

Share this post


Link to post
Share on other sites
chadiz

I got Error.. and couldnt register the dll.. anything i could do?

so I managed to register the dll.. using regasm from VStudio command prompt.

and i got SUCCESS for creating the object..

I will need to figure out how to call the methods...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.