Announcement

Collapse
No announcement yet.

Why does it result in GPF?

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

  • Why does it result in GPF?

    I am trying the followings w/o success:
    Code:
    #COMPILE EXE
    #INCLUDE "WIN32API.INC"
    %FORMAT_MESSAGE_FROM_HMODULE = &H800
    DECLARE FUNCTION InternetGetLastResponseInfo LIB "wininet.dll" ALIAS "InternetGetLastResponseInfoA" _
        (lpdwError AS DWORD, lpszErrorBuffer AS ASCIIZ, lpdwErrorBufferLength AS DWORD) AS INTEGER
    DECLARE SUB ErrorOut(BYVAL dwError AS LONG, szFunc AS STRING)
    
    GLOBAL szErrorMessage AS STRING
    FUNCTION PBMAIN
        DIM szFunc AS STRING
        szFunc = "Whatever "
        Errorout 0, szFunc
    END FUNCTION
    SUB ErrorOut(BYVAL dwError AS LONG, szFunc AS STRING)
        DIM dwRet AS LONG
        DIM dwTemp AS DWORD PTR
        DIM szString1 AS ASCIIZ * 256
        DIM szString AS ASCIIZ * 2048
        DIM szFile AS ASCIIZ * 12
        DIM lp AS LONG
        szFile  = "wininet.dll"
        lp = GetModuleHandle(szFile)
        dwRet = FormatMessage(%FORMAT_MESSAGE_FROM_HMODULE, _
                          lp, dwError, 0, _
                          szString1, 256, 0)
        szErrorMessage = szFunc & " error code: " & FORMAT$(dwError) & " Message: " & szString1
        IF (dwError = 12003) THEN
            ' Extended error information was returned
            dwRet = InternetGetLastResponseInfo(dwTemp, szString, 2048)
            szErrorMessage = szString
        END IF
    END SUB
    This work fine in VB, but in PB it causes GPF at FormatMessage.
    Any idea why?


    Regards,


    Peter Redei

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

  • #2
    don't know, but maybe the module handle? for ways to use formatmessage in
    pb, see: http://www.powerbasic.com/support/pb...ad.php?t=22769

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

    Comment


    • #3
      According to Win32api.inc the szBuffer is an Asciiz and you are
      passing a string. This will work in VB because VB has no native
      support for ASCIIZ's In VB you pass a string ByVal.

      Hope this helps
      Trevor

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

      Comment


      • #4
        Trevor, maybe I'm missing something, but which dynamic string is being passed to an API here? I only see ASCIIZ strings being passed to API functions.

        The problem that I can see is that InternetGetLastResponseInfo() expects the buffer size to be specified in TCHARS (Unicode characters) which means that the value passed for the buffer size should be 0.5 * the buffer byte size count, less the null-terminator character (two bytes in unicode). See http://msdn.microsoft.com/library/de...sponseinfo.asp

        Therefore, the call should look something like this:
        Code:
        dwRet = InternetGetLastResponseInfo(dwTemp, szString, [b](SIZEOF(szString) - 1) \ 2[/b])
        Finally, the buffer content will probably need to be converted to ANSI...

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

        Comment


        • #5
          One more thing: this API returns a BOOL, which should be translated to LONG in PowerBASIC, not INTEGER... therefore, the DECLARE statement is also incorrect.

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

          Comment


          • #6
            Oops,

            Sorry, I am sure the first time I read the code szString1 was dimensioned as a string. Obviously not I probably saw szFunc.



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

            Comment


            • #7
              Thank you for all replies.
              The problem Lance, is not with InternetGetLastResponseInfo. The program never gets there. It is already blowing at FormatMessage.
              I tried to use Semen's code following the link that Borje gave me and loading the library instead of GetModuleHandle, although the function I used returned a valid handle.
              It did not change anything. GPF as usual...
              Any other ideas?

              Regards,

              Peter Redei


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

              Comment


              • #8
                Never mind...
                Changing as

                dwRet = FormatMessage(%FORMAT_MESSAGE_FROM_HMODULE, _
                BYVAL lp, dwError, BYVAL 0&, _
                szString1, SIZEOF(szString1), BYVAL 0&)

                works.

                Thank you all.


                Regards,

                Peter Redei

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

                Comment

                Working...
                X