Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DECLARE and USING API HOW?
Message
From
28/01/1999 21:21:16
 
 
To
28/01/1999 20:48:23
Tossapon Nanagara
AstraZeneca (Thailand) Ltd.
Bangkok, Thailand
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00181630
Message ID:
00181638
Views:
15
>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.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform