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
21 static ENVTABLE EnvTable[20];
23 static ENVTABLE *SearchEnvTable(ATOM atom)
27 for (i = 19; i >= 0; i--) {
28 if (EnvTable[i].atom == atom)
34 static ATOM GDI_GetNullPortAtom(void)
36 static ATOM NullPortAtom = 0;
41 GetProfileStringA( "windows", "nullport", "none",
42 NullPort, sizeof(NullPort) );
43 NullPortAtom = AddAtomA( NullPort );
48 static ATOM PortNameToAtom(LPCSTR lpPortName, BOOL16 add)
51 BOOL needfree = FALSE;
54 if (lpPortName[strlen(lpPortName) - 1] == ':') {
55 p = HEAP_strdupA(GetProcessHeap(), 0, lpPortName);
56 p[strlen(lpPortName) - 1] = '\0';
60 p = (char *)lpPortName;
67 if(needfree) HeapFree(GetProcessHeap(), 0, p);
73 /***********************************************************************
74 * GetEnvironment (GDI.134)
76 INT16 WINAPI GetEnvironment16(LPCSTR lpPortName, LPDEVMODE16 lpdev, UINT16 nMaxSize)
83 TRACE(gdi, "('%s', %p, %d)\n", lpPortName, lpdev, nMaxSize);
85 if (!(atom = PortNameToAtom(lpPortName, FALSE)))
87 if (atom == GDI_GetNullPortAtom())
88 if (!(atom = FindAtomA((LPCSTR)lpdev)))
90 if (!(env = SearchEnvTable(atom)))
92 size = GlobalSize16(env->handle);
94 if (size < nMaxSize) nMaxSize = size;
95 if (!(p = GlobalLock16(env->handle))) return 0;
96 memcpy(lpdev, p, nMaxSize);
97 GlobalUnlock16(env->handle);
102 /***********************************************************************
103 * SetEnvironment (GDI.132)
105 INT16 WINAPI SetEnvironment16(LPCSTR lpPortName, LPDEVMODE16 lpdev, UINT16 nCount)
108 BOOL16 nullport = FALSE;
113 TRACE(gdi, "('%s', %p, %d)\n", lpPortName, lpdev, nCount);
115 if ((atom = PortNameToAtom(lpPortName, FALSE))) {
116 if (atom == GDI_GetNullPortAtom()) {
118 atom = FindAtomA((LPCSTR)lpdev);
120 env = SearchEnvTable(atom);
121 GlobalFree16(env->handle);
124 if (nCount) { /* store DEVMODE struct */
128 p = (LPSTR)lpPortName;
130 if ((atom = PortNameToAtom(p, TRUE))
131 && (env = SearchEnvTable(0))
132 && (handle = GlobalAlloc16(GMEM_SHARE|GMEM_MOVEABLE, nCount))) {
133 if (!(p = GlobalLock16(handle))) {
134 GlobalFree16(handle);
138 env->handle = handle;
139 memcpy(p, lpdev, nCount);
140 GlobalUnlock16(handle);