source: trunk/src/win16ldr/odin.c@ 5954

Last change on this file since 5954 was 5954, checked in by sandervl, 24 years ago

Preliminary verison of win16 loader

File size: 3.6 KB
Line 
1#include <windows.h>
2#include <stdlib.h>
3#include <string.h>
4#include <stdio.h>
5#include <string.h>
6#include "peexe.h"
7
8HINSTANCE hinstApp;
9HWND hwnd;
10HINSTANCE hDll;
11
12long FAR PASCAL __export MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
13BOOL InitApplication(HANDLE hInstance);
14BOOL InitInstance(HANDLE hInstance, int nCmdShow);
15HANDLE hModule = 0;
16
17
18//*****************************************************************************************
19//*****************************************************************************************
20int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
21{
22 MSG msg;
23
24 if (!hPrevInstance)
25 if (!InitApplication(hInstance))
26 return (FALSE);
27
28 if (!InitInstance(hInstance, nCmdShow))
29 return (FALSE);
30
31 while(*lpCmdLine == ' ') lpCmdLine++;
32
33 hModule = WinExec(lpCmdLine, SW_SHOW);
34
35 if(hModule >= 32) {
36 while (GetMessage(&msg, NULL, NULL, NULL))
37 {
38 TranslateMessage(&msg);
39 DispatchMessage(&msg);
40 }
41 }
42 else {
43 char errormsg[256];
44
45 sprintf(errormsg, "WinExec %s failed with error %d", lpCmdLine, hModule);
46 MessageBox(hwnd, errormsg, "Ïnternal Error", MB_ICONHAND);
47 DestroyWindow(hwnd);
48 }
49
50 FreeLibrary(hDll);
51 return (msg.wParam);
52}
53//*****************************************************************************************
54//*****************************************************************************************
55BOOL InitApplication(HANDLE hInstance)
56{
57 WNDCLASS wc;
58
59 hDll = LoadLibrary("odindll.dll");
60 if(hDll == 0) {
61 return 0;
62 }
63
64 wc.style = NULL;
65 wc.lpfnWndProc = MainWndProc;
66 wc.cbClsExtra = 0;
67 wc.cbWndExtra = 0;
68 wc.hInstance = hInstance;
69 wc.hIcon = 0;
70 wc.hCursor = 0;
71 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
72 wc.lpszMenuName = NULL;
73 wc.lpszClassName = "Win16OdinClass";
74
75 return (RegisterClass(&wc));
76}
77//*****************************************************************************************
78//*****************************************************************************************
79BOOL InitInstance(HANDLE hInstance, int nCmdShow)
80{
81 hinstApp = hInstance;
82
83 hwnd = CreateWindow(
84 "Win16OdinClass",
85 "Odin Win16 Program Launcher",
86 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
87 CW_USEDEFAULT,
88 CW_USEDEFAULT,
89 CW_USEDEFAULT,
90 CW_USEDEFAULT,
91 NULL,
92 NULL,
93 hInstance,
94 NULL
95 );
96
97 if (!hwnd)
98 return (FALSE);
99
100 return (TRUE);
101
102}
103//*****************************************************************************************
104//*****************************************************************************************
105long FAR PASCAL __export MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
106{
107 char modname[256];
108
109 switch (message) {
110 case WM_CREATE:
111 SetTimer(hWnd, 1234, 500, NULL);
112 return 0;
113
114 case WM_TIMER:
115 if(GetModuleFileName(hModule, modname, sizeof(modname)) == 0) {
116 KillTimer(hWnd, 1234);
117 DestroyWindow(hWnd);
118 }
119 break;
120
121 case WM_DESTROY:
122 PostQuitMessage(0);
123 break;
124
125 default:
126 return (DefWindowProc(hWnd, message, wParam, lParam));
127 }
128 return (NULL);
129}
130//*****************************************************************************************
131//*****************************************************************************************
Note: See TracBrowser for help on using the repository browser.