//******************************************************************** CPacketList::CPacketList(uint mutex_timeout, uint flags) : rx_pkt_list_top(0), rx_pkt_list_tail(0), eth_rx_queueing_enabled(false), hListAccessMutex(0), mutex_timeout_secs(mutex_timeout), // first_construct(false), rx_event_active(false), hdlRxEvent(0), reporting_func(NULL), rpt_private_data(NULL) { // ZeroMemory((char *) this, sizeof(CPacketList)) ; mutex_timeout_secs = mutex_timeout ; // wsprintfA(bfr, "EVENT%u", (uint) time(NULL)) ; if (!first_construct) { first_construct = true ; srand2(time(NULL)) ; // syslog("CPacketList: init rand2\n") ; } // rpt_private_data = NULL ; // reporting_func = NULL ; // make this default to TRUE eth_rx_queueing_enabled = (flags & EPL_QUEUEING_DISABLED) ? false : true ; if (flags & EPL_USE_RX_EVENT) { rx_event_active = true ; char bfr[40] ; // wsprintfA(bfr, "EVENT%u", (uint) time(NULL)) ; wsprintfA(bfr, "EVENT%u", (uint) rand2()) ; // syslog("CPacketList starting [%X] [%s]\n", flags, bfr) ; hdlRxEvent = CreateEventA(NULL, false, false, bfr) ; if (hdlRxEvent == NULL) syslog("CreateEvent: %s\n", get_system_message()) ; // else // syslog("hdlRxEvent handle created\n") ; } hListAccessMutex = CreateMutex(NULL, false, NULL) ; if (hListAccessMutex == NULL) { report_func("CreateMutex [CPacketList]: %s\n", get_system_message()) ; } else { // note: this is not actually an error! if (GetLastError() == ERROR_ALREADY_EXISTS) { report_func("CreateMutex [CPacketList]: mutex already exists!!\n") ; } } }
//**************************************************************************** void draw_init_screen(HWND hwnd) { // if (DialogBox (g_hinst, TEXT ("CreateBox"), hwnd, CreateDlgProc)) int result = DialogBox (g_hinst, MAKEINTRESOURCE(IDD_CREATEBOX), NULL, CreateDlgProc) ; if (result < 0) { syslog("Init: DialogBox: %s\n", get_system_message()) ; } }
//**************************************************************************** // These listview-header tooltips do not depend on the HWND for each // header column, which is fortunate since I don't know any of those handles! // Instead, according to the one example that I've found so far: // http://bb4w.wikispaces.com/List+View+with+header+tooltips // They then used a polling mechanism to check for cursor being within // one of the relevant headers. This seems like a pretty clutzy method // for solving this problem; I hope there's a better way somewhere... //**************************************************************************** bool CVListView::create_tooltips(uint max_width, uint popup_msec, uint stayup_msec) { if (hwndLViewToolTips != NULL) return true ; hwndLViewToolTips = ListView_GetToolTips(hwndVListView) ; // hwndLViewToolTips = CreateWindowEx(0, TOOLTIPS_CLASS, NULL, TTS_ALWAYSTIP, // CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, //lint !e569 // hwndVListView, NULL, GetModuleHandle(NULL), NULL); if (hwndLViewToolTips == NULL) { syslog("ToolTip CreateWindowEx: %s\n", get_system_message()) ; return false; } SendMessage(hwndLViewToolTips, TTM_SETMAXTIPWIDTH, 0, max_width) ; SendMessage(hwndLViewToolTips, TTM_SETDELAYTIME, TTDT_INITIAL, popup_msec) ; SendMessage(hwndLViewToolTips, TTM_SETDELAYTIME, TTDT_AUTOPOP, stayup_msec) ; if (hwndLVHdrToolTips != NULL) return true ; hwndLVHdrToolTips = ListView_GetToolTips(hwndVListView) ; // hwndLVHdrToolTips = CreateWindowEx(0, TOOLTIPS_CLASS, NULL, TTS_ALWAYSTIP, // CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, //lint !e569 // hwndVListView, NULL, GetModuleHandle(NULL), NULL); if (hwndLVHdrToolTips == NULL) { syslog("ToolTip CreateWindowEx: %s\n", get_system_message()) ; return false; } SendMessage(hwndLVHdrToolTips, TTM_SETMAXTIPWIDTH, 0, max_width) ; SendMessage(hwndLVHdrToolTips, TTM_SETDELAYTIME, TTDT_INITIAL, popup_msec) ; SendMessage(hwndLVHdrToolTips, TTM_SETDELAYTIME, TTDT_AUTOPOP, stayup_msec) ; // TOOLINFO ti; // ti.cbSize = sizeof(TOOLINFO); // ti.uFlags = TTF_SUBCLASS; // ti.hwnd = hwndLVHeader ; // // ti.uId = (UINT) target; // // ti.lpszText = msg ; // bool bresult = SendMessage(hwndLVHdrToolTips, TTM_ADDTOOL, 0, (LPARAM) &ti); // if (!bresult) { // syslog("TTM_ADDTOOL: %s\n", get_system_message()) ; // } return true; }
void error_dlg(const wstring& title, const Error& e) { wostringstream st; st << title << L'\n'; if (e.code != E_MESSAGE) { wstring sys_msg = get_system_message(e.code, get_lang_id()); if (!sys_msg.empty()) st << word_wrap(sys_msg, get_optimal_msg_width()) << L'\n'; } for (list<wstring>::const_iterator msg = e.messages.begin(); msg != e.messages.end(); msg++) { st << word_wrap(*msg, get_optimal_msg_width()) << L'\n'; } st << extract_file_name(widen(e.file)) << L':' << e.line; message(c_error_dialog_guid, st.str(), 0, FMSG_WARNING | FMSG_MB_OK); }
static void read_config_file(void) { int result ; // search for existing file. // 1. look in current directory // 2. if not found, search location of executable // 3. if not found, generate default file in location of executable // printf("seek local ini=%s\n", local_ini_name) ; result = read_ini_file(local_ini_name) ; if (result == 0) { return ; } // If search for local file failed, try location of executable, // if that isn't the local directory. // If global INI filename isn't present, give up on search. // This will usually mean that we are running under WinNT 4.0, // and the executable is already in the current directory. // Just write the file in the current directory. // printf("ininame=%s\n", ininame) ; // getchar() ; if (ininame[0] == 0) { strcpy(ini_path, local_ini_name) ; } // If global INI filename IS present, try to load it else { result = read_ini_file(ininame) ; if (result == 0) { return ; } strcpy(ini_path, ininame) ; } // If we couldn't open any existing INI files, // generate default file in appropriate location. result = write_default_ini_file(ini_path) ; if (result != 0) { // perror(ini_path) ; sprintf (tempstr, "path [%s]\n", ini_path); nputs (0xA, tempstr); sprintf (tempstr, "FindFirst: %s\n", get_system_message ()); nputs (0xA, tempstr); } // try to read again, after writing defaults read_ini_file(ini_path) ; }
//***************************************************************************** void CVListView::set_header_text(uint idx, char *msg) { HWND hwndHeader = ListView_GetHeader(hwndVListView); if (hwndHeader) { HDITEM item; item.mask = HDI_TEXT ; #ifdef UNICODE item.pszText = ascii2unicode(msg) ; item.cchTextMax = _tcslen(item.pszText) ; #else item.pszText = msg ; item.cchTextMax = strlen(msg) ; #endif item.fmt = HDF_STRING | HDF_CENTER ; Header_SetItem(hwndHeader, idx, &item); //lint !e522 } else { //lint !e550 Symbol 'item' (line 753) not accessed syslog("ListView_GetHeader: %s\n", get_system_message()) ; } }
//******************************************************************** // This mutex is released by: // ReleaseMutex(this_port->hEthRxBfrAccessMutex) ; //******************************************************************** int CPacketList::claim_list_mutex(void) { // let's time out after a few seconds and give up, // just in case something is wrong... // Later: we've found that when polling is running at a high rate // (as Ron likes to run it), and a user tries to send a command // via the command field, the user command may time out waiting for // polling to release the mutex. So I'm stretching out this timeout // to see if I can make sure commands successfully get through // even when polling is active. // uint wait_seconds = 3 ; uint wait_seconds = mutex_timeout_secs ; bool done = false ; while (!done) { wait_seconds-- ; DWORD mresult = WaitForSingleObject(hListAccessMutex, 1000) ; switch (mresult) { case WAIT_TIMEOUT: if (wait_seconds == 0) { report_func("CPacketList: cannot obtain mutex\n") ; return -(int)ERROR_BUSY; // used *only* for Mutex-acquisition failure!! } wait_seconds-- ; break; case WAIT_FAILED: mresult = GetLastError() ; report_func("CPacketList: WaitForSingleObject: %s\n", get_system_message(mresult)) ; return -(int)mresult; case WAIT_ABANDONED: report_func("CPacketList: WaitForSingleObject: operation abandoned\n") ; return -ERROR_INVALID_FUNCTION; default: // success: mutex was acquired done = true ; break; } // end switch } return 0; }
//*************************************************************************** // this will be needed for normal Ethernet Rx waiting //*************************************************************************** int CPacketList::wait_for_packet(u8 *rbfr, uint tmo_secs) { int result = 0 ; // DWORD dresult ; if (!rx_event_active) { return -(int) ERROR_INVALID_HANDLE; } // report_func("wait for eth RX packet [%u]\n", ) ; // DWORD rc = WaitForSingleObject(this_port->hdlRxEvent, tmo_secs * 1000) ; int done = 0 ; while (!done) { // if (user_abort_signalled(this_port)) // return -(int) ERROR_CANCELLED ; // if (dbg_flags & DBG_RX_DEBUG) // syslog("Wait Rx Event\n") ; // DWORD rc = WaitForSingleObject(hdlRxEvent, 1000) ; DWORD rc = WaitForSingleObject(hdlRxEvent, tmo_secs * 1000) ; // if (dbg_flags & DBG_RX_DEBUG) // syslog("Got Rx Event, rc=%u\n", (unsigned) rc) ; switch (rc) { case WAIT_OBJECT_0: //***************************************************************************** // this function has an interesting quirk... // Even though we've received an RxEvent, indicating that the event // had been signalled, and therefore there should be data on the queue, // get_packet_data() sometimes returns -ERROR_NOT_SAME_DEVICE, // indicating there is NO data on the queue. // Further, it appears to happen after some timeout period... // How could this happen? //***************************************************************************** // syslog("read comm resp: data ready, hdl=%u\n", (uint) hdlRxEvent) ; result = get_packet_data(rbfr) ; // pop list into rx_bfr // if (result < 0) { // DWORD dresult = GetLastError() ; // syslog("w4so: GLE=%u, R=%d, tsec=%u\n", (uint) dresult, result, tmo_secs) ; // } done = 1 ; break; case WAIT_TIMEOUT: // if packet timed out or errored out, // take a pass at processing the partial packet, // just in case we got everything except ETX result = -ERROR_SEM_TIMEOUT; done = 1 ; break; // if (tmo_secs == 0) { // result = -ERROR_SEM_TIMEOUT; // done = 1 ; // break; // } // // if timeout seconds have *not* counted down to 0, keep waiting // if (--tmo_secs == 0) { // result = -ERROR_SEM_TIMEOUT; // done = 1 ; // break; // } // break; // case WAIT_ABANDONED: // ummm... I don't know... default: if (rc == WAIT_ABANDONED) syslog("read comm resp: what does WAIT_ABANDONED mean??\n") ; else syslog("read comm resp: WaitForSingleObject [%u]: %d, [%u] %s\n", (uint) hdlRxEvent, rc, (uint) GetLastError(), get_system_message()) ; result = -ERROR_INVALID_DATA; done = 1 ; break; } } // while !done return result; }
//*********************************************************************** //lint -esym(1784, WinMain) int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { //*************************************************************** // note that szAppName is not a very unique name; if either: // 1. someone else created a mutex with this name, or // 2. Elsewhere in this, or some other program, we created // another mutex using szAppName, // then this would not have the results intended!! //*************************************************************** if (!WeAreAlone (szAppName)) { // The old technique: // We are already running, display message and quit // The new technique: // We are already running, switch to first instance HWND hOther = NULL; EnumWindows(searcher, (LPARAM) &hOther); if ( hOther != NULL ) { /* pop up */ SetForegroundWindow( hOther ); if ( IsIconic( hOther ) ) { /* restore */ ShowWindow( hOther, SW_RESTORE ); } /* restore */ } /* pop up */ return 0; } g_hinst = hInstance; //Plant seed for random number generator with system time time_t ti ; time(&ti) ; srand2((unsigned) ti); // sprintf(tempstr, "ti=%u, rand=%u", ti, rand()) ; // OutputDebugString(tempstr) ; // set up initial data structs // read_config_data() ; init_castle_contents() ; init_player() ; // hdlTopLevel = OpenProcess(PROCESS_ALL_ACCESS, false, _getpid()) ; HWND hwnd = CreateDialog(g_hinst, MAKEINTRESOURCE(IDD_MAIN_DIALOG), NULL, (DLGPROC) TermProc) ; if (hwnd == NULL) { syslog("CreateDialog: %s\n", get_system_message()) ; return 0; } HACCEL hAccel = LoadAccelerators(g_hinst, MAKEINTRESOURCE(IDR_ACCELERATOR1)); // [2920] hInstance=4194304, 4194304, 4194304 // syslog("hInstance=%u, %u, %u\n", // hInstance, // GetWindowLong(hwnd, GWL_HINSTANCE), // GetModuleHandle(NULL) // ); MSG Msg; while(GetMessage(&Msg, NULL,0,0)) { if(!TranslateAccelerator(hwnd, hAccel, &Msg) && !IsDialogMessage(hwnd, &Msg)) { // if(!IsDialogMessage(hwnd, &Msg)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } } return (int) Msg.wParam ; } //lint !e715