开发者

Is using COM right for me?

开发者 https://www.devze.com 2023-04-10 02:05 出处:网络
My work has an application written in VB6. I am tasked with writing another, different, application in C# .NET. I am not allowed to change the VB6 code, but I need to call a function (from my .NET app

My work has an application written in VB6. I am tasked with writing another, different, application in C# .NET. I am not allowed to change the VB6 code, but I need to call a function (from my .NET application) every time a particular function gets called in the VB6 application.

My boss recomme开发者_开发知识库nded using COM or DCOM for this task. I am not familiar with either of these topics, and am having trouble finding a tutorial that I can understand easily and that relates to my task.

Can I do this using COM or will I have to modify the existing VB6 code?


You need to expose the function in VB6 as COM (ActiveX DLL). This is straight forward. http://vb-helper.com/howto_activex_dll.html

Calling a COM Object is easy too. http://www.c-sharpcorner.com/UploadFile/psingh/CallingCOMComponentFromCSharp12022005231615PM/CallingCOMComponentFromCSharp.aspx


It sounds to me like you have a VB6 application whose source code should not be changed. Now every time a method in the VB6 application is called you also want to call a method in another component (C#).

The above is an assumption since your question is not 100% clear.

If that is the case and you can't change the VB6 application then you might be able to do something using COM Channel Hooks (assuming the VB6 app is composed of COM objects).

But that would be using C++ and low level COM which is probably something you don't want to do.


I think you are asking about invoking a method from your C# application from within your VB6 application. So we are talking about some form of inter-process communication (hence the comment about DCOM).

I've used .NET Remoting to replace DCOM in some applications by creating a COM-callable .NET library to act as the client with the remoting objects being hosted in a .NET application. Your VB6 application uses the objects, and the methods execute on the server.

BUT you will have to modify your VB6 application, at least a little, to inject the new calls to your .NET. Can you be more clear on the requirements to not change the VB6 application?

0

精彩评论

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

关注公众号