'this' pointer in vb.net 2005

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello
I have this code in c++.


Code:
void CRelCtrlDlg::OnViewfinder()
{
cErr = PR_RC_StartViewFinder(m_hCamera,(prContext)this);
}

type of 'prContext' is uint32.

what is point object of ''''this''''?
I need translate this code to vb.net 2005.
Are you know any solutions?
very thanks.
 
Farsad,

Still is "me", the exact equivalent for the C sharp languages.
You see that, because your class (type) has probably the name Sample.Form1.

This command below is in VB.Net by the way
(prContext)this

DirectCast(me,prContext)


Cor
 
Farsad said:
Hello
I have this code in c++.


Code:
void CRelCtrlDlg::OnViewfinder()
{
cErr = PR_RC_StartViewFinder(m_hCamera,(prContext)this);
}

type of 'prContext' is uint32.

what is point object of ''''this''''?
I need translate this code to vb.net 2005.
<snip>

What the code is doing is casting the current class reference (which
is, as pointed out by Cor, "Me" in VB) to another type, a uint32,
according to you (UInteger, in VB).

Unfortunatelly this can't be done in VB.Net (nor in C# or Managed C++,
as far as I know, unless you go unsafe, I guess).

You need to provide more information on this. How is
PR_RC_StartViewFinder(..) declared? If this is an external (non .Net)
API, then maybe you can twiddle its declaration, so it accepts a
managed pointer instead of a UInteger, or maybe something more
meaningfull (a window handle,perhaps) may be passed as parameter
instead of the invalid cast.

Regards,

Branco.
 
thanks Branco
I explanation this more:

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:

Public Shared Function ViewFinderCallBackFunc(ByVal CameraHandle As
System.UInt32, ByVal Context As System.UInt32, ByVal Size As System.UInt32,
ByRef pVFData As IntPtr) As System.UInt32
.... get picture
Return 0
End Function

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

perror = PSReCWrap.prRC_StartViewFinder(prHandle,????????????, AddressOf
ViewFinderCallBackFunc)
'C++ sample for up line is:
'cErr =
PR_RC_StartViewFinder( m_hCamera,(prContext)this,(prViewFinderCB*)ViewFinderCallBackFun);
End Sub

If I set 'me.handle' instead '(prContext)this' i get this error:
Unhandled exception at 0x0027e692 in Sample.exe: 0xC0000005: Access
violation writing location 0x00000001.

are you have any solution.
very thanks.
 
Farsad wrote:
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
');
<snip>

It seems, by its usage, that the 'Context' variable is an opaque
handler that would only have meaning to your callback function --
notice that I'm just guessing, here. It would be nice if you could post
any documentation on the original (C++) declaration.
now I create a sample program that work with PSReCWrap to get picture from
camera.
my sample code for viewfinder is:

Public Shared Function ViewFinderCallBackFunc(ByVal CameraHandle As
System.UInt32, ByVal Context As System.UInt32, ByVal Size As System.UInt32,
ByRef pVFData As IntPtr) As System.UInt32
... get picture
Return 0
End Function

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

perror = PSReCWrap.prRC_StartViewFinder(prHandle,????????????, AddressOf
ViewFinderCallBackFunc)
'C++ sample for up line is:
'cErr =
PR_RC_StartViewFinder( m_hCamera,(prContext)this,(prViewFinderCB*)ViewFinderCallBackFun);
End Sub
<snip>

Did you try simply passing 0 (zero) in place of Context to see what
happens? Are you using the Context variable in any way inside your
callback? Are you sure that it's the *Context* variable that is causing
the error you mentioned? -- for instance, the prHandle variable doesn't
seem to be initialized at all...

Feel free to post more information, because, right now, the current
information isn't enough to provide any kind of suggestion... =P

Regards,

Branco.
 
Farsad said:
I try this. but my problem not solve.
PSReCWrap.prRC_StartViewFinder(prHandle, DirectCast(Me, System.UInt32))
I get last error for 'Me'

I think you should describe in more detail what you are attempting to
archieve. Pointers do not much sense here and neither 'Me' in VB nor 'this'
in C# can be considered "pointers".
 
Farsad wrote:
pBufferSize = Nothing
pDeviceinfo = Nothing
perror = PSReCWrap.prGetDeviceInfo(prHandle, pBufferSize, pDeviceinfo)
perror = PSReCWrap.prInitiateReleaseControl(prHandle)
perror = PSReCWrap.prRC_StartViewFinder(prHandle, 0, _
AddressOf ViewFinderCallBackFunc)
I 99.9% sure! that prhandle is right becuase previous line
(prInitiateReleaseControl) work correctly and lens of my camera jumping.

As the documentation you sent me states, the second parameter to
PR_RC_StartViewFinder is user defined and probably is not used by the
SDK. From the documentation:

prCAPI PR_RC_StartViewFinder(
prHandle CameraHandle,
prContext Context,
prViewFinderCB* pViewFinderCB
);
Parameters
<snip>
Context [in] Specifies the data to be passed to the parameters
in the registered callback function. The client may use this
freely.
<snip>

Thus, the error you're experiencing either comes from a marshalling
error between .Net and the SDK when passing the address of the callback
function, or from a previous initialization error which you didn't
account for. I honestly doubt the first alternative. For the second
alternative, well, I notice that you don't actually check the error
code returned by each call to the SDK. For example, the call to
PR_GetDeviceInfo above is probably returning an error, because you pass
a value of 0 in pBufferSize, and this (according, again, to the
documentation) would cause an error code to be retrieved and the
initialization of pBufferSize to the correct value.

Therefore, I suggest you check the return code of each call to the SDK
previous to calling PR_RC_StartViewFinder to see if something comes up.

HTH.

Best Regards,

Branco.
 
thanks Branco.
I consequently think my erro comes from a marshalling
error between .Net and the SDK when passing the address of the callback
function.
I post this issue to new post "callback function error"

Best regards
Farsad
 
Back
Top