Add browse to folder location for MapInfo Pro x64

201 views
Skip to first unread message

Kalu

unread,
Feb 16, 2015, 5:44:24 PM2/16/15
to mapi...@googlegroups.com
Hi

I have a MapBasic application which includes a form with a text field and browse button to update that text field with a folder location. This works in MapInfo 32-bit version but causes MapInfo 64-bit to crash when I click on the button.

Can anybody provide me with the code to add a browse to folder location button on a form which will work for 64-bit.

Thanks. Kalu


Here's the code I currently use:

' *********************************************************

Declare Sub MENUBrowserFolder

Define BIF_RETURNONLYFSDIRS 1
Define BIF_DONTGOBELOWDOMAIN 2
Define MAX_PATH 260

Type BrowseInfo
    hWndOwner As Integer
    pIDLRoot As Integer
    pszDisplayName As integer
    lpszTitle As String
    ulFlags As Integer
    lpfnCallBack As Integer
    lParam As Integer
    iImage As Integer
End Type

Declare Function SHBrowseForFolder Lib "shell32" ( lpbi As BrowseInfo) As Integer
Declare Function SHGetPathFromIDList Lib "shell32" Alias "SHGetPathFromIDList" ( byval pidList As Integer, lpBuffer As String) As Integer

Global strOutputFolder as string

' *********************************************************

Sub MENUBrowserFolder

    Dim lpIDList, retVal As Integer
    Dim sBuffer As String
    Dim tBrowseInfo As BrowseInfo

    tBrowseInfo.hWndOwner = SystemInfo(SYS_INFO_MAPINFOWND)
    tBrowseInfo.lpszTitle = "Select Output Folder"
    tBrowseInfo.ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN
    lpIDList = SHBrowseForFolder(tBrowseInfo)

    If (lpIDList) Then

        sBuffer = space$(MAX_PATH)
        retVal = SHGetPathFromIDList(lpIDList, sBuffer)
               
        strOutputFolder = sBuffer

        ' update text field on dialog with folder string
        alter control 11 Value strOutputFolder
   
    End If

End Sub

Kalu

unread,
Feb 16, 2015, 6:51:23 PM2/16/15
to mapi...@googlegroups.com


Actually I worked it out. Using the method provided in the Library.

Declare Method FILEBrowseForFolder
    Class "FILELib.MIController"  Lib "FILELib.dll" Alias "BrowseForFolder"
    (ByVal sDescription As String    'Text to display in the dialog
        , ByVal sFolder As String        'Start folder to use in the dialog
        ) As String                    'Return the folder selected, or "" if the dialog was cancelled

thanks

Peter Horsbøll Møller

unread,
Feb 20, 2015, 5:16:44 AM2/20/15
to mapi...@googlegroups.com
Kalu

This is probably one of the places where you need to replace some of the Integer variables with the new variable type introduced in MapBasic 12.5.1: IntPtr

I have already struggled a bit with this with the WinAPI functions for finding files where I needed to change some of them into IntPtr. The trick is to figure out which needs to get changed and which don't

Declare Function WAPIFindFirstFile Lib "kernel32" Alias "FindFirstFileA"
( ByVal lpFileName As String
, lpFindFileData As WIN32_FIND_DATA
) As IntPtr
Declare Function WAPIFindNextFile Lib "kernel32" Alias "FindNextFileA"
( ByVal hFindFile As IntPtr
, lpFindFileData As WIN32_FIND_DATA
) As Integer
Declare Function WAPIFindClose Lib "kernel32" Alias "FindClose"
( ByVal hFindFile As IntPtr
) As Integer

I got this tip from one of our software engineers after blindly having replaced all Integers with IntPtrs:

However, definitely do NOT change all the Integer types to IntPtr.  If, in the API function definition, the type should be Integer, then leave it as Integer.  However, for Windows API types like long pointers (which generally have a prefix of lp), HANDLE, and some others whose values will (or can) vary depending upon whether it is a 32-bit or a 64-bit architecture, these should be IntPtr.  With the functions below, FindNext and FindClose should still return an Integer.  However, FindFirst is returning a HANDLE, which is then passed to FindNext. This handle needs to be declared as IntPtr in MapBasic.

Consider this a headsup for those of you who are working with the WinAPI and looking to move onto the 64bit version.

Also note that the IntPtr isn't supported in MapBasic versions earlier than 12.5.1

Peter Horsbøll Møller
Pitney Bowes Software



Date: Mon, 16 Feb 2015 14:44:23 -0800
From: plott...@gmail.com
To: mapi...@googlegroups.com
Subject: [MI-L] Add browse to folder location for MapInfo Pro x64
--
--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en

---
You received this message because you are subscribed to the Google Groups "MapInfo-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapinfo-l+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages