Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== 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:54by 127.0.0.1