K
K
kot2204872014-07-11 18:30:35
Visual Basic
kot220487, 2014-07-11 18:30:35

Is it possible to put the path to the included dll into some external file?

In the VB.net project, I include the dll like this:

<DllImport("dll.dll",
               EntryPoint:="Test",
               SetLastError:=True,
               CharSet:=CharSet.Ansi,
               ExactSpelling:=True,
               CallingConvention:=CallingConvention.Cdecl
              )>

Is it possible to somehow replace the path and the dll itself with a variable that would be initialized from some configuration file? For example, having one project on vb.net and a set of library versions, switch between them. (The solution is of interest for any dll)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sumor, 2014-07-11
@Sumor

An unmanaged dll can be loaded dynamically via LoadLibrary by specifying the path to it.
The order is something like this:
1. LoadLibrary with the path to the dll.
2. GetProcAddress gets an unmanaged function pointer in the dll.
3. Marshal.GetDelegateForFunctionPointer converts an unmanaged function pointer into a delegate that can be used in the usual C# way.
4. FreeLibrary exits the dll.
More details and with an example
Well, you need to work with managed ones through the Assembly class.
For example, loading an assembly is Assembly.LoadFrom(string)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question