vb.net 转 VC++.net(搞定另加50分-100分)

qshurufa 2009-06-19 09:50:07
Declare Sub SetPortDir Lib "SX_GPIO.dll" (ByVal iPort As Integer, ByVal dbDir As Byte)
Declare Function GetPortDir Lib "SX_GPIO.dll" (ByVal iPort As Integer) As Byte
Declare Function ReadPort Lib "SX_GPIO.dll" (ByVal iPort As Integer) As Byte
Declare Sub WritePort Lib "SX_GPIO.dll" (ByVal iPort As Integer, ByVal dbValue As Byte)

Public Const MAX_ASCII_LENGTH = 2
Public data_Mark As Byte = 0

Public Function Ascii2Hex(ByVal p As Char) As Integer
If (p >= "0"c) AndAlso (p <= "9"c) Then
Return CType(AscW(p), Integer) - &H30
End If
If (p >= "A"c) AndAlso (p <= "F"c) Then
Return CType(AscW(p), Integer) - CType(AscW("A"), Integer) + &HA
End If
If p >= "a"c AndAlso p <= "f"c Then
Return CType(AscW(p), Integer) - CType(AscW("a"), Integer) + &HA
End If
Return -1
End Function

Private Sub fmMain_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Select Case e.KeyCode
Case Keys.Escape
Application.Exit()
End Select
End Sub

Private Sub fmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cbPort.SelectedIndex = 0
End Sub

Private Sub txtSetDir_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSetDir.TextChanged
If txtSetDir.Text.Length = 0 OrElse txtSetDir.Text.Length > MAX_ASCII_LENGTH Then
MsgBox("Please input 00~FF.")
txtSetDir.Text = "0"
End If
End Sub

Private Sub txtWrite_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtWrite.TextChanged
If txtWrite.Text.Length = 0 OrElse txtWrite.Text.Length > MAX_ASCII_LENGTH Then
MsgBox("Please input 00~FF.")
txtWrite.Text = "0"
End If
End Sub

Private Sub btnSetDir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetDir.Click
Dim dbDir As Byte
Dim nPort As Integer = Integer.Parse(cbPort.Text)
If txtSetDir.Text <> "" Then
If 2 = txtSetDir.Text.Length Then
Dim first_Ch As Char = Convert.ToChar(txtSetDir.Text.Substring(0, 1))
Dim second_Ch As Char = Convert.ToChar(txtSetDir.Text.Substring(1, 1))
Dim first_Num As Integer = Ascii2Hex(first_Ch)
Dim second_Num As Integer = Ascii2Hex(second_Ch)
If first_Num >= 0 AndAlso second_Num >= 0 Then
dbDir = Byte.Parse(Convert.ToString(first_Num * 16 + second_Num))
data_Mark = dbDir
SetPortDir(nPort, dbDir)
Else
MsgBox("Please input 00~FF.")
txtSetDir.Text = "0"
End If
End If
If 1 = txtSetDir.Text.Length Then
Dim last_Num As Integer = Ascii2Hex(Convert.ToChar(txtSetDir.Text.Substring(0, 1)))
If last_Num >= 0 Then
dbDir = Byte.Parse(Convert.ToString(last_Num))
data_Mark = dbDir
SetPortDir(nPort, dbDir)
Else
MsgBox("Please input 00~FF.")
txtSetDir.Text = "0"
End If
End If
Else
txtSetDir.Text = "0"
MsgBox("Please input 00~FF.")
End If
End Sub

Private Sub btnGetDir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetDir.Click
Dim get_Data As Byte
Dim nPort As Integer = Integer.Parse(cbPort.Text)
get_Data = GetPortDir(nPort)
If get_Data >= 0 AndAlso get_Data <= 255 Then
txtGetDir.Text = get_Data.ToString("X")
End If
End Sub

Private Sub btnWrite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWrite.Click
Dim wData As Byte
Dim nPort As Integer = Integer.Parse(cbPort.Text)
If txtWrite.Text <> "" Then
If 2 = txtWrite.Text.Length Then
Dim first_Ch As Char = Convert.ToChar(txtWrite.Text.Substring(0, 1))
Dim second_Ch As Char = Convert.ToChar(txtWrite.Text.Substring(1, 1))
Dim first_Num As Integer = Ascii2Hex(first_Ch)
Dim second_Num As Integer = Ascii2Hex(second_Ch)
If first_Num >= 0 AndAlso second_Num >= 0 Then
wData = Byte.Parse(Convert.ToString(first_Num * 16 + second_Num))
wData = wData And data_Mark
WritePort(nPort, wData)
Else
MsgBox("Please input 00~FF.")
txtWrite.Text = "0"
End If
End If
If 1 = txtWrite.Text.Length Then
Dim last_num As Integer = Ascii2Hex(Convert.ToChar(txtWrite.Text.Substring(0, 1)))
If last_num >= 0 Then
wData = Byte.Parse(Convert.ToString(last_num))
wData = wData And data_Mark
WritePort(nPort, wData)
Else
MsgBox("Please input 00~FF.")
txtWrite.Text = "0"
End If
End If
Else
txtWrite.Text = "0"
MsgBox("Please input 00~FF.")
End If
End Sub

Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click
Dim rData As Byte
Dim nPort As Integer = Integer.Parse(cbPort.Text)
rData = ReadPort(nPort)
rData = rData And CByte(Not data_Mark) 'Not data_mark 按位取反, C#中为~data_mark
If rData >= 0 AndAlso rData <= 255 Then
txtRead.Text &= rData.ToString("X")
End If
End Sub
...全文
98 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
qshurufa 2009-06-23
  • 打赏
  • 举报
回复
不是调用dll,帮忙把代码从vb.net 转成vc++.net。
qshurufa 2009-06-22
  • 打赏
  • 举报
回复
自己再顶一下。
用户 昵称 2009-06-22
  • 打赏
  • 举报
回复
感觉就是调用dll嘛。
IamDeane 2009-06-21
  • 打赏
  • 举报
回复
说实话有的时候你还不如告诉你想要的功能更简单
imdeveloper 2009-06-20
  • 打赏
  • 举报
回复
你可以使用.NET Reflector自动完成VB.NET代码到VC++/CLI或managed C++得转换。安全方便。

具体步骤:
1. 把VB.NET代码编译成assembly。
2. 使用.net reflector加载这个assembly。
3. disasemble这个assembly
4. 如果是managed C++,在工具栏上选择managed C++即可
如果是C++/CLI,你还需要安装一个.NET Reflector插件
http://www.sandpapersoftware.com/Main/Reflector.html


Regards
All-In-One Code Framework Project Group
http://cfx.codeplex.com
qshurufa 2009-06-19
  • 打赏
  • 举报
回复
代码是多了点,不过分也是多啊,搞定了多加100分,(*^__^*)...嘻嘻!!!
满衣兄 2009-06-19
  • 打赏
  • 举报
回复
好象目前没有这种工具.最好还是自己学习一下,太多了.
shaqing_0928 2009-06-19
  • 打赏
  • 举报
回复
顶一个,结构好像是先用declare声明变量,作为宏定义,然后定义静态变量,之后是函数定义及操作,你可以把vc++ .net的基础看看,就很好改了
qshurufa 2009-06-19
  • 打赏
  • 举报
回复
楼上大哥帮帮忙吧,我不是学用VC开发的,只是现在要用到VC,现学有点不太合适吧。帮忙转一下,分是大大的。
oyljerry 2009-06-19
  • 打赏
  • 举报
回复
自己再学习一下VC,然后应该比较方便转换了...
qshurufa 2009-06-19
  • 打赏
  • 举报
回复
来人啊,帮帮忙啊!!!
Declare Sub SetPortDir Lib "SX_GPIO.dll" (ByVal iPort As Integer, ByVal dbDir As Byte)
Declare Function GetPortDir Lib "SX_GPIO.dll" (ByVal iPort As Integer) As Byte

Public Function Ascii2Hex(ByVal p As Char) As Integer
If (p >= "0"c) AndAlso (p <= "9"c) Then
Return CType(AscW(p), Integer) - &H30
End If
If (p >= "A"c) AndAlso (p <= "F"c) Then
Return CType(AscW(p), Integer) - CType(AscW("A"), Integer) + &HA
End If
If p >= "a"c AndAlso p <= "f"c Then
Return CType(AscW(p), Integer) - CType(AscW("a"), Integer) + &HA
End If
Return -1
End Function


Private Sub btnWrite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWrite.Click
Dim wData As Byte
Dim nPort As Integer = Integer.Parse(cbPort.Text)
If txtWrite.Text <> "" Then
If 2 = txtWrite.Text.Length Then
Dim first_Ch As Char = Convert.ToChar(txtWrite.Text.Substring(0, 1))
Dim second_Ch As Char = Convert.ToChar(txtWrite.Text.Substring(1, 1))
Dim first_Num As Integer = Ascii2Hex(first_Ch)
Dim second_Num As Integer = Ascii2Hex(second_Ch)
If first_Num >= 0 AndAlso second_Num >= 0 Then
wData = Byte.Parse(Convert.ToString(first_Num * 16 + second_Num))
wData = wData And data_Mark
WritePort(nPort, wData)
Else
MsgBox("Please input 00~FF.")
txtWrite.Text = "0"
End If
End If
If 1 = txtWrite.Text.Length Then
Dim last_num As Integer = Ascii2Hex(Convert.ToChar(txtWrite.Text.Substring(0, 1)))
If last_num >= 0 Then
wData = Byte.Parse(Convert.ToString(last_num))
wData = wData And data_Mark
WritePort(nPort, wData)
Else
MsgBox("Please input 00~FF.")
txtWrite.Text = "0"
End If
End If
Else
txtWrite.Text = "0"
MsgBox("Please input 00~FF.")
End If
End Sub

Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click
Dim rData As Byte
Dim nPort As Integer = Integer.Parse(cbPort.Text)
rData = ReadPort(nPort)
rData = rData And CByte(Not data_Mark) 'Not data_mark 按位取反, C#中为~data_mark
If rData >= 0 AndAlso rData <= 255 Then
txtRead.Text &= rData.ToString("X")
End If
End Sub

减少工作量,搞定这些就结贴。加分。

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧