DllImport and error handling

  • Thread starter Thread starter Torben Laursen
  • Start date Start date
T

Torben Laursen

I am calling a c++ dll using DllImport and is loading a number of functions.

I all work fine but I need the code to be able to react to a case where the
dll is missing or some of the functions are missing.
My C++ code looks like this:
if(!Dll_)
Dll_ = LoadLibrary(dllname_.c_str());
if(Dll_)
{
SetMixture_ = (tdSetMixture_*)GetProcAddress(Dll_, "SetMixture");
if(!SetMixture_)
///and so on

How to I write the same code in C#?

Thanks Torben
 
Hello, Torben!

TL> I all work fine but I need the code to be able to react to a case where
TL> the dll is missing or some of the functions are missing.
TL> My C++ code looks like this:
TL> if(!Dll_)
TL> Dll_ = LoadLibrary(dllname_.c_str());
TL> if(Dll_)
TL> {
TL> SetMixture_ = (tdSetMixture_*)GetProcAddress(Dll_, "SetMixture");
TL> if(!SetMixture_)
TL> ///and so on

TL> How to I write the same code in C#?

You will have to P/Invoke ( again DllImport ) on LoadLibrary and GetProcAddress functions to test if specified
function exists in the loaded module...
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
Back
Top