В VB6 я использовал следующий модуль:
- Код: Выделить всё
Option Explicit
Public Type CEOSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type
Public Declare Function CeGetVersionEx Lib "rapi.dll" ( _
lpVersionInformation As CEOSVERSIONINFO) As Boolean
Private Function GetSub(Addr As Long) As Long
'Used for the init Call.
GetSub = Addr
End Function
Public Function ConnectedRapi()
'Used for the init Call - Do not remove.
End Function
Public Function RapiConnect() As Boolean
'Initiates a connection and returns true
' if it connected, false if it did not.
Dim pRapiInit As RAPIINIT
On Error GoTo RapiConnect_Err
With pRapiInit
.cbSize = Len(pRapiInit)
.heRapiInit = GetSub(AddressOf ConnectedRapi)
End With
Call CeRapiInitEx(pRapiInit)
RapiConnect = RapiGetCEOSVersionString <> ""
Exit Function
RapiConnect_Err:
RapiConnect = False
End Function
Public Function RapiGetCEOSVersionString() As String
' Returns the Major, Minor, and Build number of the OS In a string.
Dim ceosver As CEOSVERSIONINFO
ceosver.dwOSVersionInfoSize = Len(ceosver)
If CeGetVersionEx(ceosver) Then
RapiGetCEOSVersionString = ceosver.dwMajorVersion & "." & _
ceosver.dwMinorVersion & "." & _
ceosver.dwBuildNumber & " " & _
Left$(ceosver.szCSDVersion, _
InStr(ceosver.szCSDVersion, Chr$(0)) - 1)
Else
RapiGetCEOSVersionString = ""
End If
End Function
Вызываю функцию из RapiConnect модуля:
- Код: Выделить всё
Dim bConnected As Boolean
bConnected = RapiConnect
Получаю значение - присоединен ли КПК к ПК.
К сожалению в VB.NET он не работает.
Есть неплохая статья http://msdn.microsoft.com/library/rus/default.asp?url=/library/RUS/vbcon/html/vbup1048.aspкак заменить AddressOf.
Я попробовал таким образом выкрутиться:
- Код: Выделить всё
Delegate Sub ConnectedRapiDelegate()
Private Function GetSub(ByVal Addr As ConnectedRapiDelegate) As Integer
'Used for the init Call.
GetSub = Addr
End Function
Public Sub ConnectedRapi()
'Used for the init Call - Do not remove.
End Sub
Public Function RapiConnect() As Boolean
'Initiates a connection and returns true
' if it connected, false if it did not.
Dim pRapiInit As RAPIINIT
Dim a As Integer
Try
With pRapiInit
.cbSize = Len(pRapiInit)
Dim myDlg As ConnectedRapiDelegate
myDlg = AddressOf ConnectedRapi
.heRapiInit = GetSub(myDlg) 'AddressOf ConnectedRapi)
End With
Call CeRapiInitEx(pRapiInit)
RapiConnect = RapiGetCEOSVersionString() <> ""
Exit Function
Catch ex As Exception
RapiConnect = False
End Try
End Function
Но в данном случае, что-то не стыкуется в строке GetSub = Addr. Выдает ругательство "Value of Type 'ConnectedRapiDelegate' cannot be converted to 'Integer'"