Link to home
Start Free TrialLog in
Avatar of Mikael Jansson
Mikael JanssonFlag for Sweden

asked on

Where are UploadPrinterDriverPackage and InstallPrinterDriverFromPackage in winspool.drv

Hi,
I have searched really hard to find how to call the methods UploadPrinterDriverPackage and InstallPrinterDriverFromPackage that are described in the "Printing and Print spooler functions" described on MSDN for Windows GDI. The documentation describes those methods and several other methods that are not found either. It refers to winspool as header and library and I assume that they then should be available in winspool.drv as the other methods described and working.

When I run Dumpbin on winspool.drv I dont find some of the functions described in the documentation on http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/prntspol_7mgj.asp

I am coding from both VB.NET but mainly from C#.NET in VS 2005 and uses many of the existing methods today in winspool.drv

I also have anothor smaller question related to calling e.g. winspool.drv methods, is it unsafe to use this kind of DllImport calls or can a application using this be successfully tested in Microsofts test program within Microsoft Certified partner program?

I really need help from you mega experts out there to solve this (the first question about winspool methods).

br

/ Mikael
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mikael Jansson

ASKER

Hi AlexFM,
Thanx for you eagle eyes :-) . My eyes was reading included in XP etc..... sometimes even the brain gets blind ;-)

thanks, you just saved me from searching on something thats not even there!

p.s. Maybe you know another way to solve this before vista?

/ Mikael
Avatar of houyaopan
houyaopan

These functions are not properly exported in the Winspool.drv, you can use LoadLibrary() and GetProcAddress() to get hold of those functions. Here is a sample code you can use:

#include "Winspool.h"

typedef HRESULT (*LPUploadPrinterDriverPackage)(
        LPCTSTR  pszServer,
        LPCTSTR  pszInfPath,
        LPCTSTR  pszEnvironment,
        DWORD    dwFlags,
        HWND     hwnd,
        LPTSTR   pszDestInfPath,
        PULONG   pcchDestInfPath
);

typedef HRESULT (*LPInstallPrinterDriverFromPackage)(
  LPCTSTR  pszServer,
  LPCTSTR  pszInfPath,
  LPCTSTR  pszDriverName,
  LPCTSTR  pszEnvironment,
  DWORD    dwFlags
);

DWORD MyInstallDriver(HWND     hwnd)
{
      TCHAR szDestInfPath[MAX_PATH*2 + 1];
      DWORD dwDestLen = MAX_PATH*2;
      LPUploadPrinterDriverPackage pUploadPackage = NULL;
      HINSTANCE hInstance = ::LoadLibrary(_TEXT("Winspool.drv"));
      pUploadPackage = (LPUploadPrinterDriverPackage)GetProcAddress(hInstance, "UploadPrinterDriverPackageW");
      if(pUploadPackage==NULL)
            return 0L;
      
      HRESULT lResult = pUploadPackage(
                                      NULL,
                                      _TEXT("MyDriver.inf"),
                                      _TEXT("Windows NT x86"),
                                      UPDP_SILENT_UPLOAD | UPDP_UPLOAD_ALWAYS,
                                      hwnd,
                                      szDestInfPath,
                                      &dwDestLen
      );

      LPInstallPrinterDriverFromPackage pInstallPackage = NULL;
      pInstallPackage = (LPInstallPrinterDriverFromPackage)GetProcAddress(hInstance, "InstallPrinterDriverFromPackageW");
      if(pInstallPackage!=NULL)
      {
            lResult = pInstallPackage(NULL,
                                    szDestInfPath,
                                    _TEXT("My Driver Name"),
                                    _TEXT("Windows NT x86"),
                                    IPDFP_COPY_ALL_FILES
                                    );
      }
      FreeLibrary(hInstance);
      return (DWORD)lResult;
}