blog:unmanagedcodeinvokation

no way to compare when less than two revisions

Differences

This shows you the differences between two versions of the page.


blog:unmanagedcodeinvokation [2009/11/27 17:54] (current) – created - external edit 127.0.0.1
Line 1: Line 1:
 +====== Unmanaged code invokation ======
  
 +When making an unmanaged call if the imported DLL does not exist you program will crash. Its much better to first check to see if the DLL is there. Here is a snippet in C#.
 +
 +<code csharp>
 +public const string AVR309DLL = "AVR309.DLL";
 +[DllImport(AVR309DLL)]
 +public static extern int DoGetInfraCode(ref byte[] TimeCodeDiagram, ref int DiagramLength);
 +</code>
 +
 +How to we make sure the AVR309DLL library exists?
 +
 +<code csharp>
 +[DllImport ("kernel32.dll")]
 +private extern static IntPtr LoadLibrary(string fileName);
 +
 +
 +[DllImport("kernel32.dll")]
 +private extern static IntPtr FreeLibrary(IntPtr hModule);
 +
 +
 +public static bool isDLLAvailable()
 +{
 +  IntPtr hModule = LoadLibrary(AVR309DLL);
 +  bool result = hModule.ToInt32() > 32;
 +  if(result) FreeLibrary(hModule);
 +  return result;
 +}
 +</code>
 +
 +{{tag>csharp programming}}x
  • blog/unmanagedcodeinvokation.txt
  • Last modified: 2009/11/27 17:54
  • by 127.0.0.1