I tried this in the shortcut target..
Code:
C:\WINDOWS\system32\cmd.exe /C Start D:\Software_Development\pbwin80\work\test_getStdHandle_stdout.exe
C:\WINDOWS\system32\cmd.exe /C Start D:\Software_Development\pbwin80\work\test_getStdHandle_stdout.exe
%windir%\system32\cmd.exe "/c start notepad"
REM test_start.cmd REM Echo Testing launch Start d:\Software_Development\pbwin80\work\test_getStdhandle_stdout.exe
#COMPILE EXE #DEBUG ERROR ON #REGISTER NONE #DIM ALL #TOOLS OFF '=====[Windows API Header Files] ============================ ' If you don't need all of the functionality supported by these APIs ' (and who does?), you can selectively turn off various modules by putting ' the following constants in your program BEFORE you #include "win32api.inc": ' ' %NOGDI = 1 ' no GDI (Graphics Device Interface) functions ' %NOMMIDS = 1 ' no Multimedia ID definitions %NOMMIDS = 1 #INCLUDE "WIN32API.INC" '==[End Windows API Header Files]============================ #IF NOT %DEF (%SYSEMT_INC) %SYSEMT_INC = 1 FUNCTION SystemErrorMessageText (BYVAL ECode AS LONG) AS STRING LOCAL Buffer AS ASCIIZ * 255 FormatMessage %FORMAT_MESSAGE_FROM_SYSTEM, BYVAL %NULL, ECode, %NULL, buffer, SIZEOF(buffer), BYVAL %NULL FUNCTION = FORMAT$(ECode, "##### ") & Buffer END FUNCTION #ENDIF #IF %DEF(%PB_WIN32) FUNCTION STDOUT (Z AS STRING) AS LONG ' returns TRUE (non-zero) on success LOCAL hStdOut AS LONG, nCharsWritten AS LONG LOCAL nStdHandle AS DWORD ' casting problems> LOCAL w AS STRING STATIC CSInitialized AS LONG, CS AS CRITICAL_SECTION LOCAL iRET AS LONG, LE AS LONG ' ------------------------ IF ISFALSE CSInitialized THEN InitializeCriticalSection CS CSInitialized = 1 END IF nStdHandle = BITS???(%STD_OUTPUT_HANDLE) 'STD_OUTPUT_HANDLE defined in Win32API.INC as -11& EntercriticalSection Cs hStdOut = GetStdHandle (nStdHandle) ' per Win32API.INC wants DWORD param, returns DWORD MSGBOX USING$ ("hStdout # & ", hStdout, HEX$(hStdOut, 8)) SELECT CASE AS LONG hStdOut CASE %NULL, -1& iRet = AllocConsole ' OK, it creates the first time LE = GetLAstError #IF 0 IF ISFALSE iRet THEN MSGBOX "Could not create Console" & $CRLF & SystemErrorMessageText (LE) ELSE MSGBOX "Created Console" END IF #ENDIF hStdOut = GetStdHandle (%STD_OUTPUT_HANDLE) END SELECT LeaveCriticalSection CS w = Z & $CRLF iRet = WriteFile(hStdOut, BYVAL STRPTR(W), LEN(W), nCharsWritten, BYVAL %NULL) LE = GETLastError FUNCTION = iRet #IF 1 IF ISFALSE iREt THEN MSGBOX SystemErrorMessageTExt(LE),,"WriteFile Failed" ' 2/18/08 its failing on invalid handle. but I am getting a value of 7 which should be valid ' I am NOT creating it... I am inheriting it. What If I create my own instead? ' See 'fix' above using GetConsoleWindow. This code is not going to work ' on Win/98 anymore. END IF #ENDIF FUNCTION = iRet ' true is good END FUNCTION #ENDIF #IF NOT %DEF (%INVALID_HANDLE_VALUE_LONG) %INVALID_HANDLE_VALUE_LONG = -1& #ENDIF FUNCTION WINMAIN (BYVAL hInstance AS LONG, _ BYVAL hPrevInstance AS LONG, _ BYVAL lpCmdLine AS ASCIIZ PTR, _ BYVAL iCmdShow AS LONG) AS LONG ' do exactly one "stdout" just to get the values LOCAL S AS STRING S = "First" STDOUT S ' do the second one to make sure it writes S = "Second" STDOUT S ' hold the console open MSGBOX "Check COnsole" '04/21/08 Working perfectly from within the PB ide. (Compile and execute) ' ' Returns hstdout = 7 when exe is run from command prompt, hStdout= 7 (not zero, not INVALID_HANDLE_VALUE ' but writefile fails on error 6, "the handle is invalid" ' ' when run from desktop shortcut, returns hStdout = 65537d (0x00010001) and again WriteFile ' fails on error 6 the handle is invalid. ' Windows/XP Pro, all service packs and updates. PB/Win 8.03 END FUNCTION
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: