Hooking into old DLL
-
I am fairly new to C# and .NET, so please bear with me. I have an old DLL, written by a 3rd party, so not sure if its vb6 or C or what. I need the ability to do late binding on this dll, set up to 300 properties contained in the dll, and then call the methods it exposes. I have read a bit on reflection, but not sure if this works with setting properties of an object or not. Has anyone done this before that could breifly explain what I would need to do, or can anyone point me in the right direction to read up on this? Thank You.
-
I am fairly new to C# and .NET, so please bear with me. I have an old DLL, written by a 3rd party, so not sure if its vb6 or C or what. I need the ability to do late binding on this dll, set up to 300 properties contained in the dll, and then call the methods it exposes. I have read a bit on reflection, but not sure if this works with setting properties of an object or not. Has anyone done this before that could breifly explain what I would need to do, or can anyone point me in the right direction to read up on this? Thank You.
First, determine whether it's a COM dll. If it is, just go into your Visual Studio project, right-click on the References folder, and Add Reference to the the COM dll. What's happening under the hood is that the tlbimp tool included in the .NET SDK is generating a .NET wrapper over your COM dll automagically. Now, if it's not a COM dll, if it's just a standard C/C++ dynamic link library, you have 2 options. One is to use P/Invoke to call functions in the dll. If you want to do that, see this page[^]. And the last option is more work, but ultimately faster and cleaner than using P/Invoke: build a seperate C++/CLI (managed C++) dll that talks to the old C dll, and exposes its functionality through .NET functions. Your C# code can talk to the C++/CLI dll natively, as if it were written in C#. If you want to do that, look at this article[^].
Tech, life, family, faith: Give me a visit. I'm currently blogging about: For Christians: The Significance of Yom Teruah The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
-
First, determine whether it's a COM dll. If it is, just go into your Visual Studio project, right-click on the References folder, and Add Reference to the the COM dll. What's happening under the hood is that the tlbimp tool included in the .NET SDK is generating a .NET wrapper over your COM dll automagically. Now, if it's not a COM dll, if it's just a standard C/C++ dynamic link library, you have 2 options. One is to use P/Invoke to call functions in the dll. If you want to do that, see this page[^]. And the last option is more work, but ultimately faster and cleaner than using P/Invoke: build a seperate C++/CLI (managed C++) dll that talks to the old C dll, and exposes its functionality through .NET functions. Your C# code can talk to the C++/CLI dll natively, as if it were written in C#. If you want to do that, look at this article[^].
Tech, life, family, faith: Give me a visit. I'm currently blogging about: For Christians: The Significance of Yom Teruah The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
I have added a reference to the dll, and that works fine. However, I need to do late binding on the dll. The possibility exists that when the application is installed, the dll may not be present. If I have a reference to the dll, and it is not there, will the application error out if I dont use the dll?
-
I have added a reference to the dll, and that works fine. However, I need to do late binding on the dll. The possibility exists that when the application is installed, the dll may not be present. If I have a reference to the dll, and it is not there, will the application error out if I dont use the dll?
No, the application won't error out because what you're *really* done is create a new .NET wrapper dll around the COM dll. Your application will be distributed with the .NET wrapper dll, and your application will function fine. However, if you call into the .NET wrapper dll, which in turn tries to call into the COM dll, then that function call will fail with an exception.
Tech, life, family, faith: Give me a visit. I'm currently blogging about: For Christians: The Significance of Yom Teruah The apostle Paul, modernly speaking: Epistles of Paul Judah Himango