Alexis Hetu | d73b871 | 2018-09-21 15:14:43 -0400 | [diff] [blame] | 1 | // Copyright 2018 The SwiftShader Authors. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | // main.cpp: DLL entry point. |
| 16 | |
Chris Forbes | 3d27f2e | 2018-09-26 09:24:39 -0700 | [diff] [blame] | 17 | #if defined(_WIN32) |
Alexis Hetu | d73b871 | 2018-09-21 15:14:43 -0400 | [diff] [blame] | 18 | #include "resource.h" |
| 19 | #include <windows.h> |
| 20 | |
Alexis Hetu | d73b871 | 2018-09-21 15:14:43 -0400 | [diff] [blame] | 21 | #ifdef DEBUGGER_WAIT_DIALOG |
| 22 | static INT_PTR CALLBACK DebuggerWaitDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) |
| 23 | { |
| 24 | RECT rect; |
| 25 | |
| 26 | switch(uMsg) |
| 27 | { |
| 28 | case WM_INITDIALOG: |
| 29 | GetWindowRect(GetDesktopWindow(), &rect); |
| 30 | SetWindowPos(hwnd, HWND_TOP, rect.right / 2, rect.bottom / 2, 0, 0, SWP_NOSIZE); |
| 31 | SetTimer(hwnd, 1, 100, NULL); |
| 32 | return TRUE; |
| 33 | case WM_COMMAND: |
| 34 | if(LOWORD(wParam) == IDCANCEL) |
| 35 | { |
| 36 | EndDialog(hwnd, 0); |
| 37 | } |
| 38 | break; |
| 39 | case WM_TIMER: |
| 40 | if(IsDebuggerPresent()) |
| 41 | { |
| 42 | EndDialog(hwnd, 0); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | return FALSE; |
| 47 | } |
| 48 | |
| 49 | static void WaitForDebugger(HINSTANCE instance) |
| 50 | { |
| 51 | if(!IsDebuggerPresent()) |
| 52 | { |
| 53 | HRSRC dialog = FindResource(instance, MAKEINTRESOURCE(IDD_DIALOG1), RT_DIALOG); |
| 54 | DLGTEMPLATE *dialogTemplate = (DLGTEMPLATE*)LoadResource(instance, dialog); |
| 55 | DialogBoxIndirect(instance, dialogTemplate, NULL, DebuggerWaitDialogProc); |
| 56 | } |
| 57 | } |
| 58 | #endif |
| 59 | |
| 60 | extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) |
| 61 | { |
| 62 | switch(reason) |
| 63 | { |
| 64 | case DLL_PROCESS_ATTACH: |
| 65 | #ifdef DEBUGGER_WAIT_DIALOG |
| 66 | WaitForDebugger(instance); |
| 67 | #endif |
| 68 | break; |
| 69 | case DLL_THREAD_ATTACH: |
| 70 | case DLL_THREAD_DETACH: |
| 71 | case DLL_PROCESS_DETACH: |
| 72 | default: |
| 73 | break; |
| 74 | } |
| 75 | |
| 76 | return TRUE; |
| 77 | } |
Chris Forbes | 3d27f2e | 2018-09-26 09:24:39 -0700 | [diff] [blame] | 78 | #endif |