我正在尝试初始化 Canon EDSDK 的 API,但由于某种原因,err = EdsInitializeSDK() 没有返回正确的值“0”或 EDS_ERR_OK。这导致它跳过所有剩余的 if 语句。
这是代码:
Private Sub VBSample_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim err As Integer = EDS_ERR_OK
Dim cameraList As IntPtr = Nothing
Dim camera As IntPtr = Nothing
Dim count As Integer = 0
Dim isSDKLoaded As Boolean = False
Dim propObj As New CameraProperty
' connect property id to combobox.
m_cmbTbl.Add(kEdsPropID_AEMode, Me.AEModeCmb)
m_cmbTbl.Add(kEdsPropID_ISOSpeed, Me.ISOSpeedCmb)
m_cmbTbl.Add(kEdsPropID_Av, Me.AvCmb)
m_cmbTbl.Add(kEdsPropID_Tv, Me.TvCmb)
m_cmbTbl.Add(kEdsPropID_MeteringMode, Me.MeteringModeCmb)
m_cmbTbl.Add(kEdsPropID_ExposureCompensation, Me.ExposureCompCmb)
m_cmbTbl.Add(kEdsPropID_ImageQuality, Me.ImageQualityCmb)
err = EdsInitializeSDK()
If err = EDS_ERR_OK Then
isSDKLoaded = True
End If
If err = EDS_ERR_OK Then
err = EdsGetCameraList(cameraList)
End If
If err = EDS_ERR_OK Then
err = EdsGetChildCount(cameraList, count)
If count = 0 Then
err = EDS_ERR_DEVICE_NOT_FOUND
End If
End If
'// Get the first camera.
If err = EDS_ERR_OK Then
err = EdsGetChildAtIndex(cameraList, 0, camera)
End If
Dim deviceInfo As EdsDeviceInfo = Nothing
If err = EDS_ERR_OK Then
err = EdsGetDeviceInfo(camera, deviceInfo)
If err = EDS_ERR_OK And IsNothing(camera) = True Then
err = EDS_ERR_DEVICE_NOT_FOUND
End If
End If
If IsNothing(cameraList) = False Then
EdsRelease(cameraList)
End If
'// Create the camera model
If err = EDS_ERR_OK Then
model = cameraModelFactory(camera, deviceInfo)
If IsNothing(model) = True Then
err = EDS_ERR_DEVICE_NOT_FOUND
End If
End If
If err <> EDS_ERR_OK Then
MessageBox.Show("Cannot detect camera")
End If"
我认为我的 API 设置正确,但我可能是错的。
此代码可能会有所帮助:
Option Strict Off
Option Explicit On
Imports System.Runtime.InteropServices
Public Module EDSDK
'===================================================
'
' EDSDK.h
'
'===================================================
'/******************************************************************************
'*******************************************************************************
'//
'// initialize / terminate
'//
'*******************************************************************************
'******************************************************************************/
'/*-----------------------------------------------------------------------------
'//
'// Function: EdsInitializeSDK
'//
'// Description:
'// Initializes the libraries.
'// When using the EDSDK libraries, you must call this API once
'// before using EDSDK APIs.
'//
'// Parameters:
'// In: None
'// Out: None
'//
'// Returns: Any of the sdk errors.
'-----------------------------------------------------------------------------*/
Public Declare Function EdsInitializeSDK Lib "EDSDK" () As Integer"
当我解除该功能时,我应该做其他事情吗?