private static void LazyInitLibrary() { if (_dllAddress != IntPtr.Zero) { return; } // need absolute path for LoadLibraryW var path = Path.GetFullPath(DLLPath); if (!File.Exists(DLLPath)) { throw new InvalidOperationException($"Hand2Note Api dll \"{path}\" doesn't exist"); } var addr = WinApiHelper.LoadLibraryW(path); if (addr == IntPtr.Zero) { throw new InvalidOperationException($"Failed to load library \"{path}\": {WinApiHelper.GetLastError()}"); } _h2nIsRunning = (h2n_is_running)LoadDelegate <h2n_is_running>(addr, "h2n_is_running"); _h2nMakeTableName = (h2n_make_table_name)LoadDelegate <h2n_make_table_name>(addr, "h2n_make_table_name"); _h2nFreeCString = (h2n_free_cstring)LoadDelegate <h2n_free_cstring>(addr, "h2n_free_cstring"); _h2nSendHandHistory = (h2n_send_handhistory)LoadDelegate <h2n_send_handhistory>(addr, "h2n_send_handhistory"); _h2nSendHandStart = (h2n_send_hand_start)LoadDelegate <h2n_send_hand_start>(addr, "h2n_send_hand_start"); _h2nSendHandAction = (h2n_send_action)LoadDelegate <h2n_send_action>(addr, "h2n_send_action"); _h2nSendHandStreet = (h2n_send_street)LoadDelegate <h2n_send_street>(addr, "h2n_send_street"); _h2nSendCommand = (h2n_send_command)LoadDelegate <h2n_send_command>(addr, "h2n_send_command"); _dllAddress = addr; }