>I try to use win32api by re-create from VB code -
>
>Const STD_INPUT_HANDLE& = -10
>Const STD_OUTPUT_HANDLE& = -11
>Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) As Long
>
>Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped As Long) As Long
>and the they call the function
> STDIN = GetStdHandle(STD_INPUT_HANDLE)
> Call ReadFile(STDIN, bPostData(1), Val(ContentLength), lReaded, 0)
>
>I try to do this in VFP but cant get it work would anyone give me some suggest ;-
>My code
> DECLARE Long GetStdHandle IN KERNEL32 ByVal nStdHandle As Long
>DECLARE long ReadFile IN win32api ByVal hFile As Long, lpBuffer As Any, ByVal
nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped
As Long
The ByVal and ByRef operators don't exist in VFP, there is no ANY type, but you can simulate a buffer with a string. I would not recommend using an overlapped structure; instead, I'd declare it as an integer type and pass 0 to represent a null pointer.
Try:
DECLARE INTEGER GetStdHandle IN KERNEL32.DLL INTEGER nStHandle
DECLARE INTEGER ReadFile IN WIN32API ;
INTEGER hFile, ;
STRING @ lpBUffer, ;
INTEGER nBytesToRead, ;
INTEGER nBytesActuallyRead, ;
INTEGER lpOverlapped
LOCAL hStdOut, hStdIn, cBuff, nBytesRead, nResult
hStdOut = GetStdHandle(-11)
hStdIn = GetStdHandle(-10)
cBuff=SPACE(256)
nBytesRead = 0
nResult = ReadFile(hStdIn, ;
@cBuff, ;
256, ;
@nBytesRead, ;
0)
>PUBLIC hnSTDOUT,hnSTDIN
Don't use PUBLICs if you can avoid it. There is just too much wierdness, and it's bad OOP. If a function, procedure or method need them, pass them to whatever needs the values, or stick them in properties of a known object.
>hnSTDOUT=GetStdHandle(@STD_OUTPUT_HANDLE)
You can't pass a constant by reference. You'd have to #DEFINE STD_OUTPUT_HANDLE or it must be in a file in a #INCLUDE. For brevity, i just used the constants defined in WINBASE.H directly.
This code is untested; I did it off the top of my head. It's generally correct but it hasn't been checked for typos or against the declarations in the MSDN docs.