使用 VB.NET 从您的口袋电脑发送文件
如何从您的口袋电脑发送文件。
引言
这段代码可以让你通过红外线从你的口袋电脑发送文件。
有人在论坛上问我如何使用 VB.NET 发送文件。我找不到任何相关信息,所以尝试使用了实际的 Beam.exe 来发送文件,结果成功了。以下是代码
Imports System.Runtime.InteropServices
Public Class Wireless
<DllImport("CoreDll.DLL", SetLastError:=True)> _
Private Shared Function CreateProcess(ByVal imageName As String, _
ByVal cmdLine As String, _
ByVal lpProcessAttributes As IntPtr, _
ByVal lpThreadAttributes As IntPtr, _
ByVal boolInheritHandles As Int32, _
ByVal dwCreationFlags As Int32, _
ByVal lpEnvironment As IntPtr, _
ByVal lpszCurrentDir As IntPtr, _
ByVal si() As Byte, _
ByVal pi As ProcessInfo) As Integer
End Function
<DllImport("CoreDll.dll")> _
Private Shared Function GetLastError() As Int32
End Function
Public Shared Function CreateProc(ByVal ExeName As String, _
ByVal CmdLine As String, _
ByVal pi As ProcessInfo) As Boolean
If pi Is Nothing Then
pi = New ProcessInfo
End If
Dim si(127) As Byte
Return CreateProcess(ExeName, CmdLine, IntPtr.Zero, _
IntPtr.Zero, 0, 0, _
IntPtr.Zero, _
IntPtr.Zero, si, pi) <> 0
End Function 'CreateProc
End Class 'Externals
Public Class ProcessInfo
Public hProcess As IntPtr
Public hThread As IntPtr
Public ProcessId As Int32
Public ThreadId As Int32
End Class 'ProcessInfo
Wireless.CreateProc("\Windows\Beam.exe", filename, nothing)
文件名是指你要发送的文件。
玩得开心!!