Trabajar con canalizaciones con nombre en Windows (C ++ / C #)

I have a C++ application that needs to send over images from a webcam in real-time to a C# application on the same PC. The C++ code cannot be called from the C# code so I need to implement communication via named pipes in order to send over the images.

I have never done any communications programming before and I was wondering how to approach this problem.

My first thoughts was to have the C++ application create the named pipe server on a separate thread, after creation the thread would wait continuously until a image is available to send. At that point it would send the image over.

Similarly the C# application would create a new thread that acts as the client. It would connect to the server and loop continuously until an image is available. At that point it would receive the image and store it in a queue that the main thread can access.

Does this make sense? Is this the best approach?

preguntado el 09 de marzo de 12 a las 15:03

Good question, but I think it belongs on This is more conceptual than those that typically belong here. -

if you have to store these images permanently, memory-mapped files will be probably a better approach. -

So on each frame in the C++ application I would store the entire image in a named memory mapped file which can then be read from the C# application? Would I still need to create a new thread on each side as above for handling reading and writing to the memory mapped files? -

Whatever solution you would use for transferring the data via a disk file will apply for a memory mapped file. Personally, I would wait for an Evento signal instead of creating a thread and polling. -

your idea sounds fine. alternatively if you are familiar with COM, you could make a COM component in c++ that .NET could access and would be reasonably fast. -

1 Respuestas

I second the notion of using COM here. I'd write the COM object in C#, frankly, because it's easier (than C++). C# has great COM interoperability. See I wrote a work-alike MS VSS COM interface that was callable by Python (our build system), interfacing with a C# .NET interface exposed by another vendor; because it was lowly COM, it was also callable from JScript, C++, etc.

Unless you're going inter-machine and/or need Windows security as part of this, I'd avoid named pipes, though what you actually use to transport across your object can be anything, probably dictated by the size/rate involved.

Respondido 18 Abr '12, 22:04

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.