Working code in C++ for changing cameraport

I create this topic because I can’t use C++ code in Visual Studio to change the camera port, in order to have a stereoscopic vision.

I make a code in C# wich work well, but the one in C++, not so different doesn’t work.

Do you have any idea why it can’t work in C++ ?

PS : In attachment, you could find the program in C++.

Hi @Alwin

Generally speaking CS2SetCamPort will - if returning with a return value >= 0 that indicates success - generate a new image handle that holds the reference to an image that is linked to the port to which you wanted to switch (in your code this would be Image_D). The input handle will be altered as well: It will loose the connection to the device and remain a simple static image after a successful call to CS2SetCamPort. In your code, however, there are two problems:

  1. m_cvImg seems to refer to an Image control (judging from the presence of the LoadImage member function), and if you want to pass the content of that ActiveX control to CS2SetCamPort you need to invoke the GetImage() member function.
  2. Image_D is never used any more after the CS2SetCamPort call judging from the code snippet (in fact it seems to leak…) - but it contains the image you actually want!

Please try the following:

CS2SetCamPort(reinterpret_cast<IMG>(m_cvImg.GetImage()), 0, 2, Image_D);
return TRUE;

Note: You are switching to port 0 right after loading the driver. Unless camera 0 has already been claimed by a different process, the driver will already come up with camera 0 - you might want to check with CS2GetCamPort before switching whether there is in fact reason to switch.

Hi illusive,

Many thanks for your reply and your advices !

For the first point :
Yes I try to develop a graphic application, that’s why I use an Image controle.
But the fact is that I can’t use the GetImage() member function inside the CS2SetCamport, because the program can’t build it and return this error :

Error	C2664	'cvbres_t CS2SetCamPort(IMG,cvbval_t,cvbval_t,IMG &)' : impossible to convert the argument 1 from 'intptr_t' in 'IMG'

For the second point :
You’re right, and it seems that the code did’nt see any problem for those lines.

Thanks for correcting the port, I try many lines in this code and I forget this mistake to let it in initial conditions.

  1. my bad. That should of course have read
    CS2SetCamPort(reinterpret_cast<IMG>(m_cvImg.GetImage()), 0, 2, Image_D);
    (I did correct it in the above code sample just now)
  2. Dangling pointers are not a syntactical problem and therefore it’s ok for the compiler not to point this out (after all, the compiler has no idea what CS2SetCamPort is doing so it cannot judge whether there is a problem or not).

1.Many thanks for your help, it works right now.
I didn’t know the cast form before your answer, and I understand how it works.

  1. Ok thanks for this explanation. The code works fine.