开发者

Create multiple instances of same OCX

开发者 https://www.devze.com 2023-02-07 11:48 出处:网络
I have to load a couple of OCX libraries to access legacy code. I am creating the instance using Activator.CreateInstance:

I have to load a couple of OCX libraries to access legacy code. I am creating the instance using Activator.CreateInstance:

var type = Type.GetTypeFromProgID(ProgId);
var comObject = Activator.CreateInstance(type);

Unfortunately Activator.CreateInstance see开发者_开发问答ms to create only one instance per ProgId, however I need multiple instances with different configurations.

Example: Assuming I am using an OCX wich allows to set a value:

var instance1 = Create(progId);
Set(instance1, "key", "1");
var value1 = Get(instance1, "key"); // returns 1

var instance2 = Create(progId);
Set(instance2, "key", "2"); 
var value2 = Get(instance2, "key"); // returns 2

var value3 = Get(instance1, "key"); // returns 2

I need a way to instantiate one OCX (same ProgId) control multiple times without getting handed references to just one instance.


Problem has been solved by changing the OCX to not use global variables. Thanks Hans Passant.

0

精彩评论

暂无评论...
验证码 换一张
取 消