callback function error

G

Guest

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_StartViewFinder Lib "PRSDK.dll" Alias
"PR_RC_StartViewFinder" (ByVal CameraHandle As System.UInt32, ByVal Context
As System.UInt32, ByRef pViewFinderCB As prViewFinderCB) As Integer
'C++ doe:
'typedef prResponse prSTDCALL prRC_StartViewFinder(
' 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(UnmanagedType.FunctionPtr)> Private aa As PSReCWrap.prViewFinderCB

Public Shared Function ViewFinderCallBackFunc(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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
...
aa = New PSReCWrap.prViewFinderCB(AddressOf ViewFinderCallBackFunc)
**** 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.
 
A

Armin Zingler

Farsad said:
Declare Auto Function prRC_StartViewFinder Lib "PRSDK.dll" Alias
"PR_RC_StartViewFinder" (ByVal CameraHandle As System.UInt32, ByVal
Context As System.UInt32, ByRef pViewFinderCB As prViewFinderCB) As
Integer


I'm not sure, but i would try to pass the last argument "ByVal".

'C++ doe:
'typedef prResponse prSTDCALL prRC_StartViewFinder(
' prHandle CameraHandle,
' prContext Context,
' prViewFinderCB* pViewFinderCB
');




Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top