I'm sill learning VS .NET 2003, not an expert yet.
I'm calling an unmanaged C++ DLL from C# using [DllImport()]. When the
whole project is done I will be calling a total of 5 C++ DLLs from C#. All
the DLLs have the same signature, and I never have to call more than one DLL
in the same program. (The DLLs parse and validate 5 different binary
formats.) Originally I was expecting to have 5 different C# programs as the
constants are different for each of 5 DLLs. But I figured out how to
dyanmically load the constants from XML files so now one C# program is all
that's needed. ;-) Color me 'Very Happy.'
What's the best way to late bind to an unmanaged DLL from C# code?
1. Although I find no MSDN or Google samples, it seems to me that one
'should' be able to (somehow) use a string in the class constructor.
[DllImport(string DllName)]
After all, the DLL does not have to be present for the C# build, and if I
forget to copy the Dll to the Debug folder the C# program runs fine up until
the call to the Dll. It's obviously late binding to the DLL so if e.g.
DllImportAttribute.DllFilename was exposed it could easily specified during
class construction. This desireable feature appears to have been left out
of .NET 2003.
2. Various newgroups threads suggest using Reflection. This is yet another
..NET feature I know exists but haven't studied.
3. This article purports to have an assembly language solution of 4
statements.
http://www.codeproject.com/csharp/dyninvok.asp
Thanks.
-- Mark