private void Form1_Load(object sender, EventArgs e) { // Check if this is a 32 bit or 64 bit system if (IntPtr.Size == 4) { hMod = LoadLibrary("WinIo32.dll"); } else if (IntPtr.Size == 8) { hMod = LoadLibrary("WinIo64.dll"); } if (hMod == IntPtr.Zero) { MessageBox.Show("Can't find WinIo dll.\nMake sure the WinIo library files are located in the same directory as your executable file.", "DumpPort", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } IntPtr pFunc = GetProcAddress(hMod, "InitializeWinIo"); if (pFunc != IntPtr.Zero) { InitializeWinIoType InitializeWinIo = (InitializeWinIoType)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(InitializeWinIoType)); bool Result = InitializeWinIo(); if (!Result) { MessageBox.Show("Error returned from InitializeWinIo.\nMake sure you are running with administrative privileges and that the WinIo library files are located in the same directory as your executable file.", "DumpPort", MessageBoxButtons.OK, MessageBoxIcon.Error); FreeLibrary(hMod); this.Close(); } } btnGetValue_Click(this, null); }
private static void load() { // Check if this is a 32 bit or 64 bit system if (IntPtr.Size == 4) { hMod = LoadLibrary("WinIo32.dll"); } else if (IntPtr.Size == 8) { hMod = LoadLibrary("WinIo64.dll"); } if (hMod == IntPtr.Zero) { Console.WriteLine("Can't find WinIo dll.\nMake sure the WinIo library files are located in the same directory as your executable file."); } IntPtr pFunc = GetProcAddress(hMod, "InitializeWinIo"); if (pFunc != IntPtr.Zero) { InitializeWinIoType InitializeWinIo = (InitializeWinIoType)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(InitializeWinIoType)); bool Result = InitializeWinIo(); if (!Result) { Console.WriteLine("Error returned from InitializeWinIo.\nMake sure you are running with administrative privileges and that the WinIo library files are located in the same directory as your executable file."); FreeLibrary(hMod); } } }
public static void Init() { if (IntPtr.Size == 4) { hMod = LoadLibrary("WinIo32.dll"); } else if (IntPtr.Size == 8) { hMod = LoadLibrary("WinIo64.dll"); } if (hMod == IntPtr.Zero) { MessageBox.Show("Can't find WinIo dll.\nMake sure the WinIo library files are located in the same directory as your executable file.", "DumpPort"); } IntPtr pFunc = GetProcAddress(hMod, "InitializeWinIo"); if (pFunc != IntPtr.Zero) { InitializeWinIoType InitializeWinIo = (InitializeWinIoType)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(InitializeWinIoType)); bool Result = InitializeWinIo(); if (!Result) { MessageBox.Show("Error returned from InitializeWinIo.\nMake sure you are running with administrative privileges and that the WinIo library files are located in the same directory as your executable file.", "DumpPort"); FreeLibrary(hMod); } } }
public IOPortAccess() { switch (IntPtr.Size) { case 4: hMod = LoadLibrary("WinIo32.dll"); break; case 8: hMod = LoadLibrary("WinIo64.dll"); break; default: hMod = IntPtr.Zero; break; } if (hMod == IntPtr.Zero) { string msg = "Can't find WinIo.dll. Make sure the WinIo.dll library files are located in the same directory as your executable file."; Console.WriteLine(msg); // throw new Exception(msg); } IntPtr pFunc = GetProcAddress(hMod, "InitializeWinIo"); if (pFunc != IntPtr.Zero) { InitializeWinIoType InitializeWinIo = (InitializeWinIoType)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(InitializeWinIoType)); bool result = InitializeWinIo(); if (!result) { FreeLibrary(hMod); hMod = IntPtr.Zero; string msg = "Error returned from InitializeWinIo. Make sure you are running with administrative privilages are that WinIo library files are located in the same directory as your executable file."; Console.WriteLine(msg); // throw new Exception(msg); } } }