The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

C# Interface to C DLL Interface Design Questions

I am having trouble designing an interface between the managed and unmanaged layers of an application I'm writing.

My application has two parts.  A C DLL that generates key/value pairs (the same 300 keys have new values 10 times a second), and a C# application that processes those values.  Some metadata gets generated every update as well.  The DLL must be unmanaged C.

My question is, how should I transfer the values from the C DLL to the C# app?  A hashtable seems like the obvious choice, but I don't know that one can be marshaled.  Should I register a list of keys I'm interested in with the C DLL, and then use a structure to get back the values (as an array), plus the metadata?

And how do I notify the C# application that new data has arrived?  A callback is my first inclination, though from googling it sounds like callbacks to unmanaged code is hard in .NET.  Polling or some type of messaging system are the only other alternatives I see, and I'm worried I'll miss update cycles with those.

Another thing to consider is this C DLL may need to be used in a matlab application as well.  I don't know much about matlab programming, but does this limitation preclude me from using callbacks (or any of your suggestions)?

Any help/suggestions would be greatly appreciated.  Thank you.

J. Kimmel
J. Kimmel Send private email
Tuesday, January 17, 2006
 
 
What about the following:  (Maybe I don't understand the problem)

Pass an array of 'keys of interest (is this some kind of tag)' to the DLL (do this once)
Have the DLL build an array of results everytime they're available, and add this array to a circular buffer
(Keep the order of this results array the same as the order of the tags)
Whenever you can, request an array of results from the DLL.  (Pass an empty array into the DLL and copy to it in C)
Use a Win32 event to signal that there's new results available so that the C# app doesn't have to poll. 

The circular buffer will stop you losing results if the C# can't always keep up.
Will Dean Send private email
Wednesday, January 18, 2006
 
 
+1 Will. In other words, you are queueing up the results in the C DLL and polling them from your C# component.
Anon and anon
Wednesday, January 18, 2006
 
 
It is possible to call C# functions from unmanaged DLL. Just do it.

Most probably interface for Matlab will be different.
Andrei Send private email
Thursday, January 19, 2006
 
 
Take a look at http://sourceforge.net/projects/libcurl-net
Start with a focus on the Easy.cs and LibCurlShim.c files.
Jeff Phillips Send private email
Wednesday, January 25, 2006
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz