Calling unmanaged code
-
Hi all. I haven't found an answer to this through quite some googling and searching, so I hope someone can provide some tips. Here's the deal: How can you call unmanaged code from a C# app? Yeah, I know about a few ways to do it, but they all seem to rely on the DllImport attribute initialized with the name of the DLL to be called at compile-time. For instance: [DllImport("msvcrt.dll")] in my case, I will not know the name of the unmanaged dll to be called until run-time. The name of the dll will come from a config file. So, imagine string unmanagedDll = this.GetUnmanagedDllNameFromConfigFile(); and now, is there any way to *programmatically* do the equivalent of [DllImport(unmanagedDll)] ? Thanks in advance for any suggestion, F.O.R.
-
Hi all. I haven't found an answer to this through quite some googling and searching, so I hope someone can provide some tips. Here's the deal: How can you call unmanaged code from a C# app? Yeah, I know about a few ways to do it, but they all seem to rely on the DllImport attribute initialized with the name of the DLL to be called at compile-time. For instance: [DllImport("msvcrt.dll")] in my case, I will not know the name of the unmanaged dll to be called until run-time. The name of the dll will come from a config file. So, imagine string unmanagedDll = this.GetUnmanagedDllNameFromConfigFile(); and now, is there any way to *programmatically* do the equivalent of [DllImport(unmanagedDll)] ? Thanks in advance for any suggestion, F.O.R.
You might want to have a look at this article: [http://www.codeproject.com/csharp/dyninvok.asp](http://
http://www.codeproject.com/csharp/dyninvok.asp)[[^](http://
http://www.codeproject.com/csharp/dyninvok.asp)] -
You might want to have a look at this article: [http://www.codeproject.com/csharp/dyninvok.asp](http://
http://www.codeproject.com/csharp/dyninvok.asp)[[^](http://
http://www.codeproject.com/csharp/dyninvok.asp)]Thanks, that might be just what I was looking for. F.O.R.