Announcement

Collapse
No announcement yet.

URLMON.DLL reports bad entry point, but runs another function

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

  • URLMON.DLL reports bad entry point, but runs another function

    The following code compiles under PBWin9 with no errors, but at runtime I get this message:

    MyApp.exe - Entry Point Not Found
    X The procedure entry point IsValidUrl could not be located in the dynamic link library URLMON.DLL
    Here's the info on the URLMON.DLL that resides in c:\Windows\system32 (I searched but found no other copies)

    urlmon.dll 1,159,680 .a.. 2008-06-23 11:57:40

    I'm on Win XP Pro SP3, up to date.

    I'm not sure what to make of this, since the Download in Block 2 shows that URLMON.DLL is doing something OK... (Comment out Block 1, the CheckURL function, and the Declares for IsValidURL; the Block 2 code runs fine...)

    Help?
    Thanks,
    -John



    Code:
    'URLMON_test.bas
    
    #Compiler PBWin 9
    #Compile Exe  "URLMON_test.exe"
    #Dim All
    #Include "win32api.inc"
    
    Declare Function URLDownloadToFile Lib "urlmon.dll" Alias "URLDownloadToFileA" (pCaller As Any, szURL As Asciiz, szFileName As Asciiz, ByVal dwReserved As Dword, ByVal lpfnCB As Dword) As Long
    
    #If 10  'not sure if either is correct...
    Declare Function IsValidUrl Lib "URLMON.DLL" Alias "IsValidUrl" ( _
          ByVal LPBC       As Asciiz Ptr  _                       ' /* [in] */ LPBC pbc
        , ByVal LPCWSTR    As Asciiz Ptr  _                       ' /* [in] */ LPCWSTR szURL
        , ByVal dwReserved As Dword _                       ' /* [in] */ DWORD dwReserved
        ) As Long                             ' HRESULT
    #Else
    Declare Function IsValidUrl Lib "URLMON.DLL" Alias "IsValidUrl" ( _
          ByVal LPBC       As Dword _                       ' /* [in] */ LPBC pbc
        , ByVal LPCWSTR    As Dword _                       ' /* [in] */ LPCWSTR szURL
        , ByVal dwReserved As Dword _                       ' /* [in] */ DWORD dwReserved
        ) As Long                             ' HRESULT
    'pBC
    '[in] A pointer to the IBindCtx interface. This parameter is currently ignored. It should be set to NULL.
    'szURL
    '[in] A pointer to a string value that contains the full URL to check.
    'dwReserved
    '[in] Reserved. Must be set to 0.
    #EndIf
    
    Function PBMain As Long
       Local test, SourceFile, SaveFilename As String, lRet As Long
    
    'Block 1
       'test = "http://www.mydomain.com"
       test = "http://www.mydomain.com/xyz/index.html"
       If CheckURL(test) = 0 Then
          MsgBox "is NOT a valid URL",,test
          Function = %FALSE
       Else
          MsgBox "is a valid URL",,test
          Function = %TRUE
       End If
    
    
    'Block 2
       'SourceFile = "www.powerbasic.com/index.htm"
       'SourceFile = "http://mises.org/story/3290"
       SourceFile = "http://mises.org/articles.aspx"
       SaveFilename = "C:\discard_me.htm"
       lRet  = URLDownloadToFile(ByVal 0, ByCopy SourceFile, ByCopy SaveFilename, 0, 0)
       MsgBox "URL Download to file returned: " & Trim$(Str$(lRet)),,"Download result"
    End Function
    
    
    
    Function CheckURL(ByVal URL As String) As Long
       Local SourceFile As Asciiz * %MAX_PATH
       Dim pSourceFile As Asciiz Pointer
    
       SourceFile = URL
       pSourceFile = VarPtr(SourceFile)  'is this right?
    
       If IsValidURL(0, pSourceFile, 0) = 0 Then      'goes to URLMON.DLL
          Function = %FALSE    'URL is NOT valid
       Else
          Function = %TRUE     'URL is valid
       End If
    End Function

  • #2
    Code:
    Listing of exported functions for file C:\WINDOWS\system32\urlmon.dll
    Run Date & Time 02-11-2009    18:09:51
    ...
    IsStringProperty
    [B]IsValidURL[/B]
    MkParseDisplayNameEx
    ....        END OF REPORT    115  items printed

    Show exports and imports for PB/Win 6x, 7x (original by Torsten Reinow)

    (works good as you can see).

    MCM
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Originally posted by Michael Mattias View Post
      Code:
      Listing of exported functions for file C:\WINDOWS\system32\urlmon.dll
      Run Date & Time 02-11-2009    18:09:51
      ...
      IsStringProperty
      [B]IsValidURL[/B]
      MkParseDisplayNameEx
      ....        END OF REPORT    115  items printed

      Show exports and imports for PB/Win 6x, 7x (original by Torsten Reinow)

      (works good as you can see).

      MCM

      Thanks, Michael,
      Two questions:
      1. in the "Type IMAGE_DOS_HEADER" there's this line:
      Code:
        e_cblp                      ”¦’‘p;nbsp;        AS WORD
      I've never seen that kind of notation, and have no clue what it's supposed to do. Neither does the compiler (PBWin9).

      2.
      ...
      IsStringProperty
      IsValidURL
      MkParseDisplayNameEx
      ....
      Your display confirms that the routine I wanted to use actually is in URLMON.DLL, but I'm not sure how this helps me make sense of the error message I'm getting. What am I missing?

      -John

      ...passing of time...
      The more I think about it, the more I think my DECLARE for IsValidURL must be the problem.

      Can someone take a look and see if I'm misunderstanding how to translate the API params to PB?
      Thanks!

      Comment


      • #4
        This one is usable:

        Code:
        Declare Function IsValidUrl Lib "URLMON.DLL" Alias "IsValidUrl" ( _
              ByVal LPBC       As Dword _                       ' /* [in] */ LPBC pbc
            , ByVal LPCWSTR    As Dword _                       ' /* [in] */ LPCWSTR szURL
            , ByVal dwReserved As Dword _                       ' /* [in] */ DWORD dwReserved
            ) As Long                             ' HRESULT
        The LPBC parameter should be IUnknown instead of Dword, but as it is unused it doesn't matter.

        This if flat wrong:

        Code:
        Function CheckURL(ByVal URL As String) As Long
           Local SourceFile As Asciiz * %MAX_PATH
           Dim pSourceFile As Asciiz Pointer
        
           SourceFile = URL
           pSourceFile = VarPtr(SourceFile)  'is this right?
        
           If IsValidURL(0, pSourceFile, 0) = 0 Then      'goes to URLMON.DLL
              Function = %FALSE    'URL is NOT valid
           Else
              Function = %TRUE     'URL is valid
           End If
        End Function
        Use:

        Code:
        Function CheckURL(ByVal URL As String) As Long
           Local SourceFile As String
        
           SourceFile = UCODE$(URL & $NUL)
        
           If IsValidURL(0, STRPTR(SourceFile), 0) = 0 Then      'goes to URLMON.DLL
              Function = %FALSE    'URL is NOT valid
           Else
              Function = %TRUE     'URL is valid
           End If
        End Function
        Forum: http://www.jose.it-berater.org/smfforum/index.php

        Comment


        • #5
          Hi John,

          I think Michael was a little too cryptic. The vital point to note is that the exported function names are case-sensitive.

          i.e. Alias "IsValidUrl" <> Alias "IsValidURL"

          So, this declaration seems to work for me:

          Code:
          DECLARE FUNCTION IsValidUrl LIB "URLMON.DLL" ALIAS "IsValidURL" ( _
                BYVAL LPBC       AS DWORD _                       ' /* [in] */ LPBC pbc
              , BYVAL LPCWSTR    AS ASCIIZ PTR _                       ' /* [in] */ LPCWSTR szURL
              , BYVAL dwReserved AS DWORD _                       ' /* [in] */ DWORD dwReserved
              ) AS LONG                             ' HRESULT
          Edit: I'd rather trust José for the parameters and usage, so ignore my declaration, apart from the ALIAS "IsValidURL", which you will still need to change.
          Edit2: Although, oddly, the code only works for me if I don't use the UCODE$() in the CheckURL routine. The code I'm using which DOES work is:

          Code:
          'URLMON_test.bas
          
          #COMPILER PBWIN 9
          #COMPILE EXE  "URLMON_test.exe"
          #DIM ALL
          #INCLUDE "win32api.inc"
          
          DECLARE FUNCTION URLDownloadToFile LIB "urlmon.dll" ALIAS "URLDownloadToFileA" (pCaller AS ANY, szURL AS ASCIIZ, szFileName AS ASCIIZ, BYVAL dwReserved AS DWORD, BYVAL lpfnCB AS DWORD) AS LONG
          
          DECLARE FUNCTION IsValidUrl LIB "URLMON.DLL" ALIAS "IsValidURL" ( _
                BYVAL LPBC       AS DWORD _                       ' /* [in] */ LPBC pbc
              , BYVAL LPCWSTR    AS DWORD _                       ' /* [in] */ LPCWSTR szURL
              , BYVAL dwReserved AS DWORD _                       ' /* [in] */ DWORD dwReserved
              ) AS LONG                             ' HRESULT
          'pBC
          '[in] A pointer to the IBindCtx interface. This parameter is currently ignored. It should be set to NULL.
          'szURL
          '[in] A pointer to a string value that contains the full URL to check.
          'dwReserved
          '[in] Reserved. Must be set to 0.
          
          
          FUNCTION PBMAIN AS LONG
             LOCAL test, SourceFile, SaveFilename AS STRING, lRet AS LONG
          
          'Block 1
             'test = "http://www.mydomain.com"
             test = "http://www.mydomain.com/xyz/index.html"
             IF CheckURL(test) = 0 THEN
                MSGBOX "is NOT a valid URL",,test
                FUNCTION = %FALSE
             ELSE
                MSGBOX "is a valid URL",,test
                FUNCTION = %TRUE
             END IF
          
          
          'Block 2
             'SourceFile = "www.powerbasic.com/index.htm"
             'SourceFile = "http://mises.org/story/3290"
             SourceFile = "http://mises.org/articles.aspx"
             SaveFilename = "C:\discard_me.htm"
             lRet  = URLDownloadToFile(BYVAL 0, BYCOPY SourceFile, BYCOPY SaveFilename, 0, 0)
             MSGBOX "URL Download to file returned: " & TRIM$(STR$(lRet)),,"Download result"
          END FUNCTION
          
          
          
          FUNCTION CheckURL(BYVAL URL AS STRING) AS LONG
             LOCAL sSource AS STRING
          
             sSource = URL & $NUL
          
             IF IsValidURL(0, STRPTR(sSource), 0) = 0 THEN      'goes to URLMON.DLL
                FUNCTION = %FALSE    'URL is NOT valid
             ELSE
                FUNCTION = %TRUE     'URL is valid
             END IF
          END FUNCTION
          Regards,

          Pete.
          Last edited by Peter Jinks; 11 Feb 2009, 07:51 PM. Reason: José's superior knowledge!

          Comment


          • #6
            Michael, Jose, Peter,

            Thank you, each and all! After cleaning up my code AND fixing the capitalization in the DECLARE, it's running fine.

            Peter, I'm not sure yet if your version is working on my machine (still testing), but Jose's is (did his changes first)...

            Thanks, fellers!
            -John
            Last edited by John Montenigro; 11 Feb 2009, 08:14 PM.

            Comment


            • #7
              >The vital point to note is that the exported function names are case-sensitive

              Top Ten Things Every Windows' Programmer should know?
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                Code:
                Listing of exported functions for file C:\WINDOWS\system32\urlmon.dll
                Run Date & Time 02-11-2009    18:09:51
                .....
                You know I really should add the file version to that print report, shouldn't I?

                Or, he hinted, someone else could do it and post the updated source code as reply.

                Here's some starter (!) code:
                Code:
                ' get version of any file
                ' removed leading space from major 8/24/07
                FUNCTION FileVersionString(szFile AS ASCIIZ) AS STRING
                  LOCAL major AS LONG, Minor AS LONG, Build AS LONG, SubBuild AS LONG
                  LOCAL ResSize AS LONG
                  LOCAL ffi  AS VS_FIXEDFILEINFO PTR
                  LOCAL  ret AS LONG
                  LOCAL Buffer AS STRING, DLLDate AS STRING
                
                  Major=0: Minor = 0:  Build = 0
                
                  ResSize = GetFileVersionInfoSize (szFile, ret)
                  IF ResSize= 0 THEN
                    FUNCTION = "No Version Info"
                    EXIT FUNCTION
                  END IF
                
                  Buffer = SPACE$(ResSize)
                  Ret =  GetFileVersionInfo(szFile, %NULL, ResSize, BYVAL STRPTR(Buffer))
                
                ' ** Read the VS_FIXEDFILEINFO info
                  VerQueryValue BYVAL STRPTR(Buffer), "\", ffi, SIZEOF(@ffi)
                  Major        = @ffi.dwProductVersionMs  \ &h10000
                  Minor        = @ffi.dwProductVersionMs MOD &h10000
                  Build        = @ffi.dwProductVersionLS MOD &h10000  ' this is for MY software which uses VERSION_MAJOR, VERSION_MINOR, 0, VERSION_BUILD under FILEVERSION
                '  SubBuild     = @ffi.dwProductVersionLS \  &h10000
                  ' combine
                
                ' 8/24/07 WAS:
                  FUNCTION = STR$(Major) & "." & TRIM$(STR$(Minor)) & "." & LTRIM$(STR$(Build))   ' & "." & LTRIM$(STR$(SubBuild))
                ' changed to: (to remove leading space)
                  FUNCTION = FORMAT$(Major) & "." & FORMAT$(Minor) & "." & FORMAT$(Build)   ' & "." & FORMAT$(SubBuild)
                
                
                END FUNCTION
                ' --------------------------------------------------------------------
                '  GET THE VERSION STRING FOR A LOADED FILE GIVEN ITS INSTANCE HANDLE
                '  THis is the same as ProgramVersion string except it uses hLib
                '  to get the file name instead of BYVAL %NULL)
                '  Added 9.22.08
                ' ----------------------------------------------------------------------
                
                FUNCTION hInstanceVersionString (BYVAL hlIb AS LONG) AS STRING
                
                      LOCAL major AS LONG, Minor AS LONG, Build AS LONG
                  LOCAL szFile AS ASCIIZ * %MAX_PATH
                  LOCAL ResSize AS LONG
                  LOCAL ffi  AS VS_FIXEDFILEINFO PTR
                
                  LOCAL  ret AS LONG
                  LOCAL Buffer AS STRING, DLLDate AS STRING
                  Major=0: Minor = 0:  Build = 0
                
                  GetModuleFileName BYVAL hLib, szFile, SIZEOF(szFile)
                  ResSize = GetFileVersionInfoSize (szFile, ret)
                  IF ResSize= 0 THEN
                    FUNCTION = "Error"
                    EXIT FUNCTION
                  END IF
                
                  Buffer    = SPACE$(ResSize)
                  Ret       = GetFileVersionInfo(szFile, %NULL, ResSize, BYVAL STRPTR(Buffer))
                
                ' ** Read the VS_FIXEDFILEINFO info
                  VerQueryValue BYVAL STRPTR(Buffer), "\", ffi, SIZEOF(@ffi)
                  Major      = @ffi.dwProductVersionMs  \ &h10000
                  Minor      = @ffi.dwProductVersionMs MOD &h10000
                  Build      = @ffi.dwProductVersionLS
                
                  FUNCTION = LTRIM$(STR$(Major)) & "." & TRIM$(STR$(Minor)) & "." & LTRIM$(STR$(Build))
                
                END FUNCTION
                NOTE THAT I DONT USE THE "STANDARD" FORMAT of Major.Minor.Build.SubBuild, these functions return Major.Minor.SubBuild. (Please do not ask why I did it like this).
                Last edited by Michael Mattias; 12 Feb 2009, 08:10 AM.
                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  Ok I will bite.....(and await a Gibbs Slap)

                  1.) I am glad to see MCM post useful code unrelated to "Self-Promotion" (which I do not see often)
                  2.)
                  NOTE THAT I DONT USE THE "STANDARD" FORMAT of Major.Minor.Build.SubBuild, these functions return Major.Minor.SubBuild. (Please do not ask why I did it like this).
                  What the HECK?????? do you use???
                  Is it a alpha, beta, gamma thing??? or that you want to release, but unsure if some part may be incorrect, and sure that it is correct (until someone proves otherwise?) or just the idea that version numbers jumping, could make an end user wonder why versions change often????

                  Inquiring minds want to know
                  Engineer's Motto: If it aint broke take it apart and fix it

                  "If at 1st you don't succeed... call it version 1.0"

                  "Half of Programming is coding"....."The other 90% is DEBUGGING"

                  "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                  Comment


                  • #10
                    >Inquiring minds want to know

                    Thy Mind Shall Remain Thus.
                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      Those who do not learn from the past, are DOOMMMMMED to repeat it.

                      Hmmm wonder why???
                      >Inquiring minds want to know

                      Thy Mind Shall Remain Thus.
                      Is it because its soooo secretive that a simple question as to how you can tell 1 version against another? or that your way is superior (at least to you) that each build makes sense many years after touching and have to search your archives???

                      Just so I do not Hijack, I will make my final comment, and say...unless its something "Secret" like you can not share a technique (because of legal obligations or other), then is it not better to share so others learn? options rather than blindly following the sheep???

                      (ok so that was wayyyyy out of scope of the question, but I had to do it before I digress)
                      Engineer's Motto: If it aint broke take it apart and fix it

                      "If at 1st you don't succeed... call it version 1.0"

                      "Half of Programming is coding"....."The other 90% is DEBUGGING"

                      "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                      Comment


                      • #12
                        Originally posted by Michael Mattias View Post
                        Actually, it didn't work well. The source code posted at that link requires several edits in order to compile and run under PB9 (on XP Pro, SP3).

                        I added an edit guide to that thread.

                        NOW it "works good".

                        Thanks for pointing me to this very useful tool!
                        -jhm

                        Doh! I'm going to replace that "guide" with a posting of my working code...

                        Comment


                        • #13
                          >added .posting of my working [with new compiler] code...


                          And you even put the version string in there. Cool!

                          I'll have to replace the copy on my system with that.

                          MCM
                          Michael Mattias
                          Tal Systems (retired)
                          Port Washington WI USA
                          [email protected]
                          http://www.talsystems.com

                          Comment


                          • #14
                            Wait - huh? No, that wasn't me - my edits were minimal.

                            But you reminded me about something else I'm trying to do regularly, so the update has now been updated with this:
                            #Compiler PBWin 9
                            Last edited by John Montenigro; 14 Feb 2009, 05:23 PM.

                            Comment


                            • #15
                              I just noticed in the comments I had added that version string thing in 2004.

                              I wonder why my report does not show it?

                              Either I made a mistake when I did that, or the version of the program which is hooked into my start menu is not the one I posted.

                              FOLLOW UP

                              Oh, I see what I did. I put the version on the screen, but I did not put it on the report.

                              Looks like you could add about two lines of code to the "PrintThelistboxContents" function...
                              Code:
                              W        = "Listing of " & IIf$(idCtrl=%ID_IMPORTS, "imported", "exported") & " functions for file " & sFilename
                                Print       #hFile, W
                              [COLOR="Red"][B]InsertHere: 
                                 CONTROL GET TEXT  hDlg, %ID_VERSION_LITERAL TO W 
                                 PRINT # hFile, USING$ ("File version &", W) 
                              EndInsert:[/B][/COLOR] 
                                W        = "Run Date & Time " & Date$ & Space$(4) & Time$
                                Print       #hFile, W
                                Print       #hFile,
                              
                                Control Send hDlg, idCtrl, %LB_GETCOUNT , 0,0 To nRow    ' how many items in lb?
                              ....
                              MCM
                              Last edited by Michael Mattias; 15 Feb 2009, 09:24 AM.
                              Michael Mattias
                              Tal Systems (retired)
                              Port Washington WI USA
                              [email protected]
                              http://www.talsystems.com

                              Comment


                              • #16
                                I added those lines into the code and it works fine.

                                I also made some changes to the screen layout to accomodate a "copy to clipboard" function. This simplifies getting a string of interest into the search function of the SDK help. It was also a good learning project for me...

                                -jhm

                                To use the copy function, you can either single click on an item and click the button, or double click the item. You'll get both visual and audio feedback when the item is on the clipboard.
                                Last edited by John Montenigro; 16 Feb 2009, 02:08 PM. Reason: tested MCM change putting version into report

                                Comment


                                • #17
                                  The 9x features (CONTROL ADD STATUSBAR, CLIPBOARD DO SOMETHING) came in handy, huh?

                                  For extra credit your mission is to add all those new features for use with all releases of PB/DLL-Windows back to 6x.

                                  (You probably won't buy this, but I find that kind of a fun thing to do with demos.. that and make the program work with EITHER PB/WIN or PB/CC with no change in source code).

                                  (Speaking of which...maybe you want to ZIP up an EXE and attach so those with PB/CC can use it. That program was never written with PB/CC users in mind, at all).
                                  Last edited by Michael Mattias; 16 Feb 2009, 06:51 PM.
                                  Michael Mattias
                                  Tal Systems (retired)
                                  Port Washington WI USA
                                  [email protected]
                                  http://www.talsystems.com

                                  Comment


                                  • #18
                                    No question, there are a number of new PB statements that I can't wait to use in replacing chunks of code I wrote way back when - especially DISPLAY BROWSE, DISPLAY OPENFILE, and DISPLAY SAVEFILE!!! But no way am I going to try retro-fitting! I have too much to learn in the forward direction!

                                    I do understand self-assigned projects for the sake of learning, and I enjoy such (as evidenced with this enum_exp_imp.bas), but my criteria for satisfaction are a bit different -- I am not at the point where I can think both PBWin and PBCC in tandem (maybe someday).

                                    I posted the .EXE in the Source Code message; that was a good suggestion! Good forum citizenship.

                                    What did you think of the changes?

                                    Comment


                                    • #19
                                      >What did you think of the changes?

                                      Enough that I'm not going to bother recompiling: someone posted an EXE I can just download and use!
                                      Michael Mattias
                                      Tal Systems (retired)
                                      Port Washington WI USA
                                      [email protected]
                                      http://www.talsystems.com

                                      Comment


                                      • #20
                                        :d

                                        Comment

                                        Working...
                                        X