Try to cast it to signed long using BITOR() function.
nHDC = BITOR(DWORDToNum(substr(cPD, 17, 4)), 0)
>I have a rather tricky problem and wonder if anyone can suggest a solution.
>Below is some straightforward code to display the Windows Printer Dialog
>and return an hDC for the selected device and settings. This works fine,
>returning a LONG that can be used to send output to the printer. The trouble
>is that the LONG is unsigned and in Windows 2000/XP can exceed the magic
>figure of 2147483647. The application I'm sending output to is a 32bit ActiveX (OCX) and does not like numbers in excess of this - it returns an OLE error message "Out of Current Range". I've taken this up with the vendors of the ActiveX application and they do not appear to understand my problem, saying "why not set the PrintDlg parameters to return a signed LONG?". I have no idea whether this is possible in VFP, or how.
>Any ideas anyone?
>Awaiting in hopeful anticipation.
>Mike Rothery
>Here is my code....
>
>FUNCTION GethDC
>declare integer PrintDlg in comdlg32.dll string @
>
>
>cPD = ""
< snip >
>
>if PrintDlg(@cPD) = 0
>return .F.
>endif
>nHDC = DWORDToNum(substr(cPD, 17, 4))
>if nHDC = 0
>return .F.
>endif
>
>FUNCTION DWORDToNum
>PARAMETERS tcWord
>LOCAL i, lnWord
>
>*-- Ensure word is 4 bytes, 0-filled to right
>tcWord = PADR(tcWord, 4, CHR(0))
>
>*-- First byte is least significant
>lnWord = 0
>FOR i = 1 TO 4
>lnWord = lnWord + (ASC(SUBSTR(tcWord, i, 1)) * (2 ^ (8 * (i - 1))))
>ENDFOR
>
>RETURN lnWord
--sb--