473,225 Members | 1,209 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,225 software developers and data experts.

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

Jan 17 '06 #1
1 1971
J.,

First, I am curious, why must the DLL be in unmanaged C?

I'm not sure about matlab, to be honest, so I can't say whether or not
what I will propose will work.

However, you could write your component as a .NET component, then expose
it to COM, so unmanaged code can access it (matlab, and maybe fufill the
requirement that unmanaged code access it, which is why you might have said
the dll has to be in unmanaged code).

If you really can't write it in .NET, you could define a function
definition which you could duplicate in .NET through a delegate. When you
make the call to your functions in your DLL, then you can pass the delegate
in, and store it in the dll, calling it when there is an update.

So basically, you would have a method which takes the fields you want
notifications of, as well as a callback. Then, your dll would store the
function pointer (that's what it will look like to it) and then call it when
there is an update. On the .NET side, you have to make sure the object
instance that the method that the delegate refers to doesn't go out of scope
so it is not collected, and you don't have a memory access violation when
your unmanaged code calls back into managed code.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<jk*****@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
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

Jan 17 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Roy Pereira | last post by:
I have an application that is composed of a set of "Content" dlls and a viewer application. The viewer calls a standard set of functions that are present in all the dlls. I maintain this by...
8
by: Crash | last post by:
2 Questions, but first Consider this: I'm looking at a C++ class (patterned using the Singleton Design Pattern). It has some public and private operations. It runs quite happily seving the time...
3
by: zlst | last post by:
Many technological innovations rely upon User Interface Design to elevate their technical complexity to a usable product. Technology alone may not win user acceptance and subsequent marketability....
4
by: jm | last post by:
Consider: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconwhenshouldiimplementinterfacesinmycomponent.asp // Code for the IAccount interface module. public...
20
by: Ole Hanson | last post by:
I am accessing my database through an interface, to allow future substitution of the physical datastore - hence I would like to declare in my Interface that my DAL-objects implementing the...
25
by: lovecreatesbeauty | last post by:
Could you talk something about the general rules on the interface (function) design in C program that recognized publically? Or introduce some good advice of yourself. How do you think about...
2
by: stefan.moser | last post by:
Hi All, I'm having a problem implementing the Separated Interface pattern from Martin Fowler's book Patterns of Enterprise Application Architecture. I'm using C# in Visual Studio 2005. The...
9
by: Spam Catcher | last post by:
Hi all, Can anyone recommend any books for User Interface Engineer for Windows Forms application? At the company I work at, we've gone GUI component happy. Basically GUI tools (i.e....
3
by: eric.burgin | last post by:
I have not heavily used interfaces in the past so I am looking for advice. An interface may not be the best solution but it was the first idea I had and was working at first. Here is the...
0
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.