Hi
I have a dll file (PRSDK.dll) for canon camera sdk and wish create a wrapper
and sample program for this in vb.net.
I create a class (PSReCWrap) and declared wrapper in this.
my function in wrapper for get viewfinder is:
Public Delegate Function prViewFinderCB( ByVal CameraHandle As
System.UInt32, ByVal Context As System.UInt32, ByVal Size As System.UInt32,
ByRef pVFData As IntPtr) As System.UInt32
'C++ doe:
'typedef prResponse prSTDCALL prViewFinderCB (
' prHandle CameraHandle,
' prContext Context,
' prUInt32 Size,
' prVoid * pVFData
');
Declare Auto Function prRC_StartViewF inder Lib "PRSDK.dll" Alias
"PR_RC_StartVie wFinder" (ByVal CameraHandle As System.UInt32, ByVal Context
As System.UInt32, ByRef pViewFinderCB As prViewFinderCB) As Integer
'C++ doe:
'typedef prResponse prSTDCALL prRC_StartViewF inder(
' prHandle CameraHandle,
' prContext Context,
' prViewFinderCB* pViewFinderCB
');
now I create a sample program that work with PSReCWrap to get picture from
camera.
my sample code for viewfinder is:
Imports System.Runtime. InteropServices
<MarshalAs(Unma nagedType.Funct ionPtr)Private aa As PSReCWrap.prVie wFinderCB
Public Shared Function ViewFinderCallB ackFunc(ByVal CameraHandle As
System.UInt32, ByVal Context As System.UInt32, ByVal Size As System.UInt32,
ByRef pVFData As IntPtr) As Integer
'!!!!!!!! in this section i wish get viewfinder data from pVFData !!!!!!
Return 0
End Function
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
...
aa = New PSReCWrap.prVie wFinderCB(Addre ssOf ViewFinderCallB ackFunc)
**** perror = PSReCWrap.prRC_ StartViewFinder (prHandle, 0, aa)
Label1.Text = perror.ToString ("x")
End Sub
i get this error for **** line:
Unhandled exception at 0x0027e692 in Sample.exe: 0xC0000005: Access
violation writing location 0x00000001.
I thinks this error comes from a marshalling error between .Net and the SDK
when passing the address of the callback function. I sure send first and
second parameter correct becuase this my perevious line work correctly and my
camera lens jump.
are you have any solution.
very thanks.
I have a dll file (PRSDK.dll) for canon camera sdk and wish create a wrapper
and sample program for this in vb.net.
I create a class (PSReCWrap) and declared wrapper in this.
my function in wrapper for get viewfinder is:
Public Delegate Function prViewFinderCB( ByVal CameraHandle As
System.UInt32, ByVal Context As System.UInt32, ByVal Size As System.UInt32,
ByRef pVFData As IntPtr) As System.UInt32
'C++ doe:
'typedef prResponse prSTDCALL prViewFinderCB (
' prHandle CameraHandle,
' prContext Context,
' prUInt32 Size,
' prVoid * pVFData
');
Declare Auto Function prRC_StartViewF inder Lib "PRSDK.dll" Alias
"PR_RC_StartVie wFinder" (ByVal CameraHandle As System.UInt32, ByVal Context
As System.UInt32, ByRef pViewFinderCB As prViewFinderCB) As Integer
'C++ doe:
'typedef prResponse prSTDCALL prRC_StartViewF inder(
' prHandle CameraHandle,
' prContext Context,
' prViewFinderCB* pViewFinderCB
');
now I create a sample program that work with PSReCWrap to get picture from
camera.
my sample code for viewfinder is:
Imports System.Runtime. InteropServices
<MarshalAs(Unma nagedType.Funct ionPtr)Private aa As PSReCWrap.prVie wFinderCB
Public Shared Function ViewFinderCallB ackFunc(ByVal CameraHandle As
System.UInt32, ByVal Context As System.UInt32, ByVal Size As System.UInt32,
ByRef pVFData As IntPtr) As Integer
'!!!!!!!! in this section i wish get viewfinder data from pVFData !!!!!!
Return 0
End Function
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
...
aa = New PSReCWrap.prVie wFinderCB(Addre ssOf ViewFinderCallB ackFunc)
**** perror = PSReCWrap.prRC_ StartViewFinder (prHandle, 0, aa)
Label1.Text = perror.ToString ("x")
End Sub
i get this error for **** line:
Unhandled exception at 0x0027e692 in Sample.exe: 0xC0000005: Access
violation writing location 0x00000001.
I thinks this error comes from a marshalling error between .Net and the SDK
when passing the address of the callback function. I sure send first and
second parameter correct becuase this my perevious line work correctly and my
camera lens jump.
are you have any solution.
very thanks.
Comment