Friday, August 27, 2010

How to: Determining programmatically if DLL is registered

Here is a C# code snippet to determine if a particular DLL is registered or not.

[DllImport("kernel32")]

public extern static int LoadLibrary(string lpLibFileName); 

[DllImport("kernel32")]

public extern static bool FreeLibrary(int hLibModule); 

public bool IsDllRegistered(string DllName)

{

      int libId = LoadLibrary(DllName);

      if (libId>0) FreeLibrary(libId);

      return (libId>0);

} 

Source: http://blogs.msdn.com/asanto

No comments: