📄 common.vb
字号:
'Filename : Common.vb
'Part of : Application installer VB.NET example
'Description : Main module of VBInstaller.NET example application
'Version : 3.2
'
'This example is only to be used with PC Connectivity API version 3.2.
'Compability ("as is") with future versions is not quaranteed.
'
'Copyright (c) 2007 Nokia Corporation.
'
'This material, including but not limited to documentation and any related
'computer programs, is protected by intellectual property rights of Nokia
'Corporation and/or its licensors.
'All rights are reserved. Reproducing, modifying, translating, or
'distributing any or all of this material requires the prior written consent
'of Nokia Corporation. Nokia Corporation retains the right to make changes
'to this material at any time without notice. A copyright license is hereby
'granted to download and print a copy of this material for personal use only.
'No other license to any other intellectual property rights is granted. The
'material is provided "as is" without warranty of any kind, either express or
'implied, including without limitation, any warranty of non-infringement,
'merchantability and fitness for a particular purpose. In no event shall
'Nokia Corporation be liable for any direct, indirect, special, incidental,
'or consequential loss or damages, including but not limited to, lost profits
'or revenue,loss of use, cost of substitute program, or loss of data or
'equipment arising out of the use or inability to use the material, even if
'Nokia Corporation has been advised of the likelihood of such damages occurring.
Option Strict Off
Option Explicit On
Imports System.Runtime.InteropServices
Module Common
Public hDMHandle As Integer ' Device manager handle
Public hFSHandle As Integer ' File System handle
Public MainForm As InstallerDialog ' Main form of application
Public bAppUninstallSupported As Boolean ' Phone supports appication uninstallation
'===================================================================
' DeviceNotifyCallback
'
' Callback function for device connection notifications
'
'===================================================================
Public Function DeviceNotifyCallback(ByRef iStatus As Integer, <MarshalAs(UnmanagedType.LPWStr)> ByVal pstrSerialNumber As String) As Integer
On Error Resume Next
MainForm.bRefreshPhonecombo = True
DeviceNotifyCallback = CONA_OK
End Function
'===================================================================
' FSNotifyCallback
'
' Callback function for file operation notifications
'
'===================================================================
Public Function FSNotifyCallback(ByVal iOperation As Integer, ByVal iStatus As Integer, ByVal iTransferredBytes As Integer, ByVal iAllBytes As Integer) As Integer
FSNotifyCallback = CONA_OK
If iOperation = CONAInstallApplicationNtf Then
If iStatus = CONA_OK_BUT_USER_ACTION_NEEDED Then
' Show text stating wait status
MainForm.labelWait.Visible = True
MainForm.ProgressBar1.Visible = False
Else
MainForm.SetProgress(iStatus)
End If
Else
MainForm.SetProgress(iStatus)
End If
If MainForm.IsCancelled Then
FSNotifyCallback = ECONA_CANCELLED
End If
End Function
'===================================================================
' InstallJavaApplication
'
' Install Java application to phone
'
'===================================================================
Public Function InstallJavaApplication(ByVal strJarFile As String, ByVal strJadFile As String) As Integer
Dim jarFile As String
Dim jadFile As String
Dim path As String
Dim javaFiles As CONAPI_APPLICATION_JAVA
Dim dwOptions As Integer = CONA_DEFAULT_FOLDER Or CONA_OVERWRITE Or CONA_WAIT_THAT_USER_ACTION_IS_DONE
If Len(strJarFile) = 0 Then
MsgBox("File name is missing")
Exit Function
End If
jarFile = System.IO.Path.GetFileName(strJarFile)
jadFile = System.IO.Path.GetFileName(strJadFile)
javaFiles.pstrFileNameJar = jarFile
If Len(jadFile) = 0 Then
javaFiles.pstrFileNameJad = vbNullString
Else
javaFiles.pstrFileNameJad = jadFile
End If
path = System.IO.Path.GetDirectoryName(strJarFile)
InstallJavaApplication = CONAInstallJavaApplication(hFSHandle, CONA_APPLICATION_TYPE_JAVA, javaFiles, dwOptions, path, vbNullString)
If InstallJavaApplication = CONA_OK Then
MsgBox("Application installation succeeded")
ElseIf InstallJavaApplication = CONA_OK_BUT_USER_ACTION_NEEDED Then
' Either device does not support waiting or the maximum waiting time exceeded
MsgBox("User action needed on the device side")
Else
ShowErrorMessage("CONAInstallApplication", InstallJavaApplication)
End If
End Function
'===================================================================
' InstallSymbianApplication
'
' Install Symbian application to phone
'
'===================================================================
Public Function InstallSymbianApplication(ByVal strFile As String) As Integer
Dim sisFile As String
Dim path As String
Dim sisFiles As CONAPI_APPLICATION_SIS
Dim dwOptions As Integer = CONA_DEFAULT_FOLDER Or CONA_OVERWRITE Or CONA_WAIT_THAT_USER_ACTION_IS_DONE
If Len(strFile) = 0 Then
MsgBox("File name is missing")
Exit Function
End If
sisFile = System.IO.Path.GetFileName(strFile)
sisFiles.pstrFileNameSis = sisFile
path = System.IO.Path.GetDirectoryName(strFile)
InstallSymbianApplication = CONAInstallSymbianApplication(hFSHandle, CONA_APPLICATION_TYPE_SIS, sisFiles, dwOptions, path, vbNullString)
If InstallSymbianApplication = CONA_OK Then
MsgBox("Application installation succeeded")
ElseIf InstallSymbianApplication = CONA_OK_BUT_USER_ACTION_NEEDED Then
' Either device does not support waiting or the maximum waiting time exceeded
MsgBox("User action needed on the device side")
Else
ShowErrorMessage("CONAInstallApplication", InstallSymbianApplication)
End If
End Function
'===================================================================
' InstallTheme
'
' Install theme to phone
'
'===================================================================
Public Function InstallTheme(ByVal strFile As String) As Integer
Dim strNthFile As String
Dim path As String
Dim nthFile As CONAPI_APPLICATION_FILE
Dim dwOptions As Integer = CONA_DEFAULT_FOLDER Or CONA_OVERWRITE Or CONA_WAIT_THAT_USER_ACTION_IS_DONE
If Len(strFile) = 0 Then
MsgBox("File name is missing")
Exit Function
End If
strNthFile = System.IO.Path.GetFileName(strFile)
nthFile.pstrFileName = strNthFile
path = System.IO.Path.GetDirectoryName(strFile)
InstallTheme = CONAInstallTheme(hFSHandle, CONA_APPLICATION_TYPE_THEMES, nthFile, dwOptions, path, vbNullString)
If InstallTheme = CONA_OK Then
MsgBox("Application installation succeeded")
ElseIf InstallTheme = CONA_OK_BUT_USER_ACTION_NEEDED Then
' Either device does not support waiting or the maximum waiting time exceeded
MsgBox("User action needed on the device side")
Else
ShowErrorMessage("CONAInstallApplication", InstallTheme)
End If
End Function
'===================================================================
' InstallNGageApplication
'
' Install NGage application to phone
'
'===================================================================
Public Function InstallNGageApplication(ByVal strFile As String) As Integer
Dim nGageFile As String
Dim sourcePath As String
Dim targetPath As String = "\\C:\Data\" 'Phone memory is used
Dim nGageFolder As String = "N-Gage"
Dim iOptions As Integer = CONA_DIRECT_PC_TO_PHONE Or CONA_OVERWRITE
Dim iResult As Integer
If Len(strFile) = 0 Then
MsgBox("File name is missing")
Exit Function
End If
' Split source file name in path and file name
nGageFile = System.IO.Path.GetFileName(strFile)
sourcePath = System.IO.Path.GetDirectoryName(strFile)
' Create n-gage folder on Phone
iResult = CONACreateFolder(hFSHandle, nGageFolder, targetPath)
If iResult <> CONA_OK And iResult <> ECONA_FOLDER_ALREADY_EXIST Then
ShowErrorMessage("CONACreateFolder", iResult)
End If
' Append n-gage foldr to target path
targetPath = targetPath & nGageFolder
' N-Gage application is installed by copying file to predefined folder,
InstallNGageApplication = CONACopyFile(hFSHandle, iOptions, nGageFile, sourcePath, targetPath)
If InstallNGageApplication = CONA_OK Then
MsgBox("Application installation succeeded")
Else
ShowErrorMessage("CONACopyFile", InstallNGageApplication)
End If
End Function
'===================================================================
' UnInstallApplication
'
' UnInstalls application from phone
'
'===================================================================
Public Function UnInstallApplication(ByVal strAppName As String, ByVal strAppUID As String) As Integer
Dim iOptions As Integer
iOptions = CONA_SILENT_UNINSTALLATION
UnInstallApplication = CONAUninstallApplication(hFSHandle, iOptions, strAppName, strAppUID)
If UnInstallApplication <> CONA_OK Then
ShowErrorMessage("CONAUninstallApplication", UnInstallApplication)
End If
End Function
End Module
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -