blob: 80b6ee0361899bd09f95f024ba3a104c89984092 [file] [log] [blame]
Alexis Hetud73b8712018-09-21 15:14:43 -04001// 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 Forbes3d27f2e2018-09-26 09:24:39 -070017#if defined(_WIN32)
Alexis Hetud73b8712018-09-21 15:14:43 -040018#include "resource.h"
19#include <windows.h>
20
Alexis Hetud73b8712018-09-21 15:14:43 -040021#ifdef DEBUGGER_WAIT_DIALOG
22static 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
49static 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
60extern "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 Forbes3d27f2e2018-09-26 09:24:39 -070078#endif