0

For the previous couple of years, I have developed user interfaces using MFC. The main reason being, the libraries used to interface with the cameras being used are only available in C++. Generally 60% of project time has been spent trying to build UIs with clunky MFC...

Lately, I have been looking into mixed-mode programming with the intention of developing interfaces and high level functions in C#. Whilst mixing this with the native C++ code required for hardware communication.

One component I would like to get some advice about, is the presentation of the camera data. From what I have read, the data would need to be provided to the managed UI code by the native code by means of some form of callback and marshalling the data into a form that the managed code can draw on a control (video display). From what I know of marshalling, it can be a time expensive procedure. So that leads me to the question, how safe (if at all possible), is it to provide the unmanaged code a handle to a control on which the video is to be presented, and have the unmanaged code section handle the drawing?

tuskcode
  • 317
  • 2
  • 14
  • For streaming camera data in form of a video into a control, [this](http://stackoverflow.com/questions/6737581/c-sharp-control-to-display-camera-video-with-directshow-net) question might give you some ideas. For non-video data (such as a control or state information data of your device), you have various options to get the data into your application, such as using a network socket or some pipe or other means of inter-process communications - or create/use a managed wrapper for your c-API. – BitTickler Oct 05 '14 at 09:31
  • Yeah I'm looking down the line of a managed wrapper. My question is about exposing the control for presentation. Can you make any comment about this? – tuskcode Oct 05 '14 at 09:35
  • I think how to do it best is driven by the communications design of the camera and its API. If the API is notification/event driven or if it is a poll-style API (getters). If that C-API has something like ``SetCameraZoomChangedCallback(pfunc)``, an active X (ATL) COM object might be an idea to wrap it and map those callbacks to Active X events. But maybe someone else has a more modern solution for that. – BitTickler Oct 05 '14 at 09:41
  • Sorry, when I say control, I am referring to a windows form control on which the video will be displayed. As far as hardware control goes, I have got a majority of the solution developed. Thanks for your input though – tuskcode Oct 05 '14 at 09:48
  • Not trying to persuade you to change your mind but would like to point out that you don't have to switch languages just to get away from the undeniable clunkiness of MFC, Qt and QML would be a viable alternative. – sjdowling Oct 05 '14 at 09:53
  • Might the answer to your question be as simple as...? Use System.Drawing.Bitmap and GetHBitmap() method, pass handle to your C-code, use GDI bitblit functions to render your camera data into the bitmap. – BitTickler Oct 05 '14 at 10:02
  • Wouldn't blame you for trying... I have wondered about using Qt, yet haven't taken the leap to understand what it is exactly, or more importantly introduce the idea to the rest of the dev. team. I will investigate ;) – tuskcode Oct 05 '14 at 10:03
  • Depending on how the camera is connected, the answer might as well be: "Don't use the C-API at all" - if it is a network-connection rather than some PCI camera or something. – BitTickler Oct 05 '14 at 10:14
  • Here a [link](http://stackoverflow.com/questions/113426/how-do-i-connect-to-a-usb-webcam-in-net) to the solution for a USB camera. – BitTickler Oct 05 '14 at 10:19

0 Answers0