您好需要帮助在vb和c#:) [英] hi need help in vb and c# :)
问题描述
我正在使用DLL和教程如何在VB中使用某些函数。
问题是我不熟悉VB,我需要在C#中实现$
这是VB中的教程
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
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
这就是我使用InitComm的方式
and this is how i use InitComm
[DllImport("pf500.dll", CharSet = CharSet.Unicode)]
public static extern long InitComm(byte s);
并且运行良好
问题出在send命令???
i没有ideo什么意思是别名writecommand
and works good
the problem is on sendcommand???
i have no ideo what means alias writecommand
[DllImport("pf500.dll", CharSet = CharSet.Unicode)]
public static extern int WriteCommand(long portnum, byte seq, string hyrje, long dalje, long stats);
这是我尝试的方式,但我得到这样的错误
无法找到名为'Send Command的入口点'在DLL中'pf500.dll'。
问题是如何在C#中实现这一个:
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:
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
推荐答案
(< span class =code-digit> 256 ,vbNullChar)
sStatus = String
(256, vbNullChar) sStatus = String
( 256 ,vbNullChar)
Dim lngPortHandle 作为 长
Dim lngIzlez 作为 长
Dim lngStatus 作为 长
lngIzlez = StrPtr (sIzlez)
lngStatus = StrPtr(sStatus)
如果((seq< 32 )或(seq> 127 ))然后
sIzlez = Sekventniot broj MORA da pripagja vo intervalot od [32,127]
sStatus = GRESEN Sekventen broj
退出 功能
结束 如果
如果(Len(sVlez)= 0 )然后
sIzlez = Parametarot vlez e cmd + data,znaci -mora- da bide min.1 znak dolg
sStatus = GRESNA vrednos t za parametarot vlez
退出 功能
结束 如果
lngPortHandle = InitComm(com_port)
如果 lngPortHandle> 0 然后
如果( SendCommand(lngPortHandle,seq,sVlez,lngIzlez,lngStatus)> = 0 )然后 prakjanje na komandata
sIzlez = AnsiZtoString(lngIzlez)
sStatus = AnsiZtoString(lngStatus)
其他
sIzlez = Neuspeshno prakjanje / primanje na podatoci od COM + str(com_port)
sStatus = GRESKA
结束 如果
CloseComm(lngPortHandle)
< span class =code-keyword> Else
sIzlez = Portot COM + str(com_port)+ ne e pronajden!
sStatus = GRESKA
结束 如果
(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
这就是我使用InitComm的方式
and this is how i use InitComm
[DllImport("pf500.dll", CharSet = CharSet.Unicode)]
public static extern long InitComm(byte s);
并且运行良好
问题出在send命令???
i没有ideo什么意思是别名writecommand
and works good
the problem is on sendcommand???
i have no ideo what means alias writecommand
[DllImport("pf500.dll", CharSet = CharSet.Unicode)]
public static extern int WriteCommand(long portnum, byte seq, string hyrje, long dalje, long stats);
这是我尝试的方式,但我得到这样的错误
无法找到名为'Send Command的入口点'在DLL中'pf500.dll'。
问题是如何在C#中实现这一个:
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:
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
声明:
The declaration:
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
使用名称 SendCommand
来引用函数 WriteCommand 。在你的C#声明中,你应该使用
WriteCommand
,它应该可以工作。有关VB声明的完整详细信息,请参阅 http://msdn.microsoft.com /en-us/library/aa243324(v=vs.60).aspx [ ^ ]。
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[^].
这篇关于您好需要帮助在vb和c#:)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!