473,320 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

'this' pointer in vb.net 2005

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.
Jan 20 '07 #1
8 5063
me

Cor

"Farsad" <Fa****@discussions.microsoft.comschreef in bericht
news:CA**********************************@microsof t.com...
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.

Jan 20 '07 #2
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" <Fa****@discussions.microsoft.comschreef in bericht
news:3B**********************************@microsof t.com...
thanks core but 'me' can not convert to uint32.
I trannslate this to vb:
cErr = PSReCWrap.prRC_StartViewFinder(m_hCamera, Me)
But get this error:
Value of type 'Sample.Form1' cannot be converted to 'UInteger'.

"Cor Ligthert [MVP]" wrote:
>me

Cor

Jan 20 '07 #3
Farsad wrote:
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.

Jan 20 '07 #4
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*)ViewFin derCallBackFun);
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.
Jan 20 '07 #5

Farsad wrote:
<snip>
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*)ViewFin derCallBackFun);
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.

Jan 20 '07 #6
"Farsad" <Fa****@discussions.microsoft.comschrieb:
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".

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 20 '07 #7
Farsad wrote:
<snip>
pBufferSize = Nothing
pDeviceinfo = Nothing
perror = PSReCWrap.prGetDeviceInfo(prHandle, pBufferSize, pDeviceinfo)
perror = PSReCWrap.prInitiateReleaseControl(prHandle)
perror = PSReCWrap.prRC_StartViewFinder(prHandle, 0, _
AddressOf ViewFinderCallBackFunc)
<snip>
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.

Jan 21 '07 #8
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
Jan 27 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

51
by: BigMan | last post by:
Does the C++ standard define what should happen in case of NULL pointer dereferencing. If not, does it say that it is illegal? Where, if so, does it say it?
9
by: iceColdFire | last post by:
HI, I have a function as void f(int p) { return p++; } now I have created a function pointer as
7
by: Alfonso Morra | last post by:
Straight of the bat, I'll admit this is not a nice solution, it is dangerous (not type safe) etc,etc, I know what the perils are. I don't need a lecture on why what I'm doing is perilous - that is...
5
by: Stephen Mayes | last post by:
#include <stdio.h> #include <stdlib.h> #include <string.h> int main (void) { static char * contents = "Line1\nLine2\nLine3\nLine4"; FILE * tmp; char readbuf; size_t len, n = 0;
42
by: junky_fellow | last post by:
Consider an implementation that doesn't use all bits 0 to represent a NULL pointer. Let the NULL pointer is represented by 0x12345678. On such an implementation, if the value of NULL pointer is...
204
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 =...
28
by: Wonder | last post by:
Hello, I'm confused by the pointer definition such as int *(p); It seems if the parenthesis close p, it defines only 3 integers. The star is just useless. It can be showed by my program: ...
16
by: aegis | last post by:
Given the following: int a = 10; int *p; void *p1; unsigned char *p2; p = &a;
17
by: Charles Sullivan | last post by:
The library function 'qsort' is declared thus: void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)); If in my code I write: int cmp_fcn(...); int...
33
by: siliconwafer | last post by:
What is size of pointer in C on DOS? is it sizeof(int ) or size of (long int)? If this ans is present in FAQ pls direct me to tht ouestion
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.