Working with a DLL question

techmanbd

Junior Contributor
Joined
Sep 10, 2003
Messages
397
Location
Burbank, CA
I have a 3rd party bus communications box and there is a dll that comes with it to speak to this box through the USB port. At one time I could have 3 to 5 of these boxes connected. I would like to just use one form to talk to all these boxes. Here is what happens. I will use 2 boxes as an example. If I run the EXE file, it will talk to 1 of the boxes. If I want to talk to the second box, I have to run the exe file a second time. Now I have been trying to do this with one form so I don't have mutiple executables running at the same time and not having success.

Can someone lead me into the right direction? What to look in to?
I will still search as well. I have a feeling it has to do with the DLL and assigining a new instance to it for the 2nd box. Also I can't reference this dll through the framework. I have to use the system.runtime.interopservices and the <Dllimport("whatever")> code.

Hope this makes sense
Thanks,
 
Yes I do.

This is a sample of the class, there are more dllImports but not needed to see.
Visual Basic:
Public Class McS1Com2
  <DllImport("MCS132", EntryPoint:="PassThruConnect", CharSet:=CharSet.Ansi, SetLastError:=True)> _
    Public Shared Function PassThruConnect(ByVal ProtocolID As Int64, ByVal Flags As Int64, _
                                                                                ByRef pChannelID As Int64) As Integer
    End Function
end class


Then in my form
Visual Basic:
 Dim MCS As NEW McS1Com2 'This is at the top

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim intC As Int64
        Dim intCC As Int64
        Dim strC As String
        intC = MCS.PassThruConnect(MCS.Protocol.MSCAN, MCS.PassThruCon_TXFlag.TX_BLOCKING, intCC)
        strC = "Connect Status: " & intC
   
        Me.Label2.Text = strC
        Me.Label1.Text = intCC.ToString

    End Sub
 
It returns the same parameter. I am not sure how it is identifying the different devices. I am thinking it is in that DLL. Unfortunately the person that wrote it is no longer around so I can't talk to him, and have asked another guy, but he doesn't know either.


Edit: Also I would like to note, I have the GUI interface that the company supplies with these boxes. And their interface it the same way. If I want to interface with 2 boxes, I have to run it twice.

If they are doing this as well, I may just be SOL and just write a program, and have a button to start the executable for how ever many I need.
 
Last edited:
In the code snippet you posted the line
Visual Basic:
 intC = MCS.PassThruConnect(MCS.Protocol.MSCAN, MCS.PassThruCon_TXFlag.TX_BLOCKING, intCC)
has a parameter intCC - are you getting consistent values back when you call the method?
 
Yes, but it is always 0. I assigned it different numbers before this command, and it brings back that number instead of changing it just to see. I don't think it is doing anything.

I haven't been able to work on it the past couple of work days as other priorities have come up.

This is the code I took that was done in borland C. I am not a C programmer, but I though the "&" means that it assigns a value to that address?

This is where the person assigned the variable
unsigned long hMSCAN;

The first time I see it used.
Status = PassThruConnect(MSCAN, 0, &hMSCAN);

Then it is used here to send commands to that box
Status = PassThruWriteMsgs(hMSCAN, &TxMsgs[1], &NumMsgs, 100);
 
Back
Top