Canon EDSDK code not returning proper values in visual basic
-
29-07-2022 - |
Pergunta
I am trying to initialize the API for Canon EDSDK, but for some reason the err = EdsInitializeSDK() is not returing the correct value "0" or EDS_ERR_OK. This is causing it to skip all of the remaning if statements.
Here is the code:
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"
I think I have the API set up correctly, but I could be wrong.
This code might be helpful:
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"
Should I be doing something else when I delare the function?
Nenhuma solução correta
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow