2 * Driver Environment functions
4 * Note: This has NOTHING to do with the task/process environment!
6 * Copyright 1997 Marcus Meissner
7 * Copyright 1998 Andreas Mohr
22 static ENVTABLE EnvTable[20];
24 static ENVTABLE *SearchEnvTable(ATOM atom)
28 for (i = 19; i >= 0; i--) {
29 if (EnvTable[i].atom == atom)
35 static ATOM GDI_GetNullPortAtom(void)
37 static ATOM NullPortAtom = 0;
42 GetProfileString32A( "windows", "nullport", "none",
43 NullPort, sizeof(NullPort) );
44 NullPortAtom = AddAtom32A( NullPort );
49 static ATOM PortNameToAtom(LPCSTR lpPortName, BOOL16 add)
52 BOOL32 needfree = FALSE;
55 if (lpPortName[strlen(lpPortName) - 1] == ':') {
56 p = HEAP_strdupA(GetProcessHeap(), 0, lpPortName);
57 p[strlen(lpPortName) - 1] = '\0';
61 p = (char *)lpPortName;
68 if(needfree) HeapFree(GetProcessHeap(), 0, p);
74 /***********************************************************************
75 * GetEnvironment (GDI.134)
77 INT16 WINAPI GetEnvironment(LPCSTR lpPortName, LPDEVMODE16 lpdev, UINT16 nMaxSize)
84 TRACE(gdi, "('%s', %p, %d)\n", lpPortName, lpdev, nMaxSize);
86 if (!(atom = PortNameToAtom(lpPortName, FALSE)))
88 if (atom == GDI_GetNullPortAtom())
89 if (!(atom = FindAtom32A((LPCSTR)lpdev)))
91 if (!(env = SearchEnvTable(atom)))
93 size = GlobalSize16(env->handle);
95 if (size < nMaxSize) nMaxSize = size;
96 if (!(p = GlobalLock16(env->handle))) return 0;
97 memcpy(lpdev, p, nMaxSize);
98 GlobalUnlock16(env->handle);
103 /***********************************************************************
104 * SetEnvironment (GDI.132)
106 INT16 WINAPI SetEnvironment(LPCSTR lpPortName, LPDEVMODE16 lpdev, UINT16 nCount)
109 BOOL16 nullport = FALSE;
114 TRACE(gdi, "('%s', %p, %d)\n", lpPortName, lpdev, nCount);
116 if ((atom = PortNameToAtom(lpPortName, FALSE))) {
117 if (atom == GDI_GetNullPortAtom()) {
119 atom = FindAtom32A((LPCSTR)lpdev);
121 env = SearchEnvTable(atom);
122 GlobalFree16(env->handle);
125 if (nCount) { /* store DEVMODE struct */
129 p = (LPSTR)lpPortName;
131 if ((atom = PortNameToAtom(p, TRUE))
132 && (env = SearchEnvTable(0))
133 && (handle = GlobalAlloc16(GMEM_SHARE|GMEM_MOVEABLE, nCount))) {
134 if (!(p = GlobalLock16(handle))) {
135 GlobalFree16(handle);
139 env->handle = handle;
140 memcpy(p, lpdev, nCount);
141 GlobalUnlock16(handle);