int main(int argc, char **argv) { Args args(argc, argv, "DRIVER PORT BAUD"); Emulator *emulator = LoadEmulator(args); const DeviceConfig config = ParsePortArgs(args); args.ExpectEnd(); InitialiseIOThread(); Port *port = OpenPort(config, *emulator->handler); if (port == NULL) { delete emulator; fprintf(stderr, "Failed to open COM port\n"); return EXIT_FAILURE; } emulator->port = port; ConsoleOperationEnvironment env; emulator->env = &env; if (!port->WaitConnected(env)) { delete port; delete emulator; DeinitialiseIOThread(); fprintf(stderr, "Failed to connect the port\n"); return EXIT_FAILURE; } if (!port->StartRxThread()) { delete port; delete emulator; DeinitialiseIOThread(); fprintf(stderr, "Failed to start the port thread\n"); return EXIT_FAILURE; } while (port->GetState() != PortState::FAILED) Sleep(1000); delete port; delete emulator; DeinitialiseIOThread(); return EXIT_SUCCESS; }
// 'Main program' equivalent: the program execution "starts" here bool wxEmulatorApp::OnInit() { #if wxUSE_LOG wxLog::DisableTimestamp(); #endif // wxUSE_LOG wxInitAllImageHandlers(); wxString currentDir = wxGetCwd(); // Use argv to get current app directory m_appDir = wxFindAppPath(argv[0], currentDir, wxT("WXEMUDIR")); // If the development version, go up a directory. #ifdef __WXMSW__ if ((m_appDir.Right(5).CmpNoCase(wxT("DEBUG")) == 0) || (m_appDir.Right(11).CmpNoCase(wxT("DEBUGSTABLE")) == 0) || (m_appDir.Right(7).CmpNoCase(wxT("RELEASE")) == 0) || (m_appDir.Right(13).CmpNoCase(wxT("RELEASESTABLE")) == 0) ) m_appDir = wxPathOnly(m_appDir); #endif // Parse the command-line parameters and options wxCmdLineParser parser(sg_cmdLineDesc, argc, argv); int res; { wxLogNull log; res = parser.Parse(); } if (res == -1 || res > 0 || parser.Found(wxT("h"))) { #ifdef __X__ wxLog::SetActiveTarget(new wxLogStderr); #endif parser.Usage(); return false; } if (parser.Found(wxT("v"))) { #ifdef __X__ wxLog::SetActiveTarget(new wxLogStderr); #endif wxString msg; msg.Printf(wxT("wxWidgets PDA Emulator (c) Julian Smart, 2002 Version %.2f, %s"), wxEMULATOR_VERSION, __DATE__); wxLogMessage(msg); return false; } if (parser.Found(wxT("u"), & m_displayNumber)) { // Should only be number, so strip out anything before // and including a : character if (m_displayNumber.Find(wxT(':')) != -1) { m_displayNumber = m_displayNumber.AfterFirst(wxT(':')); } } if (parser.GetParamCount() == 0) { m_emulatorInfo.m_emulatorFilename = wxT("default.wxe"); } else if (parser.GetParamCount() > 0) { m_emulatorInfo.m_emulatorFilename = parser.GetParam(0); } // Load the emulation info if (!LoadEmulator(m_appDir)) { //wxMessageBox(wxT("Sorry, could not load this emulator. Please check bitmaps are valid.")); return false; } // create the main application window wxEmulatorFrame *frame = new wxEmulatorFrame(wxT("wxEmulator"), wxPoint(50, 50), wxSize(450, 340)); #if wxUSE_STATUSBAR frame->SetStatusText(m_emulatorInfo.m_emulatorTitle, 0); wxString sizeStr; sizeStr.Printf(wxT("Screen: %dx%d"), (int) m_emulatorInfo.m_emulatorScreenSize.x, (int) m_emulatorInfo.m_emulatorScreenSize.y); frame->SetStatusText(sizeStr, 1); #endif // wxUSE_STATUSBAR m_containerWindow = new wxEmulatorContainer(frame, wxID_ANY); frame->SetClientSize(m_emulatorInfo.m_emulatorDeviceSize.x, m_emulatorInfo.m_emulatorDeviceSize.y); // and show it (the frames, unlike simple controls, are not shown when // created initially) frame->Show(true); #ifdef __WXX11__ m_xnestWindow = new wxAdoptedWindow; wxString cmd; cmd.Printf(wxT("Xnest :%s -geometry %dx%d"), m_displayNumber.c_str(), (int) m_emulatorInfo.m_emulatorScreenSize.x, (int) m_emulatorInfo.m_emulatorScreenSize.y); // Asynchronously executes Xnest m_xnestPID = wxExecute(cmd); if (0 == m_xnestPID) { frame->Destroy(); wxMessageBox(wxT("Sorry, could not run Xnest. Please check your PATH.")); return false; } wxReparenter reparenter; if (!reparenter.WaitAndReparent(m_containerWindow, m_xnestWindow, wxT("Xnest"))) { wxMessageBox(wxT("Sorry, could not reparent Xnest..")); frame->Destroy(); return false; } #endif m_containerWindow->DoResize(); // success: wxApp::OnRun() will be called which will enter the main message // loop and the application will run. If we returned false here, the // application would exit immediately. return true; }
extern "C" HRESULT WINAPI DllUnregisterServer(void) { LoadEmulator(); return DirectInputModuleManager::Get().DllUnregisterServer(); }
extern "C" HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID FAR* ppv) { LoadEmulator(); return DirectInputModuleManager::Get().DllGetClassObject(rclsid, riid, ppv); }
extern "C" HRESULT WINAPI DllCanUnloadNow(void) { LoadEmulator(); return DirectInputModuleManager::Get().DllCanUnloadNow(); }
extern "C" HRESULT WINAPI DirectInput8Create(HINSTANCE hinst, DWORD dwVersion, REFIID riidltf, LPVOID *ppvOut, LPUNKNOWN punkOuter) { LoadEmulator(); return DirectInputModuleManager::Get().DirectInput8Create(hinst, dwVersion, riidltf, ppvOut, punkOuter); }