Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
HDC Using VBPrinter.OCX
Message
From
09/09/2004 05:01:50
 
 
To
All
General information
Forum:
Windows
Category:
API
Title:
HDC Using VBPrinter.OCX
Miscellaneous
Thread ID:
00940522
Message ID:
00940522
Views:
81
My VFP 6/8 app uses VBPrinter to get a Device Context Handle (hDC) to a printer or PDF Driver, allowing users to select a driver and modify preferences before sending a non VFP Graphics output to the hDC for printing. This has worked well for years, but suddenly I find in WinXP and Win2000 that a negative integer is sometimes being returned, caused by too large a number being wrapped around to a negative by the code below. For example the value returned by the HexToBin function below is 2652965944 (Type "U" in VFP), and is being transformed in the BITOR function to
-1642001352. This is obviously an invalid hDC. Can anyone suggest a work around?


Here is the code used to get the hDC
declare integer CreateDC in Win32API string, string, string, string
	declare integer PrintDlg in comdlg32.dll string @


	cPD = ""
	cPD = cPD + chr(66) + chr(0) + chr(0) + chr(0)				&& lStructSize
	cPD = cPD + chr(0) + chr(0) + chr(0) + chr(0)				&& hwndOwner
	cPD = cPD + chr(0) + chr(0) + chr(0) + chr(0)				&& hDevMode
	cPD = cPD + chr(0) + chr(0) + chr(0) + chr(0)				&& hDevNames
	cPD = cPD + chr(0) + chr(0) + chr(0) + chr(0)				&& hDC
	cPD = cPD + chr(4 + 8) + chr(1) + chr(0) + chr(0)			&& Flags (see commdlg.h)
	cPD = cPD + chr(1) + chr(0)									&& nFromPage
	cPD = cPD + chr(1) + chr(0)									&& nToPage
	cPD = cPD + chr(0) + chr(0)									&& nMinPage
	cPD = cPD + chr(0) + chr(0)									&& nMaxPage
	cPD = cPD + chr(1) + chr(0)									&& nCopies
	cPD = cPD + chr(0) + chr(0) + chr(0) + chr(0)				&& hInstance
	cPD = cPD + chr(0) + chr(0) + chr(0) + chr(0)				&& lCustData
	cPD = cPD + chr(0) + chr(0) + chr(0) + chr(0)				&& lpfnPrintHook
	cPD = cPD + chr(0) + chr(0) + chr(0) + chr(0)				&& lpfnSetupHook
	cPD = cPD + chr(0) + chr(0) + chr(0) + chr(0)				&& lpPrintTemplateName
	cPD = cPD + chr(0) + chr(0) + chr(0) + chr(0)				&& lpSetupTemplateName
	cPD = cPD + chr(0) + chr(0) + chr(0) + chr(0)				&& PrintTemplate
	cPD = cPD + chr(0) + chr(0) + chr(0) + chr(0)				&& SetupTemplate

	if PrintDlg(@cPD) = 0
		return .F.
	endif
	
	this.HDC = BITOR(this.HexToBin(substr(cPD, 17, 4)), 0)

FUNCTION HextoBin
parameter cHex

* Converts a 4 character string into an integer

return ;
	asc(substr(cHex, 1, 1)) * 0x00000001 + ;
	asc(substr(cHex, 2, 1)) * 0x00000100 + ;
	asc(substr(cHex, 3, 1)) * 0x00010000 + ;
	asc(substr(cHex, 4, 1)) * 0x01000000
Thanks in advance
Next
Reply
Map
View

Click here to load this message in the networking platform