Announcement

Collapse
No announcement yet.

GetLastError - SetLastError

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • GetLastError - SetLastError

    Hi,

    please take a look at the following program:
    Code:
    #COMPILE EXE "c:\temp\test.exe"
    #INCLUDE "WIN32API.INC"
    
    SUB fctTest(BYVAL s AS STRING)
        CALL SetLastError(123)
    END SUB
    
    FUNCTION WINMAIN (BYVAL CurInst AS LONG, _
                      BYVAL PrvInst AS LONG, _
                      CmdLine AS ASCIIZ PTR, _
                      BYVAL CmdShow&) EXPORT AS LONG
    DIM lRet AS LONG
    DIM sTmp AS STRING
    
        sTmp = ""
        CALL fctTest(sTmp)
        lRet = GetLastError()
        MSGBOX STR$(lRet)
        
        sTmp = "abc"
        CALL fctTest(sTmp)
        lRet = GetLastError()
        MSGBOX STR$(lRet) 
    
    END FUNCTION
    What´s wrong with the string-routines in PBDLL?
    API-LastError must not be changed by PBDLL!
    (and if there must be an internal function like
    VB´s Err.LastDLLError)

    Thank you!
    ------------------

    mailto:[email protected][email protected]</A> www.selisoft.com

    [This message has been edited by Josef Lindinger (edited November 01, 2000).]

  • #2
    There is *nothing* wrong with the string routines themselves, so the problem is most likely to be connected to the Windows OLE string engine which is clearing SetLastError(). In other words, I do not believe it to be a PowerBASIC problem per se.

    I'll ask R&D about it and let you know what I find out.

    Thanks!


    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected]rbasic.com[email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Well ...
      For dynamic strings - OLE.
      But what is here ? MoveMemory ?

      Code:
         #Compile Exe
         #Register None
         #Dim All
         #Include "WIN32API.INC"
      
         Function PbMain
            Dim sTmp As String * 4
            SetLastError 123
            sTmp = "abc"
            MsgBox Str$(GetLastError)
         End Function
      ------------------
      E-MAIL: [email protected]

      Comment


      • #4
        If ByVal is not used in "fctTest" there appears to be no problem.
        Excerpt from "Win32.hlp":
        You should call the GetLastError function immediately when a function's return value indicates that such a call will return useful data.

        It appears the stack popping when returning from the function plays some role.
        If the function return value is assigned the value of GetLastError(), all is well.
        Or, if s$ is set to "" before SetLastError is called, all is well.
        Code:
         
        #Register None
        #Dim All
        #Option Version4
        #Include "WIN32API.INC"
         
         
        Function fctTest(ByVal s As String) As Long
          Static Cnt As Long
          Dim lRet As Long
          Incr cnt
          SetLastError 123+cnt
         
          Function = GetLastError()
        End Function
         
        Function WINMAIN (ByVal CurInst As Long, _
            ByVal PrvInst As Long, _
            CmdLine As Asciiz Ptr, _
            ByVal CmdShow&) As Long
             
          Dim lRet As Long
          Dim sTmp As String
          sTmp = ""
          lRet = fctTest(sTmp)
         
          StdOut "1st GLE:" & Str$(lRet)
         
          sTmp = "abc"
          lRet = fctTest(sTmp)
         
          StdOut "2nd GLE:" & Str$(lRet)
        End Function
        ------------------
        Ron

        [This message has been edited by Ron Pierce (edited November 02, 2000).]

        Comment


        • #5
          R&D are certainly on the ball today... here is their response:
          The ByVal string requires use of a temp buffer allocated from OLE string space. That space must be allocated and released by PB with Win32 API calls.

          GetLastError MUST be called IMMEDIATELY after an API function call, with no intervening API function calls, if it is to be of any value.

          That is simply not possible in a case like this. GetLastError is of little value except when called inline, immediately after another function call.

          No intervening compiler function calls or compiler function exits. That's how Windows works...

          ------------------
          Lance
          PowerBASIC Support
          mailto:[email protected][email protected]</A>
          Lance
          mailto:[email protected]

          Comment


          • #6
            Lance,

            Originally posted by Lance Edmonds:
            R&D are certainly on the ball today... here is their response:
            The ByVal string requires use of a temp buffer allocated from OLE string space. That space must be allocated and released by PB with Win32 API calls.

            GetLastError MUST be called IMMEDIATELY after an API function call, with no intervening API function calls, if it is to be of any value.

            That is simply not possible in a case like this. GetLastError is of little value except when called inline, immediately after another function call.

            No intervening compiler function calls or compiler function exits. That's how Windows works...
            Thank you for this information. But in this case, there must be a function like VB´s LastDllError.
            Please add this to the request-list for the next version.



            ------------------

            mailto:[email protected][email protected]</A> www.selisoft.com

            Comment

            Working...
            X