ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

info.c
Go to the documentation of this file.
00001 /*
00002  * WINSPOOL functions
00003  *
00004  * Copyright 1996 John Harvey
00005  * Copyright 1998 Andreas Mohr
00006  * Copyright 1999 Klaas van Gend
00007  * Copyright 1999, 2000 Huw D M Davies
00008  * Copyright 2001 Marcus Meissner
00009  *
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or (at your option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023  */
00024 
00025 #include "wine/config.h"
00026 #include "wine/port.h"
00027 
00028 #include <stdarg.h>
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <string.h>
00032 #include <ctype.h>
00033 #include <stddef.h>
00034 
00035 #include "windef.h"
00036 #include "winbase.h"
00037 #include "winerror.h"
00038 #include "wingdi.h"
00039 #include "winreg.h"
00040 #include "shlwapi.h"
00041 #include "winspool.h"
00042 #include "wine/unicode.h"
00043 #include "wine/debug.h"
00044 #include "winnls.h"
00045 
00046 WINE_DEFAULT_DEBUG_CHANNEL(winspool);
00047 
00048 /******************************************************************************
00049  *      GetDefaultPrinterA   (WINSPOOL.@)
00050  */
00051 BOOL WINAPI GetDefaultPrinterA(LPSTR name, LPDWORD namesize)
00052 {
00053    char *ptr;
00054 
00055    if (*namesize < 1)
00056    {
00057       SetLastError (ERROR_INSUFFICIENT_BUFFER);
00058       return FALSE;
00059    }
00060 
00061    if (!GetProfileStringA ("windows", "device", "", name, *namesize))
00062    {
00063       SetLastError (ERROR_FILE_NOT_FOUND);
00064       return FALSE;
00065    }
00066 
00067    if ((ptr = strchr (name, ',')) == NULL)
00068    {
00069       SetLastError (ERROR_FILE_NOT_FOUND);
00070       return FALSE;
00071    }
00072 
00073    *ptr = '\0';
00074    *namesize = strlen (name) + 1;
00075    return TRUE;
00076 }
00077 
00078 
00079 /******************************************************************************
00080  *      GetDefaultPrinterW   (WINSPOOL.@)
00081  */
00082 BOOL WINAPI GetDefaultPrinterW(LPWSTR name, LPDWORD namesize)
00083 {
00084    char *buf;
00085    BOOL  ret;
00086 
00087    if (*namesize < 1)
00088    {
00089       SetLastError (ERROR_INSUFFICIENT_BUFFER);
00090       return FALSE;
00091    }
00092 
00093    buf = HeapAlloc (GetProcessHeap (), 0, *namesize);
00094    ret = GetDefaultPrinterA (buf, namesize);
00095    if (ret)
00096    {
00097        DWORD len = MultiByteToWideChar (CP_ACP, 0, buf, -1, name, *namesize);
00098        if (!len)
00099        {
00100            SetLastError (ERROR_INSUFFICIENT_BUFFER);
00101            ret = FALSE;
00102        }
00103        else *namesize = len;
00104    }
00105 
00106    HeapFree (GetProcessHeap (), 0, buf);
00107    return ret;
00108 }
00109 
00110 /******************************************************************************
00111  *      AddPrintProvidorA   (WINSPOOL.@)
00112  */
00113 BOOL
00114 WINAPI
00115 AddPrintProvidorA(LPSTR Name, DWORD Level, PBYTE Buffer)
00116 {
00117    if (Name || Level > 2 || Buffer == NULL)
00118    {
00119       SetLastError(ERROR_INVALID_PARAMETER);
00120       return FALSE;
00121    }
00122 
00123    if (Level == 1)
00124    {
00125       BOOL bRet;
00126       PROVIDOR_INFO_1W Provider;
00127       PROVIDOR_INFO_1A  *Prov = (PROVIDOR_INFO_1A*)Buffer;
00128 
00129       if (Prov->pName == NULL || Prov->pDLLName == NULL || Prov->pEnvironment == NULL)
00130       {
00131          return FALSE;
00132       }
00133 
00134       Provider.pDLLName = HeapAlloc(GetProcessHeap(), 0, (strlen(Prov->pDLLName)+1) * sizeof(WCHAR));
00135       if (Provider.pDLLName)
00136       {
00137           MultiByteToWideChar(CP_ACP, 0, Prov->pDLLName, -1, Provider.pDLLName, strlen(Prov->pDLLName)+1);
00138           Provider.pDLLName[strlen(Prov->pDLLName)] = L'\0';
00139       }
00140 
00141       Provider.pEnvironment = HeapAlloc(GetProcessHeap(), 0, (strlen(Prov->pEnvironment)+1) * sizeof(WCHAR));
00142       if (Provider.pEnvironment)
00143       {
00144           MultiByteToWideChar(CP_ACP, 0, Prov->pEnvironment, -1, Provider.pEnvironment, strlen(Prov->pEnvironment)+1);
00145           Provider.pEnvironment[strlen(Prov->pEnvironment)] = L'\0';
00146       }
00147 
00148       Provider.pName = HeapAlloc(GetProcessHeap(), 0, (strlen(Prov->pName)+1) * sizeof(WCHAR));
00149       if (Provider.pName)
00150       {
00151           MultiByteToWideChar(CP_ACP, 0, Prov->pName, -1, Provider.pName, strlen(Prov->pName)+1);
00152           Provider.pName[strlen(Prov->pName)] = L'\0';
00153       }
00154 
00155       bRet = AddPrintProvidorW(NULL, Level, (LPBYTE)&Provider);
00156 
00157       if (Provider.pDLLName)
00158           HeapFree(GetProcessHeap(), 0, Provider.pDLLName);
00159 
00160       if (Provider.pEnvironment)
00161           HeapFree(GetProcessHeap(), 0, Provider.pEnvironment);
00162 
00163       if (Provider.pName)
00164           HeapFree(GetProcessHeap(), 0, Provider.pName);
00165 
00166       return bRet;
00167    }
00168    else
00169    {
00170       PROVIDOR_INFO_2W Provider;
00171       PROVIDOR_INFO_2A  *Prov = (PROVIDOR_INFO_2A*)Buffer;
00172 
00173       Provider.pOrder = HeapAlloc(GetProcessHeap(), 0, (strlen(Prov->pOrder)+1) * sizeof(WCHAR));
00174       if (Provider.pOrder)
00175       {
00176           BOOL bRet;
00177           MultiByteToWideChar(CP_ACP, 0, Prov->pOrder, -1, Provider.pOrder, strlen(Prov->pOrder)+1);
00178           Provider.pOrder[strlen(Prov->pOrder)] = L'\0';
00179 
00180           bRet = AddPrintProvidorW(NULL, Level, (LPBYTE)&Provider);
00181           HeapFree(GetProcessHeap(), 0, Provider.pOrder);
00182           return bRet;
00183       }
00184    }
00185 
00186   return FALSE;
00187 }
00188 
00189 
00190 /******************************************************************************
00191  *      AddPrintProvidorW   (WINSPOOL.@)
00192  */
00193 BOOL
00194 WINAPI
00195 AddPrintProvidorW(LPWSTR Name, DWORD Level, PBYTE Buffer)
00196 {
00197    HKEY hKey;
00198    LPWSTR pOrder;
00199    DWORD dwSize, dwType;
00200    BOOL bRet = FALSE;
00201 
00202    if (Name || Level > 2 || Buffer == NULL)
00203    {
00204       SetLastError(ERROR_INVALID_PARAMETER);
00205       return FALSE;
00206    }
00207 
00208 
00209    if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Print\\Providers", 0, KEY_READ | KEY_WRITE, &hKey) != ERROR_SUCCESS)
00210    {
00211       return FALSE;
00212    }
00213 
00214    if (RegQueryValueExW(hKey, L"Order", NULL, &dwType, NULL, &dwSize) != ERROR_SUCCESS || dwType != REG_MULTI_SZ)
00215    {
00216       RegCloseKey(hKey);
00217       return FALSE;
00218    }
00219 
00220    pOrder = HeapAlloc(GetProcessHeap(), 0, dwSize);
00221    if (!pOrder)
00222    {
00223       RegCloseKey(hKey);
00224       return FALSE;
00225    }
00226 
00227    if (RegQueryValueExW(hKey, L"Order", NULL, &dwType, (LPBYTE)pOrder, &dwSize) != ERROR_SUCCESS || dwType != REG_MULTI_SZ)
00228    {
00229       RegCloseKey(hKey);
00230       return FALSE;
00231    }
00232 
00233    if (Level == 1)
00234    {
00235       LPWSTR pBuffer;
00236       BOOL bFound = FALSE;
00237       PROVIDOR_INFO_1W * Prov = (PROVIDOR_INFO_1W*)Buffer;
00238 
00239       if (Prov->pName == NULL || Prov->pDLLName == NULL || Prov->pEnvironment == NULL)
00240       {
00241          SetLastError(ERROR_INVALID_PARAMETER);
00242          RegCloseKey(hKey);
00243          return FALSE;
00244       }
00245 
00246       pBuffer = pOrder;
00247 
00248       while(pBuffer[0])
00249       {
00250          if (!wcsicmp(pBuffer, Prov->pName))
00251          {
00252             bFound = TRUE;
00253             break;
00254          }
00255          pBuffer += wcslen(pBuffer) + 1;
00256       }
00257 
00258       if (!bFound)
00259       {
00260          HKEY hSubKey;
00261          DWORD dwFullSize = dwSize + (wcslen(Prov->pName)+1) * sizeof(WCHAR);
00262 
00263          if (RegCreateKeyExW(hKey, Prov->pName, 0, NULL, 0, KEY_WRITE, NULL, &hSubKey, NULL) == ERROR_SUCCESS)
00264          {
00265             RegSetValueExW(hSubKey, L"Name", 0, REG_SZ, (LPBYTE)Prov->pDLLName, (wcslen(Prov->pDLLName)+1) * sizeof(WCHAR));
00266             RegCloseKey(hSubKey);
00267          }
00268 
00269          pBuffer = HeapAlloc(GetProcessHeap(), 0, dwFullSize);
00270          if (pBuffer)
00271          {
00272              CopyMemory(pBuffer, pOrder, dwSize);
00273              wcscpy(&pBuffer[(dwSize/sizeof(WCHAR))-1], Prov->pName);
00274              pBuffer[(dwSize/sizeof(WCHAR)) + wcslen(Prov->pName)] = L'\0';
00275              RegSetValueExW(hKey, L"Order", 0, REG_MULTI_SZ, (LPBYTE)pBuffer, dwFullSize);
00276              HeapFree(GetProcessHeap(), 0, pBuffer);
00277          }
00278          bRet = TRUE;
00279       }
00280 
00281    }
00282 
00283    RegCloseKey(hKey);
00284    HeapFree(GetProcessHeap(), 0, pOrder);
00285 
00286   return bRet;
00287 }
00288 
00289 /******************************************************************************
00290  *    DeletePrintProvidorA   (WINSPOOL.@)
00291  */
00292 BOOL
00293 WINAPI
00294 DeletePrintProvidorA(LPSTR Name, LPSTR Environment, LPSTR PrintProvidor)
00295 {
00296    BOOL bRet;
00297    LPWSTR Env, Prov;
00298 
00299    if (Name || !Environment || !PrintProvidor)
00300    {
00301       SetLastError(ERROR_INVALID_PARAMETER);
00302       return FALSE;
00303    }
00304 
00305    Env = HeapAlloc(GetProcessHeap(), 0, (strlen(Environment)+1) * sizeof(WCHAR));
00306    if (!Env)
00307    {
00308       return FALSE;
00309    }
00310 
00311    MultiByteToWideChar(CP_ACP, 0, Environment, -1, Env, strlen(Environment)+1);
00312    Env[strlen(Environment)] = L'\0';
00313 
00314    Prov = HeapAlloc(GetProcessHeap(), 0, (strlen(PrintProvidor)+1) * sizeof(WCHAR));
00315    if (!Prov)
00316    {
00317       HeapFree(GetProcessHeap(), 0, Env);
00318       return FALSE;
00319    }
00320 
00321    MultiByteToWideChar(CP_ACP, 0, PrintProvidor, -1, Prov, strlen(PrintProvidor)+1);
00322    Prov[strlen(PrintProvidor)] = L'\0';
00323 
00324    bRet = DeletePrintProvidorW(NULL, Env, Prov);
00325    HeapFree(GetProcessHeap(), 0, Env);
00326    HeapFree(GetProcessHeap(), 0, Prov);
00327 
00328   return bRet;
00329 }
00330 
00331 /*
00332  * @unimplemented
00333  */
00334 BOOL
00335 WINAPI
00336 DeletePrintProvidorW(LPWSTR Name, LPWSTR Environment, LPWSTR PrintProvidor)
00337 {
00338    HKEY hKey;
00339    BOOL bFound;
00340    DWORD dwType, dwSize, dwOffset, dwLength;
00341    LPWSTR pOrder, pBuffer, pNew;
00342 
00343    if (Name || !Environment || !PrintProvidor)
00344    {
00345       SetLastError(ERROR_INVALID_PARAMETER);
00346       return FALSE;
00347    }
00348 
00349    if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Print\\Providers", 0, KEY_READ | KEY_WRITE, &hKey) != ERROR_SUCCESS)
00350    {
00351       return FALSE;
00352    }
00353 
00354    if (RegQueryValueExW(hKey, L"Order", NULL, &dwType, NULL, &dwSize) != ERROR_SUCCESS || dwType != REG_MULTI_SZ)
00355    {
00356       RegCloseKey(hKey);
00357       return FALSE;
00358    }
00359 
00360    pOrder = HeapAlloc(GetProcessHeap(), 0, dwSize);
00361    if (!pOrder)
00362    {
00363       RegCloseKey(hKey);
00364       return FALSE;
00365    }
00366 
00367    if (RegQueryValueExW(hKey, L"Order", NULL, &dwType, (LPBYTE)pOrder, &dwSize) != ERROR_SUCCESS || dwType != REG_MULTI_SZ)
00368    {
00369       RegCloseKey(hKey);
00370       return FALSE;
00371    }
00372 
00373 
00374    pBuffer = pOrder;
00375    bFound = FALSE;
00376    while(pBuffer[0])
00377    {
00378        if (!wcsicmp(pBuffer, PrintProvidor))
00379        {
00380             bFound = TRUE;
00381             break;
00382          }
00383          pBuffer += wcslen(pBuffer) + 1;
00384    }
00385 
00386    if (!bFound)
00387    {
00388       RegCloseKey(hKey);
00389       HeapFree(GetProcessHeap(), 0, pOrder);
00390       return FALSE;
00391    }
00392 
00393    pNew = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize);
00394    if (!pNew)
00395    {
00396       RegCloseKey(hKey);
00397       HeapFree(GetProcessHeap(), 0, pOrder);
00398       return FALSE;
00399    }
00400 
00401    dwOffset = pBuffer - pOrder;
00402    dwLength = (dwSize / sizeof(WCHAR)) - (dwOffset + wcslen(pBuffer) + 1);
00403    CopyMemory(pNew, pOrder, dwOffset * sizeof(WCHAR));
00404    CopyMemory(&pNew[dwOffset], pBuffer + wcslen(pBuffer) + 1, dwLength);
00405 
00406    RegSetValueExW(hKey, L"Order", 0, REG_MULTI_SZ, (LPBYTE)pNew, (dwOffset + dwLength) * sizeof(WCHAR));
00407    RegDeleteKey(hKey, PrintProvidor);
00408 
00409    HeapFree(GetProcessHeap(), 0, pOrder);
00410    HeapFree(GetProcessHeap(), 0, pNew);
00411    RegCloseKey(hKey);
00412 
00413    return TRUE;
00414 }
00415 
00416 /*
00417  * @unimplemented
00418  */
00419 BOOL
00420 WINAPI
00421 AddMonitorA(LPSTR Name, DWORD Level, PBYTE Monitors)
00422 {
00423    LPWSTR szName = NULL;
00424    MONITOR_INFO_2W Monitor;
00425    MONITOR_INFO_2A *pMonitor;
00426    BOOL bRet = FALSE;
00427 
00428    if (Level != 2 || !Monitors)
00429    {
00430       SetLastError(ERROR_INVALID_PARAMETER);
00431       return FALSE;
00432    }
00433 
00434    pMonitor = (MONITOR_INFO_2A*)Monitors;
00435    if (pMonitor->pDLLName == NULL || pMonitor->pName == NULL)
00436    {
00437       SetLastError(ERROR_INVALID_PARAMETER);
00438       return FALSE;
00439    }
00440 
00441    ZeroMemory(&Monitor, sizeof(Monitor));
00442 
00443    if (Name)
00444    {
00445       szName = HeapAlloc(GetProcessHeap(), 0, (strlen(Name) + 1) * sizeof(WCHAR));
00446       if (!szName)
00447       {
00448          return FALSE;
00449       }
00450       MultiByteToWideChar(CP_ACP, 0, Name, -1, szName, strlen(Name)+1);
00451       szName[strlen(Name)] = L'\0';
00452    }
00453 
00454    Monitor.pDLLName = HeapAlloc(GetProcessHeap(), 0, (strlen(pMonitor->pDLLName)+1) * sizeof(WCHAR));
00455    if (!Monitor.pDLLName)
00456    {
00457       goto cleanup;
00458    }
00459    MultiByteToWideChar(CP_ACP, 0, pMonitor->pDLLName, -1, Monitor.pDLLName, strlen(pMonitor->pDLLName)+1);
00460    pMonitor->pDLLName[strlen(pMonitor->pDLLName)] = L'\0';
00461 
00462    Monitor.pName = HeapAlloc(GetProcessHeap(), 0, (strlen(pMonitor->pName)+1) * sizeof(WCHAR));
00463    if (!Monitor.pName)
00464    {
00465       goto cleanup;
00466    }
00467    MultiByteToWideChar(CP_ACP, 0, pMonitor->pName, -1, Monitor.pName, strlen(pMonitor->pName)+1);
00468    pMonitor->pName[strlen(pMonitor->pName)] = L'\0';
00469 
00470 
00471    if (pMonitor->pEnvironment)
00472    {
00473       Monitor.pEnvironment = HeapAlloc(GetProcessHeap(), 0, (strlen(pMonitor->pEnvironment)+1) * sizeof(WCHAR));
00474       if (!Monitor.pEnvironment)
00475       {
00476          goto cleanup;
00477       }
00478       MultiByteToWideChar(CP_ACP, 0, pMonitor->pEnvironment, -1, Monitor.pEnvironment, strlen(pMonitor->pEnvironment)+1);
00479       pMonitor->pEnvironment[strlen(pMonitor->pEnvironment)] = L'\0';
00480    }
00481 
00482    bRet = AddMonitorW(szName, Level, (LPBYTE)&Monitor);
00483 
00484 cleanup:
00485 
00486   if (szName)
00487      HeapFree(GetProcessHeap(), 0, szName);
00488 
00489   if (Monitor.pDLLName)
00490      HeapFree(GetProcessHeap(), 0, Monitor.pDLLName);
00491 
00492   if (Monitor.pEnvironment)
00493      HeapFree(GetProcessHeap(), 0, Monitor.pEnvironment);
00494 
00495   if (Monitor.pName)
00496      HeapFree(GetProcessHeap(), 0, Monitor.pName);
00497 
00498   return bRet;
00499 }
00500 
00501 
00502 /*
00503  * @unimplemented
00504  */
00505 BOOL
00506 WINAPI
00507 AddMonitorW(LPWSTR Name, DWORD Level, PBYTE Monitors)
00508 {
00509    WCHAR szPath[MAX_PATH];
00510    HMODULE hLibrary = NULL;
00511    FARPROC InitProc;
00512    HKEY hKey, hSubKey;
00513    MONITOR_INFO_2W * pMonitor;
00514 
00515 
00516    if (Level != 2 || !Monitors)
00517    {
00518       SetLastError(ERROR_INVALID_PARAMETER);
00519       return FALSE;
00520    }
00521 
00522    pMonitor = (MONITOR_INFO_2W*)Monitors;
00523 
00524    if (pMonitor->pDLLName == NULL || pMonitor->pName == NULL)
00525    {
00526       SetLastError(ERROR_INVALID_PARAMETER);
00527       return FALSE;
00528    }
00529 
00530    if (wcschr(pMonitor->pDLLName, L'\\'))
00531    {
00532        hLibrary = LoadLibraryExW(pMonitor->pDLLName, NULL, 0);
00533    }
00534    else if (GetSystemDirectoryW(szPath, MAX_PATH) && PathAddBackslashW(szPath))
00535    {
00536       wcscat(szPath, pMonitor->pDLLName);
00537       hLibrary = LoadLibraryExW(szPath, NULL, 0);
00538    }
00539 
00540    if (!hLibrary)
00541    {
00542       return FALSE;
00543    }
00544 
00545    InitProc = GetProcAddress(hLibrary, "InitializePrintMonitor");
00546    if (!InitProc)
00547    {
00548       InitProc = GetProcAddress(hLibrary, "InitializePrintMonitor2");
00549       if (!InitProc)
00550       {
00551          FreeLibrary(hLibrary);
00552          SetLastError(ERROR_PROC_NOT_FOUND);
00553          return FALSE;
00554       }
00555    }
00556 
00557    // FIXME
00558    // Initialize monitor
00559    FreeLibrary(hLibrary);
00560 
00561    if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Print\\Monitors", 0, KEY_WRITE, &hKey) == ERROR_SUCCESS)
00562    {
00563       if (RegCreateKeyExW(hKey, pMonitor->pName, 0, NULL, 0, KEY_WRITE, NULL, &hSubKey, NULL) == ERROR_SUCCESS)
00564       {
00565          RegSetValueExW(hSubKey, L"Driver", 0, REG_SZ, (LPBYTE)pMonitor->pDLLName, (wcslen(pMonitor->pDLLName)+1)*sizeof(WCHAR));
00566          RegCloseKey(hSubKey);
00567       }
00568       RegCloseKey(hKey);
00569    }
00570    return TRUE;
00571 }
00572 

Generated on Fri May 25 2012 04:22:47 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.