|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Dynamic Native LoadlibI understand that the means of explicitly linking against native code, is
with an attribute set like this: [System.Runtime.InteropServices.DllImport("winmm.DLL", EntryPoint = "PlaySound", SetLastError = true)] But what if you want the name of the DLL to be dynamic - that is - specified with a variable rather than a string literal? The above code doesn't compile if I insert a variable in lieu of the string literal for the DLL name. Is there a way to do that (perhaps with a different FCL service)? If it can't be done, I suppose the reason would be that the compiler wants to collect in advance some type info from the named native DLL, so that it can construct proper marshalling code. But who knows... Hello!
You wrote on Fri, 13 Oct 2006 11:53:01 -0700: M> But what if you want the name of the DLL to be dynamic - that is - M> specified with a variable rather than a string literal? The above code This (dynamic loading of the dll with the name defined in runtime) is supported only in .NET 2.0. You can make some kind of proxy native DLL if you need. Such DLL would load the desired DLL itself. With best regards, Eugene Mayevski http://www.SecureBlackbox.com - the comprehensive component suite for network security You said:
> This (dynamic loading of the dll with the name defined in runtime) is I am using .NET 2.0. (I have Visual Studio 2005 Team System). Could you > supported only in .NET 2.0. tell me what syntax or semantics adjustment I must make to use this feature? As I mentioned before, it does not compile if I use a variable. > You can make some kind of proxy native DLL if Yes, this is true. But if, as you suggest, .NET 2.0 is **inherently** > you need. Such DLL would load the desired DLL itself. capable of doing this - then please do share how its done. >I am using .NET 2.0. (I have Visual Studio 2005 Team System). Could you You can call the native LoadLibrary and GetProcAddress APIs, and then>tell me what syntax or semantics adjustment I must make to use this feature? >As I mentioned before, it does not compile if I use a variable. wrap the function pointer in a delegate with Marshal.GetDelegateForFunctionPointer. Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. Hello!
You wrote on Fri, 13 Oct 2006 13:08:02 -0700: M> I am using .NET 2.0. (I have Visual Studio 2005 Team System). Could you M> tell me what syntax or semantics adjustment I must make to use this M> feature? As I mentioned before, it does not compile if I use a M> variable. Right, there's another syntax there. Unfortunately I don't remember, which one exactly, cause we went a proxy route. With best regards, Eugene Mayevski http://www.SecureBlackbox.com - the comprehensive component suite for network security |
|||||||||||||||||||||||