Background:
We have developed an C# MDI (Multi-Document Interface) application which
loads different assemblies/forms, so that the user can have many "applicatio n
windows" running within the same container. Some of these child forms need
to use legacy code from a mature product written in C, and we have achieved
this by compiling our C code into a DLL, and using DllImport directive to
reference the functions that we need. The C# applications are able to use
the functions perfectly, but we are now facing another challenge.
The Challenge:
The C code uses caching to reduce database access delays, and those caches
are simple linked lists or arrays that are global/static. While this
assumption worked well for our legacy application (which is comprised of
numerous stand alone executables that naturally have their own process
space), it doesn't work well for the MDI C# model. That is, two child forms
running inside the MDI would share those caches, since all the
assemblies/forms (and DLLs) share the same process space. However, for our
product, it is unacceptable for two MDI child forms to share the same data
cache (for example, the cached data may have been derived based on user
preferences that are specific to each child form).
Where We're Stuck:
We have been trying to load the DLL more than once into the MDI process
space, where each copy will have it's own static/global variables, and
therefore different cached data, but we were unsuccessful. We attempted
loading them through different Application Domains, but it looks like the
external reference is resolved only once per DLL and reused (i.e. all app
domains reference the same copy of the DLL in the MDI process space).
Of course, we could rewrite the C code to eliminate the global/static memory
assumptions, but this isn't feasible due to the amount/complexity of the
legacy code.
We've also considered managing multiple copies of the dll to overcome this
problem (we've tested this and it works), but we don't want to resort to a
hack like this unless we have no other choice.
The Question:
Does anybody know of a way to load multiple instances of the same unmanaged
C++ dll into the process space of a single C# application (using application
domains or some other technique)?
--
Chris 7 2109
Hi,
Based on my experience, the dll is loaded perprocess and that is why it is
called dynamical link library.
Anyway I will keep research the issue and give you a reply ASAP.
Best regards,
Perter Huang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
Hi
So far I think we have another approach is wrap the C++ dll in a COM EXE
out of proc server, so that every mdi children frame can create its own com
exe server.
Best regards,
Perter Huang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
Hi,
Thanks for the feedback.
MSDN documentation says "Access to in-process objects is much faster than to
out-of-process server objects because Automation does not need to make remote
procedure calls across the process boundary."
So we'd like to avoid this if there is an in-process technique that will
achieve the desired effect.
Thanks,
Chris
""Peter Huang" [MSFT]" wrote: Hi
So far I think we have another approach is wrap the C++ dll in a COM EXE out of proc server, so that every mdi children frame can create its own com exe server.
Best regards,
Perter Huang Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights.
Hi
I have confirmed with senior engineer that so far we may use COM
Server(EXE), because the dll is loaded per process.
Or I think we have change the dll design which will not be an good
alternative.
If you still have any concern, please feel free to post here.
Best regards,
Perter Huang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
Hi Peter,
Thanks for the reply and thanks for asking around. Your time/help is
greatly appreciated.
Concerning the COM server idea, we'd like to avoid an out-of-proc solution
as I mentioned in my last note.
What do you mean when you refer to changing the dll design?
Thanks,
Chris
""Peter Huang" [MSFT]" wrote: Hi
I have confirmed with senior engineer that so far we may use COM Server(EXE), because the dll is loaded per process. Or I think we have change the dll design which will not be an good alternative.
If you still have any concern, please feel free to post here.
Best regards,
Perter Huang Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights.
Hi
I am sorry I mean we can use a class member not global memeory to do the
data cache, so that we can make the dll a inproc com server, and each
instacne of the com object can have its own private data.
Best regards,
Perter Huang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
Hi Peter,
Thanks again for your help.
As you might appreciate, we're trying to get to a point where have all of
the information necessary to make an educated (management level) decision on
what path to take.
From your replies, it seems clear that we either need to change our code to
eliminate the global variables or we need to use an out-of-proc strategy to
be able to load multiple instances of the same dll.
In other words, there doesn't appear to be a way to load multiple instances
of the same dll within the context of a single process.
Before we close the book on the investigative stage, however, we're
wondering whether it would be worthwhile to officially raise this question
through MSDN technical support. Do you think that there's any chance that we
could learn more about the issue by doing this?
Thanks,
Chris
""Peter Huang" [MSFT]" wrote: Hi
I am sorry I mean we can use a class member not global memeory to do the data cache, so that we can make the dll a inproc com server, and each instacne of the com object can have its own private data.
Best regards,
Perter Huang Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: jarmopy |
last post by:
Hi,
I have made a service with C# and calling that service class from another C#
program with remoting.
(Referendes from the calling program)
That service class is configured so that garpage collection is not used in
this class.
(singleton class + override InitializeLifetimeService )
The service class uses C++ unmanaged function from dll (using DLLimport).
|
by: Bryan |
last post by:
I have a multi-threaded C# console application that uses WMI
(System.Management namespace) to make RPC calls to several servers (600+ )
and returns ScheduledJobs. The section of my code that performs the query
is contained in a delegate function that I execute via a second thread. On 1
or 2 of the 600+ servers the query hangs. I've tried to use Thread.Join()
coupled with a Thread.Abort() but this does not kill the thread.
Based on...
|
by: Jesse McGrew |
last post by:
Hi all,
I'm trying to make a plugin DLL for a third-party application, using
VC++ .NET 2003. This DLL acts as a bridge between the C++ plugin API of
the application, and my actual plugin code written in C#.
When the app calls my unmanaged functions, they work fine. But as soon
as my unmanaged functions call managed functions (in the same source
file!), the app reports an "unknown exception" error.
|
by: H.B. |
last post by:
Hi,
I need to make a function that can display data on my Managed C++ app and be
called by an unmanaged C++ DLL. Something like :
void Form1::Form1_Load(System::Object * sender, System::EventArgs * e)
{
MyDLLInit(MyAppDisplayFunction);
}
|
by: monika.saxena |
last post by:
Hi all,
In one of my projects which is a web based application in asp.net, a
third party tool - "Frontline Solver DLL" (It is an unmanaged DLL and
..NET is calling it using the PInvoke) is used. This DLL is used for
solving and optimizing some non linear problems.
Problem : The problem I am facing is as the solver runs and does the
| |
by: Leftie |
last post by:
Folks,
I'm trying to call an unmanaged function from VB.NET and
keep getting "Object reference not set to an instance of
an object" error.
The code that i wrote can be found at:
http://www.nomorepasting.com/paste.php?pasteID=5973
The dll (if some kind soul has the time to compile and run
the code) can be found at:
|
by: MC-Advantica |
last post by:
Does anyone have a simple "Hello World" like application that demonstrates
unmanaged C++ calling managed C++ developed in VS2005? I'm confused by many
posts as they discuss managed extensions from VS2003, and related techniques.
I have found managed to unmanaged technique very easy in VS2005, but have
not been able to build anything with unmanaged to managed calls. I have
legacy (unmanaged C++) that would like to leverage the .NET...
|
by: Amit Dedhia |
last post by:
Hi All
I have a VC++ 2005 MFC application with all classes defined as
unmanaged classes. I want to write my application data in xml format.
Since ADO.NET has buit in functions available for this, I want to use
it. Is it possible to call Managed class functions from Unmanaged
class? How to do it?
I did something like this.
I declared a managed class (in C++ CLI) called as MyManagedClass whose
|
by: Klaus |
last post by:
Hi,
I have an existing VC 6 MFC application which communicates asynchronly with
a VC 2005 managed code dll.
I use an unmanaged base class with virtual functions to access methods in
the MFC application.
Furthermore, I use a pointer to an unmanaged function to jump back into the
managed dll.
The managed part is basically a remoting enhancement which asynchronly
|
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= |
last post by:
I have a C# logging assembly with a static constructor and methods that is
called from another C# Assembly that is used as a COM interface for a VB6
Application. Ideally I need to build a file name based on the name of the
VB6 application. A second choice would be a file name based on the # COM
interface assembly. I have tried calling Assembly.GetCallingAssembly() but
this fails when I use the VB6 client. Is there a way to get this...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |