佳能EDSDK代码在visual basic中没有返回正确的值

时间:2013-11-08 22:29:17

标签: edsdk

我正在尝试初始化Canon EDSDK的API,但由于某种原因,err = EdsInitializeSDK()没有返回正确的值“0”或EDS_ERR_OK。这导致它跳过所有remaning 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"

当我取消功能时,我应该做些什么吗?

0 个答案:

没有答案