Home > Software engineering >  I use the console in vb API found several strange place
I use the console in vb API found several strange place

Time:10-21

Is at the time of input and output in the console API in the requirement to handle input and output is fixed with the several plant
 Option Explicit 

Public Declare Function AllocConsole Lib "kernel32 () As" Long

Public Declare Function WriteConsole Lib "kernel32" Alias "WriteConsoleA" (ByVal hConsoleOutput As Long, lpBuffer As Any, ByVal nNumberOfCharsToWrite As Long, lpNumberOfCharsWritten As Long, lpReserved As Any) As Long

Public Declare Function ReadConsole Lib "kernel32" Alias "ReadConsoleA" (ByVal hConsoleInput As Long, lpBuffer As Any, ByVal nNumberOfCharsToRead As Long, lpNumberOfCharsRead As Long, lpReserved As Any) As Long



Sub main ()
Dim As a String * 3
AllocConsole
WriteConsole 11, ByVal "hello_world", 12, 0, 0 'can you tell me why does it have to be fixed is 7 or 11 here
ReadConsole 3, ByVal a, 2, 0, 0 'why fixed here also 3
End Sub

And the GetStdHandle result is the same and that several plant really have what meaning

CodePudding user response:

Reference: http://binaryworld.net/Main/CodeDetail.aspx? CodeId=2200 # copy

CodePudding user response:

Check out this

CodePudding user response:

This is not the disadvantages of constant definition,
All constant looks is a magic number, cloud mountain fog cover!

CodePudding user response:

Don't understand, you have set a fixed length string not 3 what is it

CodePudding user response:

All the magic number in the include \ *. H file is defined,

CodePudding user response:

The console screen processing example program and a terminal window screen processing related API use examples, from MSVC20 \ SAMPLES \ win32 \ console \
http://download.csdn.net/detail/zhao4zhong1/3461309

CodePudding user response:

Don't understand...

CodePudding user response:

reference 5 floor zhao4zhong1 reply:
all magic number in the include \ *. H file is defined,

Magic number problem is a problem of coding standards,
Where to check information doesn't belong to the coding standards.

CodePudding user response:

The question is: see the parameters of the API, should be introduced to "handle",
But the actual call, the incoming is not like handle ah,

CodePudding user response:

references 9 f Chen8013 response:
problem: see the parameters of the API, should be introduced to "handle",
But the actual call, the incoming is not like handle ah,

Because actual getstdhandle function are used, and the result of the getstdhandle always returns that a few values

CodePudding user response:

Download a better API browser, contains the parameter specification.
Recommend a: FoxAPI
  •  Tags:  
  • API
  • Related