|
|
1.1 root 1: /*++
2:
3: Copyright (c) 1985-92, Microsoft Corporation
4:
5: Module Name:
6:
7: db32.c
8:
9: Abstract:
10:
11: Win32s sample code of Universal Thunk (UT) -
12: 32bit code that provides the same services as DB.DLL by means
13: of thunking to 16bit dll.
14: This is the main source file of DB32.DLL
15:
16: --*/
17:
18:
19: #define W32SUT_32
20:
21: #include <windows.h>
22: #include <w32sut.h>
23: #include <db.h>
24:
25: UT32PROC pfnUTProc=NULL;
26: int cProcessesAttached = 0;
27:
28:
29: BOOL
30: DllInit(HANDLE hInst, DWORD fdwReason, LPVOID lpReserved)
31: {
32:
33: if ( fdwReason == DLL_PROCESS_ATTACH ) {
34:
35: /*
36: * Registration of UT need to be done only once for first
37: * attaching process.
38: */
39:
40: if ( cProcessesAttached++ ) {
41: return(TRUE);
42: }
43:
44: return UTRegister( hInst, // DB32.DLL module handle
45: "DB16.DLL", // name of 16bit thunk dll
46: NULL, // no init routine
47: "UTProc", // name of 16bit dispatch routine
48: // exported from DB16.DLL
49: &pfnUTProc, // Global variable to receive thunk address
50: NULL, // no call back function
51: NULL // no shared memroy
52: );
53: } else if ( fdwReason == DLL_PROCESS_DETACH ) {
54:
55: if ( --cProcessesAttached == 0 ) {
56: UTUnRegister( hInst );
57: }
58: }
59:
60: }
61:
62: /*
63: * constants for dispatcher in 16bit side
64: */
65:
66: #define DB_SRV_GETVERSION 0
67: #define DB_SRV_SETTIME 1
68: #define DB_SRV_ADDUSER 2
69:
70:
71: int
72: DbGetVersion(void)
73: {
74:
75: /*
76: * call the 16bit dispatch thru the 32bit thunk. no parameters
77: * are passed.
78: * returned value is the service result.
79: */
80:
81: return( (int) (* pfnUTProc)(NULL, DB_SRV_GETVERSION, NULL) );
82:
83: }
84:
85: void
86: DbSetTime(LPDB_TIME pTime)
87: {
88:
89: /*
90: * call the 16bit dispatch thru the 32bit thunk.
91: * pass one pointer to a buffer which will be translated
92: * to 16:16 address before passed to 16bit side.
93: *
94: */
95:
96: (* pfnUTProc)(pTime, DB_SRV_SETTIME, NULL);
97:
98: }
99:
100: short
101: DbAddUser(LPDB_NAME pName, DWORD Permission, LPDWORD pId)
102: {
103:
104: DWORD Args[3]; // function has three arguments
105: PVOID TransList[4]; // Three pointers need translation:
106: // pName
107: // pName->str
108: // pId
109: // plus null to indicate end of list
110: char *pSaveStr;
111: int Ret;
112:
113: /*
114: * put arguments in buffer
115: */
116:
117: Args[0] = (DWORD) pName;
118: Args[1] = Permission;
119: Args[2] = (DWORD) pId;
120:
121: /*
122: * build translation list for all the flat pointers that need to
123: * be translated to segmented form.
124: */
125: TransList[0] = & Args[0];
126: TransList[1] = & pName->str;
127: TransList[2] = & Args[2];
128: TransList[3] = 0;
129:
130: /*
131: * save the original pointer in the NAME struct so it can be restored
132: * after the call to the thunk.
133: * This is required only if the caller of the service expects the
134: * structure to be left unmodified.
135: */
136:
137: pSaveStr = pName->str;
138:
139: /*
140: * call the 16bit dispatch thru the 32bit thunk.
141: * pass arguments in buffer along with list of addresses
142: * that need to be translated equivalent segmented format.
143: *
144: */
145:
146: Ret = (int) (* pfnUTProc)(Args, DB_SRV_ADDUSER, TransList);
147:
148: /*
149: * restore flat pointer
150: */
151: pName->str = pSaveStr;
152:
153: return(Ret);
154: }
155:
156:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.