📄 conadevicemanagement.cs
字号:
//Filename : CONADeviceManagement.cs
//Part of : PCSAPI C# examples
//Description : Device management API, converted from CONADeviceManagement.h
//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.
using System.Runtime.InteropServices;
namespace CONADeviceManagement
{
using CONADefinitions;
class CONADeviceManagement
{
/////////////////////////////////////////////////////////////
//// Device management API
/////////////////////////////////////////////////////////////
//=========================================================
// Device Management API versions
//
public const short DMAPI_VERSION_30 = 30;
public const short DMAPI_VERSION_31 = 31;
public const short DMAPI_VERSION_32 = 32;
//=========================================================
[DllImport("ConnAPI", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
//=========================================================
// DMAPI_Initialize
//
// Description:
// DMAPI_Initialize initializes the API. This must be called once and before any other DMAPI call!
// It's not allowed to call this function like this
// DMAPI_Initialize(DMAPI_GetAPIVersion(), NULL);
// You must call it like this
// DMAPI_Initialize(DMAPI_VERSION_30, NULL);
//
// Parameters:
// dwAPIVersion [in] DMAPI version requested.
// pdwParam [in] Reserved for future use. Must be NULL.
//
// Return values:
//
//=========================================================
public static extern int DMAPI_Initialize(
int dwAPIVersion,
int pdwParam
);
[DllImport("ConnAPI", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
//=========================================================
// DMAPI_Terminate
//
// Description:
// DMAPI_Terminate terminates the API. This must be called once and as the last DMAPI call!
//
// Parameters:
// pdwParam [in] Reserved for future use. Must be NULL.
//
// Return values:
//
//=========================================================
public static extern int DMAPI_Terminate(int iValue);
[DllImport("ConnAPI", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
//=========================================================
// DMAPI_GetAPIVersion
//
// Description:
// Returns currently installed version of this DMAPI.
//
// Parameters:
//
// Return values:
// API version number.
//
//=========================================================
public static extern int DMAPI_GetAPIVersion();
[DllImport("ConnAPI", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
/////////////////////////////////////////////////////////////
//// Device management API
/////////////////////////////////////////////////////////////
//=========================================================
// CONAOpenDM
//
// Description:
// Returns the handle to the device manager
//
// Parameters:
// phDMHandle [out] Device manager handle
//
// Return values:
// CONA_OK
// ECONA_INVALID_POINTER
// ECONA_NOT_INITIALIZED
// ECONA_INIT_FAILED_COM_INTERFACE
// ECONA_UNKNOWN_ERROR
//
//=========================================================
public static extern int CONAOpenDM(ref int hDMHandle);
[DllImport("ConnAPI", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
//=========================================================
// CONACloseDM
//
// Description:
// Closes the handle to the device manager
//
// Parameters:
// hDMHandle [in] Device manager handle
//
// Return values:
// CONA_OK
// ECONA_INVALID_POINTER
// ECONA_NOT_INITIALIZED
// ECONA_UNKNOWN_ERROR
//
//=========================================================
public static extern int CONACloseDM(int hDMHandle);
[DllImport("ConnAPI", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
//=========================================================
// CONAGetDeviceCount
//
// Description:
// Returns number of available devices
//
// Parameters:
// hDMHandle [in] Device manager handle
// iCount [out] Number of devices
//
// Return values:
// CONA_OK
// ECONA_INVALID_POINTER
// ECONA_NOT_INITIALIZED
// ECONA_UNKNOWN_ERROR
//
//=========================================================
public static extern int CONAGetDeviceCount(
int hDMHandle,
ref int iCount);
[DllImport("ConnAPI", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
//=========================================================
// CONAGetDevices
//
// Description:
// Returns needed number of devices
//
// Parameters:
// hDMHandle [in] Device manager handle
// iCount [in,out] In: Number of allocated CONAPI_DEVICE structs.
// Out: Number of used CONAPI_DEVICE structs.
// pDevices [out] Pointer to receiving CONAPI_DEVICE structures.
//
// Return values:
// CONA_OK
// ECONA_INVALID_POINTER
// ECONA_INVALID_PARAMETER
// ECONA_NOT_INITIALIZED
// ECONA_UNKNOWN_ERROR
//
//=========================================================
public static extern int CONAGetDevices(
int hDMHandle,
ref int iCount,
System.IntPtr
pDevices);
[DllImport("ConnAPI", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
//=========================================================
// CONAGetDevice
//
// Description:
// Returns information about selected device
//
// Parameters:
// hDMHandle [in] Device manager handle
// pstrSerialNumber [in] Serial number of the device
// pDevice [out] Pointer to device struct
//
// Return values:
// CONA_OK
// ECONA_INVALID_POINTER
// ECONA_DEVICE_NOT_FOUND
// ECONA_NOT_INITIALIZED
// ECONA_UNKNOWN_ERROR
//
public static extern int CONAGetDevice(
int hDMHandle,
[MarshalAs(UnmanagedType.LPWStr)] string pstrSerialNumber,
System.IntPtr pDevice
);
[DllImport("ConnAPI", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
//=========================================================
//=========================================================
// CONAFreeDeviceStructure
//
// Description:
// CONAFreeDeviceStructure release the memory, which
// ConnectivitAPI is allocated inside CONAPI_DEVICE structs.
//
// Parameters:
// iCount [in] Number of used CONAPI_DEVICE structs
// pDevices [in] Pointer to CONAPI_DEVICE struct list
//
// Return values:
// CONA_OK
// ECONA_INVALID_POINTER
// ECONA_INVALID_PARAMETER
// ECONA_UNKNOWN_ERROR
//
//=========================================================
public static extern int CONAFreeDeviceStructure(
int iCount,
System.IntPtr pDevices);
[DllImport("ConnAPI", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
//=========================================================
// CONARefreshDeviceList
//
// Description:
// Starts device list refreshing. All changes are notified throught the
// notifications.
//
// Parameters:
// hDMHandle [in] Device manager handle
// iValue [in] Reserved for future use. Must be zero.
//
// Return values:
// CONA_OK
// ECONA_INVALID_PARAMETER
// ECONA_NOT_INITIALIZED
// ECONA_UNKNOWN_ERROR
//=========================================================
public static extern int CONARefreshDeviceList(
int hDMHandle,
int iValue
);
[DllImport("ConnAPI", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
//=========================================================
// CONARenameFriendlyName
//
// Description:
// Sets a new friendly name for the device
//
// Parameters:
// hDMHandle [in] Device manager handle
// pstrSerialNumber [in] Serial number of the device.
// pstrNewFriendlyName [in] New Device Friendly Name .
//
// Return values:
// CONA_OK
// ECONA_INVALID_POINTER
// ECONA_NAME_ALREADY_EXISTS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -