George,
no idea why...
Anyway, digging in the past, I found an interesting thread opened by
Andy Rintoul in 2002 with a couple of functions, SetPrinter and
GetPrinter, that seem to be what you're looking for; here they are:
--------------------------------------------------------------------------------
FUNCTION SetW2KDefPrinter(cPrinter AS STRING) AS LOGIC
// Set the given printer to be the default printer
// cPrinter: name of printer to be made default
// returns whether successful
LOCAL done AS LOGIC
LOCAL hModule AS PTR
LOCAL pSet AS PSZ PTR
LOCAL pszPrinter AS PSZ PTR
LOCAL pszError AS PSZ
done := FALSE
hModule := _VOLoadLibrary(String2Psz("winspool.drv"))//.drv NOT .dll
IF hModule == NULL_PTR
done := FALSE
// Show error msg
ELSE
pSet := GetProcAddress(hModule, PSZ("SetDefaultPrinterA"))
// "SetDefaultPrinterW" for UNICODE
IF pSet == NULL_PTR
done := FALSE
// Show error msg
ELSE
pszPrinter := PSZ(cPrinter)
IF PCALL(pSet, pszPrinter) = NULL_PTR
done := FALSE
FormatMessage( ;
FORMAT_MESSAGE_ALLOCATE_BUFFER + FORMAT_MESSAGE_FROM_SYSTEM,;
NULL,;
GetLastError(),;
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),; // Default language
@pszError,;
0,;
NULL)
// Show error msg including pszError
LocalFree(pszError)
ELSE
Done := TRUE
ENDIF
// Tell all open programs about the change
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0L, 0L,;
SMTO_NORMAL, 1000, NULL)
ENDIF
ENDIF
RETURN done
--------------------------------------------------------------------------------
FUNCTION GetW2KDefPrinter() AS STRING
LOCAL hModule AS PTR
LOCAL pGet AS PSZ PTR
LOCAL cPrinter AS STRING
LOCAL dwNeeded AS DWORD
LOCAL PrintBuff AS PSZ PTR
dwNeeded := 0 //geoff's suggest
hModule := _VOLoadLibrary(String2Psz("winspool.drv")) //.drv NOT .dll
IF hModule == NULL_PTR
// Show error msg
ELSE
pGet := GetProcAddress(hModule, PSZ("GetDefaultPrinterA"))
// "GetDefaultPrinterW" for UNICODE
IF pGet == NULL_PTR
// Show error msg
ELSE
PCALL(pGet, NULL_PSZ, @dwNeeded)
IF dwNeeded > 0
PrintBuff := PSZ(Space(dwNeeded))
PCALL(pGet, PrintBuff, @dwNeeded)
IF PrintBuff == NULL_PTR
// Show error msg
ELSE
cPrinter := Psz2String(PrintBuff)
ENDIF
ELSE
// Show error msg
ENDIF
ENDIF
ENDIF
RETURN cPrinter
--------------------------------------------------------------------------------
(not well indented, but...)
It compiles without errors in 2.7.
The functions were written for W2K, but I suppose they'll work on Win7
too; I've no time to make a try, so let me know.
HTH,
Francesco