Click here to Skip to main content
15,902,883 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am writing a program that consists of 3 parts, the main dll, an .exe which runs as a service and a dll with common code and variables. The idea was that both the main dll and the exe call the common dll and share variables/constants. But it turns out they both open a seperate instance of the common dll, thus no sharing the variables. Is there a way to solve this and let them use a single instance of the common dll?
Thanks for any help

Mark
Posted

You can not share varibles across dlls. What you can do is, any data you want to share put it in external data storage area such as database, flat file.
 
Share this answer
 
Comments
Mark Oostveen 31-Aug-10 1:24am    
All possible constants I have put already in a configuration file, which is for 99% of my program sufficient. The only thing is I have one component, a videosource, to which I assign a usb webcam. This videosource I want to share across the dll and exe by using the common dll, but since they each open their own instance the videosource is not shared and since most (all?) usb webcams allow only one client, I end up either in the exe or in the main dll with a not connecting player....
Yusuf 31-Aug-10 9:30am    
OK then. One possible solution is to look for single instance DLL. They are relatively straight forward to do in C/C++, I am not sure about C#. You may want to look into it. Here is how you do for C/C++ - http://support.microsoft.com/default.aspx?scid=kb;en-us;109619
You tag your question with "C#", so I'll assume that when you say "DLL" you are implying ".Net assembly".

If that's the case, then any public static fields and/or properties, of public classes or structs, in the shared assemblies will be visible to any assemblies that reference them.
 
Share this answer
 
Comments
Mark Oostveen 31-Aug-10 1:25am    
no it is an actual dll I created, part of a server console. it indeed uses .net components, but in this case that doesn't matter. the videosource I tend to share is a public static field/property, but it appers not to be shared...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900