Click here to Skip to main content
15,844,673 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I have an unmanaged DLL (written in C++) and going to call it from the managed code through the P/Invoke.

DLL implements a sort of "gateway" to the stock trading server and is written so that at first we should establish a connection to the required trading server (host, port, login, password, etc.) and then we can do some other operations (e.g. send trading orders).
The problem is that DLL is not reentrant at all by its design - there can only be a single connection (no connection IDs, etc. are used in further function calls - they all are implied to be done on that connection we have initially established). Looks like it keeps its current connection state in its static variables and use them later. Buy I need 2 connections to 2 different servers.

My question is - is it possible to load 2 "instances" of the same DLL to the same .NET process so they would have different sets of its internal static variables ("connection states")? Maybe if we create another AppDomain another instance of DLL will be loaded into it?

Or the only way out is to launch separate .NET processes - one per connection required?

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