简体   繁体   中英

Working with named pipes in 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?

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 http://msdn.microsoft.com/en-us/library/aa645712%28v=vs.71%29.aspx . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM