Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using a DLL and a tutorial how to use some function in VB.
The problem is I'm not familiar with VB and I need to implement in C#

This is the tutorial in VB
VB
Private Declare Function InitComm Lib "pf500.dll" (ByVal portnum As Byte) As Long
Private Declare Function SendCommand Lib "pf500.dll" Alias "WriteCommand" (ByVal porthnd As Long, ByVal seq As Byte, ByVal vlez As String, ByVal izlez As Long, ByVal stats As Long) As Integer

Public Function WriteCommand(ByVal com_port As Byte, ByVal seq As Byte, ByVal sVlez As String, ByRef sIzlez As String, ByRef sStatus As String) As Integer
    
    sIzlez = String$(256, vbNullChar)   
    sStatus = String$(256, vbNullChar)  
    
    Dim lngPortHandle As Long           
    Dim lngIzlez As Long                
    Dim lngStatus As Long               
    
    lngIzlez = StrPtr(sIzlez)
    lngStatus = StrPtr(sStatus)
    
    If ((seq < 32) Or (seq > 127)) Then
        sIzlez = "Sekventniot broj MORA da pripagja vo intervalot od [32,127]"
        sStatus = "GRESEN Sekventen broj"
        Exit Function
    End If
    
    If (Len(sVlez) = 0) Then
        sIzlez = "Parametarot vlez e cmd+data, znaci -mora- da bide min. 1 znak dolg"
        sStatus = "GRESNA vrednost za parametarot vlez"
        Exit Function
    End If
    
    lngPortHandle = InitComm(com_port)  
    If lngPortHandle > 0 Then
        If (SendCommand(lngPortHandle, seq, sVlez, lngIzlez, lngStatus) >= 0) Then 'prakjanje na komandata
            sIzlez = AnsiZtoString(lngIzlez)    
            sStatus = AnsiZtoString(lngStatus)  
        Else
            sIzlez = "Neuspeshno prakjanje/primanje na podatoci od COM" + str(com_port)
            sStatus = "GRESKA"
        End If
        CloseComm (lngPortHandle)           
    Else
        sIzlez = "Portot COM" + str(com_port) + " ne e pronajden!"
        sStatus = "GRESKA"
    End If



and this is how i use InitComm
C#
[DllImport("pf500.dll", CharSet = CharSet.Unicode)]
        public static extern long InitComm(byte s);

and works good
the problem is on sendcommand???
i have no ideo what means alias writecommand

C#
[DllImport("pf500.dll", CharSet = CharSet.Unicode)]
 public static extern int WriteCommand(long portnum, byte seq, string hyrje, long dalje, long stats);

this is how i try it but i got error like this
"Unable to find an entry point named 'Send Command' in DLL 'pf500.dll'."

The problem is how to implement in C# this one:

C#
Private Declare Function SendCommand Lib "pf500.dll" Alias "WriteCommand" (ByVal porthnd As Long, ByVal seq As Byte, ByVal vlez As String, ByVal izlez As Long, ByVal stats As Long) As Integer




sorry for my bad english
Posted
Updated 11-Jul-14 2:47am
v3

1 solution

The declaration:
VB
Private Declare Function SendCommand Lib "pf500.dll" Alias "WriteCommand" (ByVal porthnd As Long, ByVal seq As Byte, ByVal vlez As String, ByVal izlez As Long, ByVal stats As Long) As Integer

is using the name SendCommand to refer to the function WriteCommand in the DLL. In your C# declaration you should just use WriteCommand and it should work. For full details of the VB declaration see http://msdn.microsoft.com/en-us/library/aa243324(v=vs.60).aspx[^].
 
Share this answer
 
Comments
nika2008 11-Jul-14 9:11am    
thnx alot +5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900