1 | #ifdef WATCOMC
|
---|
2 | #include <windows.h>
|
---|
3 | #else
|
---|
4 | #include "msc60win.h"
|
---|
5 | #endif
|
---|
6 | //#include <ddeml.h>
|
---|
7 | #include <stdlib.h>
|
---|
8 | #include <string.h>
|
---|
9 | #include <stdio.h>
|
---|
10 | #include <string.h>
|
---|
11 | #include "peexe.h"
|
---|
12 |
|
---|
13 | HINSTANCE hinstApp;
|
---|
14 | HWND hwnd;
|
---|
15 | HINSTANCE hDll;
|
---|
16 |
|
---|
17 | long FAR PASCAL __export MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
|
---|
18 | BOOL InitApplication(HANDLE hInstance);
|
---|
19 | BOOL InitInstance(HANDLE hInstance, int nCmdShow);
|
---|
20 | HANDLE hModule = 0;
|
---|
21 |
|
---|
22 | typedef void (FAR * PASCAL FUNC_SetPELdr)(LPCSTR);
|
---|
23 |
|
---|
24 | #ifdef DDE_COMM
|
---|
25 | HDDEDATA CALLBACK MyDdeCallback(UINT wType, UINT wFmt, HCONV hConv, HSZ hsz1, HSZ hsz2, HDDEDATA hData, DWORD dwData1, DWORD dwData2);
|
---|
26 |
|
---|
27 | DWORD idInst = 0;
|
---|
28 | HSZ hszServer = 0, hszTopic = 0;
|
---|
29 |
|
---|
30 | #define MSG_DDE_WILDCONNECT WM_USER+1
|
---|
31 | #define MSG_DDE_CONNECT WM_USER+2
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | //*****************************************************************************************
|
---|
35 | //*****************************************************************************************
|
---|
36 | int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
|
---|
37 | {
|
---|
38 | MSG msg;
|
---|
39 | FUNC_SetPELdr pfnSetPELdr;
|
---|
40 | char szPEPath[260];
|
---|
41 | LPSTR tmp;
|
---|
42 |
|
---|
43 | hDll = LoadLibrary("odindll.dll");
|
---|
44 | if(hDll == 0) {
|
---|
45 | return 0;
|
---|
46 | }
|
---|
47 |
|
---|
48 | pfnSetPELdr = (FUNC_SetPELdr)GetProcAddress(hDll, "SETPELDR");
|
---|
49 | if(pfnSetPELdr == NULL) {
|
---|
50 | return 0;
|
---|
51 | }
|
---|
52 | //check if the caller specified the path of the PE loader; if so, pass
|
---|
53 | //it on to odindll
|
---|
54 | tmp = strstr(lpCmdLine, "/PELDR=[");
|
---|
55 | if(tmp) {
|
---|
56 | tmp += 8; //skip /peldr=[
|
---|
57 | strcpy(szPEPath, tmp);
|
---|
58 | tmp = szPEPath;
|
---|
59 |
|
---|
60 | while(*tmp != ']' && *tmp != 0) tmp++;
|
---|
61 |
|
---|
62 | if(*tmp == ']') {
|
---|
63 | *tmp = 0;
|
---|
64 | pfnSetPELdr(szPEPath);
|
---|
65 | }
|
---|
66 |
|
---|
67 | //now skip this parameter
|
---|
68 | tmp = strstr(lpCmdLine, "/PELDR=[");
|
---|
69 | while(*tmp != ']' && *tmp != 0) tmp++;
|
---|
70 | if(*tmp == ']') {
|
---|
71 | tmp++;
|
---|
72 | }
|
---|
73 | lpCmdLine = tmp;
|
---|
74 | }
|
---|
75 |
|
---|
76 | if (!hPrevInstance)
|
---|
77 | if (!InitApplication(hInstance))
|
---|
78 | return (FALSE);
|
---|
79 |
|
---|
80 | if (!InitInstance(hInstance, nCmdShow))
|
---|
81 | return (FALSE);
|
---|
82 |
|
---|
83 | #ifdef DDE_COMM
|
---|
84 | if(DdeInitialize(&idInst, MyDdeCallback, APPCLASS_STANDARD, 0) != DMLERR_NO_ERROR) {
|
---|
85 | return FALSE;
|
---|
86 | }
|
---|
87 | hszServer = DdeCreateStringHandle(idInst, "Win16OdinServer", CP_WINANSI);
|
---|
88 | if(hszServer == 0) {
|
---|
89 | return FALSE;
|
---|
90 | }
|
---|
91 | hszTopic = DdeCreateStringHandle(idInst, "Win16Broadcast", CP_WINANSI);
|
---|
92 | if(hszTopic == 0) {
|
---|
93 | return FALSE;
|
---|
94 | }
|
---|
95 | if(DdeNameService(idInst, hszServer, 0, DNS_REGISTER) == 0) {
|
---|
96 | return FALSE;
|
---|
97 | }
|
---|
98 | #endif
|
---|
99 |
|
---|
100 | while(*lpCmdLine == ' ') lpCmdLine++;
|
---|
101 |
|
---|
102 | hModule = WinExec(lpCmdLine, SW_SHOW);
|
---|
103 |
|
---|
104 | if(hModule >= 32) {
|
---|
105 | while (GetMessage(&msg, NULL, NULL, NULL))
|
---|
106 | {
|
---|
107 | TranslateMessage(&msg);
|
---|
108 | DispatchMessage(&msg);
|
---|
109 | }
|
---|
110 | }
|
---|
111 | else {
|
---|
112 | char errormsg[256];
|
---|
113 |
|
---|
114 | sprintf(errormsg, "WinExec %s failed with error %d", lpCmdLine, hModule);
|
---|
115 | MessageBox(hwnd, errormsg, "Internal Error", MB_ICONHAND);
|
---|
116 | DestroyWindow(hwnd);
|
---|
117 | }
|
---|
118 |
|
---|
119 | #ifdef DDE_COMM
|
---|
120 | DdeNameService(idInst, hszServer, 0, DNS_UNREGISTER);
|
---|
121 | DdeFreeStringHandle(idInst, hszServer);
|
---|
122 | DdeFreeStringHandle(idInst, hszTopic);
|
---|
123 | DdeUninitialize(idInst);
|
---|
124 | #endif
|
---|
125 | FreeLibrary(hDll);
|
---|
126 | return (msg.wParam);
|
---|
127 | }
|
---|
128 | //*****************************************************************************************
|
---|
129 | //*****************************************************************************************
|
---|
130 | BOOL InitApplication(HANDLE hInstance)
|
---|
131 | {
|
---|
132 | WNDCLASS wc;
|
---|
133 |
|
---|
134 | wc.style = NULL;
|
---|
135 | wc.lpfnWndProc = MainWndProc;
|
---|
136 | wc.cbClsExtra = 0;
|
---|
137 | wc.cbWndExtra = 0;
|
---|
138 | wc.hInstance = hInstance;
|
---|
139 | wc.hIcon = 0;
|
---|
140 | wc.hCursor = 0;
|
---|
141 | wc.hbrBackground = GetStockObject(WHITE_BRUSH);
|
---|
142 | wc.lpszMenuName = NULL;
|
---|
143 | wc.lpszClassName = "Win16OdinClass";
|
---|
144 |
|
---|
145 | return (RegisterClass(&wc));
|
---|
146 | }
|
---|
147 | //*****************************************************************************************
|
---|
148 | //*****************************************************************************************
|
---|
149 | BOOL InitInstance(HANDLE hInstance, int nCmdShow)
|
---|
150 | {
|
---|
151 | hinstApp = hInstance;
|
---|
152 |
|
---|
153 | hwnd = CreateWindow(
|
---|
154 | "Win16OdinClass",
|
---|
155 | "Odin Win16 Program Launcher",
|
---|
156 | #if 1
|
---|
157 | WS_POPUP,
|
---|
158 | #else
|
---|
159 | WS_OVERLAPPEDWINDOW | WS_VISIBLE,
|
---|
160 | #endif
|
---|
161 | CW_USEDEFAULT,
|
---|
162 | CW_USEDEFAULT,
|
---|
163 | CW_USEDEFAULT,
|
---|
164 | CW_USEDEFAULT,
|
---|
165 | NULL,
|
---|
166 | NULL,
|
---|
167 | hInstance,
|
---|
168 | NULL
|
---|
169 | );
|
---|
170 |
|
---|
171 | if (!hwnd)
|
---|
172 | return (FALSE);
|
---|
173 |
|
---|
174 | return (TRUE);
|
---|
175 |
|
---|
176 | }
|
---|
177 | //*****************************************************************************************
|
---|
178 | //*****************************************************************************************
|
---|
179 | long FAR PASCAL __export MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
---|
180 | {
|
---|
181 | char modname[256];
|
---|
182 |
|
---|
183 | switch (message) {
|
---|
184 | case WM_CREATE:
|
---|
185 | SetTimer(hWnd, 1234, 500, NULL);
|
---|
186 | return 0;
|
---|
187 |
|
---|
188 | case WM_TIMER:
|
---|
189 | if(GetModuleFileName(hModule, modname, sizeof(modname)) == 0) {
|
---|
190 | KillTimer(hWnd, 1234);
|
---|
191 | DestroyWindow(hWnd);
|
---|
192 | }
|
---|
193 | break;
|
---|
194 |
|
---|
195 | case WM_DESTROY:
|
---|
196 | PostQuitMessage(0);
|
---|
197 | break;
|
---|
198 |
|
---|
199 | #ifdef DDE_COMM
|
---|
200 | case MSG_DDE_WILDCONNECT:
|
---|
201 | break;
|
---|
202 | case MSG_DDE_CONNECT:
|
---|
203 | MessageBox(0, "MyDdeCallback", "WILDCONNECT", MB_OK);
|
---|
204 | break;
|
---|
205 | #endif
|
---|
206 | default:
|
---|
207 | return (DefWindowProc(hWnd, message, wParam, lParam));
|
---|
208 | }
|
---|
209 | return (NULL);
|
---|
210 | }
|
---|
211 | #ifdef DDE_COMM
|
---|
212 | //*****************************************************************************************
|
---|
213 | //*****************************************************************************************
|
---|
214 | HDDEDATA CALLBACK MyDdeCallback(UINT wType, UINT wFmt, HCONV hConv,
|
---|
215 | HSZ hszTopic, HSZ hszItem,
|
---|
216 | HDDEDATA hData, DWORD dwData1, DWORD dwData2)
|
---|
217 | {
|
---|
218 | // WORD i, j;
|
---|
219 | // WORD cItems, iFmt;
|
---|
220 | // HDDEDATA hDataRet;
|
---|
221 |
|
---|
222 | char msg[128];
|
---|
223 |
|
---|
224 | //// MessageBeep(500);
|
---|
225 | // sprintf(msg, "type=%x format=%x %x %x %x %x %x %x", wType, wFmt, hConv, hszTopic, hszItem, hData, dwData1, dwData2);
|
---|
226 | // MessageBox(0, "MyDdeCallback", "test", MB_OK);
|
---|
227 |
|
---|
228 | if(wType == XTYP_EXECUTE && wFmt == CF_TEXT)
|
---|
229 | {
|
---|
230 | char szExec[64];
|
---|
231 |
|
---|
232 | DdeGetData(hData, (LPBYTE)szExec, 64, 0);
|
---|
233 | szExec[63] = 0;
|
---|
234 | MessageBox(0, "MyDdeCallback", szExec, MB_OK);
|
---|
235 | return (HDDEDATA)TRUE;
|
---|
236 | }
|
---|
237 | /*
|
---|
238 | * Process wild initiates here
|
---|
239 | */
|
---|
240 | if (wType == XTYP_WILDCONNECT) {
|
---|
241 | HSZ ahsz[(1 + 1) * 2];
|
---|
242 | /*
|
---|
243 | * He wants a hsz list of all our available app/topic pairs
|
---|
244 | * that conform to hszTopic and hszItem(App).
|
---|
245 | */
|
---|
246 |
|
---|
247 | // MessageBox(0, "MyDdeCallback", "WILDCONNECT", MB_OK);
|
---|
248 |
|
---|
249 | // if (!ValidateContext((PCONVCONTEXT)lData1)) {
|
---|
250 | // return(FALSE);
|
---|
251 | // }
|
---|
252 |
|
---|
253 | if (hszItem != hszServer && hszItem != 0) {
|
---|
254 | // we only support the hszAppName service
|
---|
255 | return(0);
|
---|
256 | }
|
---|
257 |
|
---|
258 | ahsz[0] = hszServer;
|
---|
259 | ahsz[1] = hszTopic;
|
---|
260 | // cap off the list with 0s
|
---|
261 | ahsz[2] = ahsz[3] = 0L;
|
---|
262 |
|
---|
263 | // send it back
|
---|
264 | return(DdeCreateDataHandle(idInst, (LPBYTE)&ahsz[0], sizeof(HSZ) * 4, 0L, 0, wFmt, 0));
|
---|
265 | }
|
---|
266 | return 0;
|
---|
267 | }
|
---|
268 | //*****************************************************************************************
|
---|
269 | //*****************************************************************************************
|
---|
270 | #endif
|
---|