示例#1
0
文件: spoolss.c 项目: endisd/samba
static BOOL test_GetPrinterDriverDirectory(struct torture_context *tctx,
					   LPSTR servername,
					   LPSTR architecture)
{
	DWORD levels[]  = { 1 };
	DWORD success[] = { 1 };
	DWORD i;
	LPBYTE buffer = NULL;

	for (i=0; i < ARRAY_SIZE(levels); i++) {

		DWORD needed = 0;
		DWORD err = 0;
		char tmp[1024];

		torture_comment(tctx, "Testing GetPrinterDriverDirectory level %d", levels[i]);

		GetPrinterDriverDirectory(servername, architecture, levels[i], NULL, 0, &needed);
		err = GetLastError();
		if (err == ERROR_INSUFFICIENT_BUFFER) {
			err = 0;
			buffer = malloc(needed);
			torture_assert(tctx, buffer, "malloc failed");
			if (!GetPrinterDriverDirectory(servername, architecture, levels[i], buffer, needed, &needed)) {
				err = GetLastError();
			}
		}
		if (err) {
			sprintf(tmp, "GetPrinterDriverDirectory failed level %d on [%s] (buffer size = %d), error: %s\n",
				levels[i], servername, needed, errstr(err));
			if (success[i]) {
				torture_fail(tctx, tmp);
			} else {
				torture_warning(tctx, tmp);
			}
		}

		free(buffer);
		buffer = NULL;
	}

	return TRUE;
}
示例#2
0
PVOID
MyGetPrinterDriverDirectory(
    PWSTR       pName,
    DWORD       level
    )

/*++

Routine Description:

    Wrapper function for GetPrinterDriverDirectory spooler API

Arguments:

    pName - Specifies the name of the server on which the printer driver resides
    level - Specifies the structure level which must be 1 for now

Return Value:

    Pointer to the requested information, NULL if there is an error

--*/

{
    PBYTE   pDriverDirectory = NULL;
    DWORD   cbNeeded;

    if (!GetPrinterDriverDirectory(pName, NULL, level, NULL, 0, &cbNeeded) &&
        GetLastError() == ERROR_INSUFFICIENT_BUFFER &&
        (pDriverDirectory = MemAlloc(cbNeeded)) &&
        GetPrinterDriverDirectory(pName, NULL, level, pDriverDirectory, cbNeeded, &cbNeeded))
    {
        return pDriverDirectory;
    }

    Error(("GetPrinterDriverDirectory failed\n"));
    MemFree(pDriverDirectory);
    return NULL;
}
示例#3
0
/**
	@param lpCopyFrom Folder to copy the printer driver files from
	@return true if copied successfully, false if failed
*/
bool PrinterInstall::DoCopyFiles(LPCTSTR lpCopyFrom)
{
	TCHAR lpPath[MAX_PATH + 1];
	DWORD uSize=0;

	// Get the Windows printer driver folder
	if (!GetPrinterDriverDirectory(NULL, NULL, 1, (LPBYTE)lpPath, MAX_PATH + 1, &uSize))
	{
		// Failed?!
		SetError(-1201);
#ifdef TRACE
		TRACE(_T("Could not get printer driver directory: %d\n"), GetLastError());
#endif
		return false;
	}

	// Copy the files from the lpCopyFrom dir to the destination dir:
	std::tstring sFrom, sTo;
	for (STRARRAY::const_iterator i = m_arFiles.begin(); i != m_arFiles.end(); i++)
	{
		// Create the full path name for the files
		sFrom = ConcatPaths(lpCopyFrom, (*i));
		sTo = ConcatPaths(lpPath, (*i));

		// Now copy
		if (!::CopyFile(sFrom.c_str(), sTo.c_str(), TRUE))
		{
			DWORD error = GetLastError();
			if (error == 0 && !::CopyFile(sFrom.c_str(), sTo.c_str(), FALSE))
			{
				// May be a permissions error or something,
				// let's ignore
			} else {
			SetError(error/*-1202*/);
			/*TCHAR msg[1024];
			_tcscpy_s (msg, 1024, "Failed to copy from\n");
			_tcscat_s (msg, 1024, sFrom.c_str());
			_tcscat_s (msg, 1024, "\nto\n");
			_tcscat_s (msg, 1024, sTo.c_str());
			MessageBox (NULL, msg, _T("Error!"), 0);*/
#ifdef TRACE
			TRACE(_T("Cannot copy file: %d\n"), GetLastError());
#endif
			return false;
			}
		}
	}

	return true;
}
示例#4
0
文件: help.c 项目: 340211173/Driver
LPWSTR
GetPlotHelpFile(
    PPRINTERINFO    pPI
)

/*++

Routine Description:

    This function setup the directory path for the driver Help file

Arguments:

    hPrinter    - Handle to the printer

Return Value:

    LPWSTR to the full path HelpFile, NULL if failed


Development History:

    01-Nov-1995 Wed 18:43:40 created


Revision History:


--*/

{
    PDRIVER_INFO_3  pDI3 = NULL;
    LPWSTR          pHelpFile = NULL;
    WCHAR           HelpFileName[MAX_HELPFILE_NAME];
    DWORD           cb;
    DWORD           cb2;
    DWORD           dwMemAllocSize = 0;
    HRESULT         hr = E_FAIL;

    if (pPI->pHelpFile) {

        return(pPI->pHelpFile);
    }

    if ((!GetPrinterDriver(pPI->hPrinter, NULL, 3, NULL, 0, &cb))              &&
            (GetLastError() == ERROR_INSUFFICIENT_BUFFER)                          &&
            (pDI3 = (PDRIVER_INFO_3)LocalAlloc(LMEM_FIXED, cb))                    &&
            (GetPrinterDriver(pPI->hPrinter, NULL, 3, (LPBYTE)pDI3, cb, &cb))      &&
            (pDI3->pHelpFile)                                                      &&
            (SUCCEEDED(DWordAdd((DWORD)wcslen(pDI3->pHelpFile), 1, &dwMemAllocSize)))     &&
            (SUCCEEDED(DWordMult(dwMemAllocSize, sizeof(WCHAR), &dwMemAllocSize))) &&
            (pHelpFile = (LPWSTR)LocalAlloc(LMEM_FIXED, dwMemAllocSize))) {

        hr = StringCchCopyW(pHelpFile, dwMemAllocSize / sizeof(WCHAR), (LPWSTR)pDI3->pHelpFile);

    } else if ((cb2 = LoadString(hPlotUIModule,
                                 IDS_HELP_FILENAME,
                                 &HelpFileName[1],
                                 COUNT_ARRAY(HelpFileName) - 1))            &&
               (SUCCEEDED(DWordAdd(cb2, 1, &cb2)))                          &&
               (SUCCEEDED(DWordMult(cb2, sizeof(WCHAR), &cb2)))             &&
               (!GetPrinterDriverDirectory(NULL, NULL, 1, NULL, 0, &cb))    &&
               (GetLastError() == ERROR_INSUFFICIENT_BUFFER)                &&
               (SUCCEEDED(DWordAdd(cb, cb2, &dwMemAllocSize)))              &&
               (pHelpFile = (LPWSTR)LocalAlloc(LMEM_FIXED, dwMemAllocSize)) &&
               (GetPrinterDriverDirectory(NULL,
                                          NULL,
                                          1,
                                          (LPBYTE)pHelpFile,
                                          cb,
                                          &cb))) {
        HelpFileName[0] = L'\\';

        hr = StringCchCatW(pHelpFile, dwMemAllocSize / sizeof(WCHAR), HelpFileName);
    }

    if (pDI3) {

        LocalFree((HLOCAL)pDI3);
        pDI3 = NULL;
    }

    if (pHelpFile && !SUCCEEDED(hr))
    {
        LocalFree(pHelpFile);
        pHelpFile = NULL;
    }

    PLOTDBG(DBG_SHOW_HELP, ("GetlotHelpFile: '%ws",
                            (pHelpFile) ? pHelpFile : L"Failed"));

    return(pPI->pHelpFile = pHelpFile);
}
示例#5
0
文件: help.c 项目: Gaikokujin/WinNT4
LPWSTR
GetPlotHelpFile(
    PPRINTERINFO    pPI
    )

/*++

Routine Description:

    This function setup the directory path for the driver Help file

Arguments:

    hPrinter    - Handle to the printer

Return Value:

    LPWSTR to the full path HelpFile, NULL if failed

Author:

    01-Nov-1995 Wed 18:43:40 created  -by-  Daniel Chou (danielc)


Revision History:


--*/

{
    PDRIVER_INFO_3  pDI3 = NULL;
    LPWSTR          pHelpFile = NULL;
    WCHAR           HelpFileName[MAX_HELPFILE_NAME];
    DWORD           cb;
    DWORD           cb2;


    if (pPI->pHelpFile) {

        return(pPI->pHelpFile);
    }

    if ((!GetPrinterDriver(pPI->hPrinter, NULL, 3, NULL, 0, &cb))           &&
        (GetLastError() == ERROR_INSUFFICIENT_BUFFER)                       &&
        (pDI3 = (PDRIVER_INFO_3)LocalAlloc(LMEM_FIXED, cb))                 &&
        (GetPrinterDriver(pPI->hPrinter, NULL, 3, (LPBYTE)pDI3, cb, &cb))   &&
        (pDI3->pHelpFile)                                                   &&
        (pHelpFile = (LPWSTR)LocalAlloc(LMEM_FIXED,
                                        cbWSTR(pDI3->pHelpFile)))) {

        wcscpy(pHelpFile, (LPWSTR)pDI3->pHelpFile);

    } else if ((cb2 = LoadString(hPlotUIModule,
                                 IDS_HELP_FILENAME,
                                 &HelpFileName[1],
                                 COUNT_ARRAY(HelpFileName) - 1))            &&
               (cb2 = (cb2 + 1) * sizeof(WCHAR))                            &&
               (!GetPrinterDriverDirectory(NULL, NULL, 1, NULL, 0, &cb))    &&
               (GetLastError() == ERROR_INSUFFICIENT_BUFFER)                &&
               (pHelpFile = (LPWSTR)LocalAlloc(LMEM_FIXED, cb + cb2))       &&
               (GetPrinterDriverDirectory(NULL,
                                          NULL,
                                          1,
                                          (LPBYTE)pHelpFile,
                                          cb,
                                          &cb))) {

        HelpFileName[0] = L'\\';
        wcscat(pHelpFile, HelpFileName);

    } else if (pHelpFile) {

        LocalFree(pHelpFile);
        pHelpFile = NULL;
    }

    if (pDI3) {

        LocalFree((HLOCAL)pDI3);
    }

    PLOTDBG(DBG_SHOW_HELP, ("GetlotHelpFile: '%ws",
                                        (pHelpFile) ? pHelpFile : L"Failed"));

    return(pPI->pHelpFile = pHelpFile);
}