API help - Passing a variable as an 'adress'

Archives Forums/Win32 Discussion/API help - Passing a variable as an 'adress'

EOF(Posted 2009) [#1]
Structure
BOOL ReadConsole(

    HANDLE hConsoleInput,	// handle of a console input buffer 
    LPVOID lpBuffer,	// address of buffer to receive data 
    DWORD nNumberOfCharsToRead,	// number of characters to read 
    LPDWORD lpNumberOfCharsRead,	// address of number of characters read  
    LPVOID lpReserved 	// reserved 
   );

How would I pass a variable to the ReadConsole's lpBuffer?
As a Byte Ptr ?

I have tried the following but I never get any data back into the inp variable:


NOTE: The ReadConsoleA finishes only after the user has pressed return. In which case, the function *should* return keyboard buffer input into inp


Extern "Win32"
   Function ReadConsoleA(hbuffIN%,lBuff:Byte Ptr,numCharsToRead%,nCharsRead%,Reserved%)
End Extern

....

Function GetInput$()
  Local inp:Byte Ptr
  ReadConsoleA stdIN,inp,16383,Null,0
  Return String.FromCString(inp)
End Function



Azathoth(Posted 2009) [#2]
Does inp contain any data? MSDN doesn't say about it being a string.


EOF(Posted 2009) [#3]
Going by the ReadConsole structure the second parameter should be the address of buffer to receive data
I take it this means the function will pull X amount of characters from the input console window (after the user presses RETURN) and pass them back into this location
The confusion for me though is, the parameter does not seem to be a pointer as such, but an address. I don't know how to access this via Max


I have tried VarPtrs, Shorts, Bytes, Arrays. All to no avail

inp is always 0


Azathoth(Posted 2009) [#4]
You should be allocating the buffer because by your example you're basically passing 0 to ReadConsole.

http://msdn.microsoft.com/en-us/library/ms684958(VS.85).aspx


EOF(Posted 2009) [#5]
Thanks so far Paul
Any ideas on how to pass an allocated buffer?
I tried this but still 'no go' ...

(NOTE: Using W version of ReadConsole)

Upon testing the return code of ReadConsoleW it always 0 which indicates that it is constantly failing

Extern "Win32"
    Function ReadConsoleW(hbuffIN%,lBuffAddr:Short,numCharsToRead%,nCharsRead%,Reserved%)
End Extern

....

Function GetInput$()
    Local inp:Short[16384]
    Local ncr%
    ReadConsoleW StdIN,inp[0],inp.Length,ncr,Null
    Return String.FromWString(inp)
End Function



Azathoth(Posted 2009) [#6]
Thanks so far Paul
Any ideas on how to pass an allocated buffer?
I tried this but still 'no go' ...

Use either 'inp' or 'Varptr inp[0]' to get the address of an array.
The address of ncr needs to be passed as it's an out parameter, so your original code should be something like

Extern "Win32"
   Function ReadConsoleA(hbuffIN%,lBuff:Byte Ptr,numCharsToRead%,lpNumberOfCharsRead:Int Ptr,Reserved%)
End Extern

....

Function GetInput$()
  Local inp:Byte[16384]
  Local ncr%

  ReadConsoleA stdIN,Varptr inp[0],inp.length,Varptr ncr,0
  Return String.FromCString(inp)
End Function



The MSDN page I linked states to use unicode the last parameter needs to be a pointer to a 'CONSOLE_READCONSOLE_CONTROL' structure.


EOF(Posted 2009) [#7]
Excellent. It's working now. Great help Paul .. many thanks