Hello all,
I have successfully used code suggested by this list to scan a folder and return a string array of *.tab files.
However, I have just now attempted to use the same code in a script compiled in MapBasic v15.2 (64 bit) for me to run in 64-bit MapInfo. And the script fails. It does not generate an error, just returns a bad result (blanks). My MapInfo is running on 64-bit Windows 7
Considering that the code does include references to 32 bit for example, “WIN32_FIND_DATA” and “kernel32” Should the script be upgraded to 64 bit?
Cheers,
Nick Lawrence
The InPtr is one change that will affect this. Another is the just introduced Align keyword.
Especially working with strings in a struct that is being passed to and from a DLL can be tricky.
I ended up implementing my own FindFiles functions using .NET instead of using the WinAPI.
Mostly because this would like me run my applications in older versions of MapInfo Pro than just 15.2.
These are the methods that I created:
Declare Method FILEFindFilesInFolder '**Searches thru this specific folder only, no subfolders
Class "FILELib.MIController" Lib "FILELib.dll" Alias "FindFilesInFolder"
( ByVal sPath As String 'Path to search
, ByVal sMask As String 'Mask to use, eg. "*.*", "*.tab" etc
) As Integer
Declare Method FILEFindFilesInFolders '**Searches thru this specific folder and all subfolders
Class "FILELib.MIController" Lib "FILELib.dll" Alias "FindFilesInFolders"
( ByVal sPath As String 'Path to search
, ByVal sMask As String 'Mask to use, eg. "*.*", "*.tab" etc
) As Integer
Declare Method FILEGetFindFilesFileName
Class "FILELib.MIController" Lib "FILELib.dll" Alias "GetFindFilesFileName"
( ByVal nFileItem As Integer 'File number to get the name full path of
) As String 'Returns full path for the file number, 1 is the first file in the list
Declare Method FILEGetFindFilesFileNames
Class "FILELib.MIController" Lib "FILELib.dll" Alias "GetFindFilesFileNames"
( arrFileNames() As String 'Array to hold all the filenames selected
) As Integer
The first two file search thru either the folder or the folder and all subfolder.
The last two are used to getting the file names from the search result.
The methods are implemented in the FileLib.dll that can be found on github:
https://github.com/PeterHorsbollMoller/mbLibrary
It’s part of my mbLibrary but you can also just use these four declares and the dll alone.
Peter Horsbøll Møller
Pitney Bowes
--
--
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.
Declare Sub GetFileNames (byval sPath As String, byval sFilespec As String, sList() As String)
Define MAX_PATH 260
Type FILETIME
dwLowDateTime As Integer
dwHighDateTime As Integer
End Type
Type WIN32_FIND_DATA
dwFileAttributes As Integer
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Integer
nFileSizeLow As Integer
dwReserved0 As Integer
dwReserved1 As Integer
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Define INVALID_HANDLE_VALUE -1
Declare Function FindFirstFile Lib "kernel32"
Alias "FindFirstFileA" (ByVal lpFileName As String, lpfindFileData As WIN32_FIND_DATA) As Integer
Declare Function FindNextFile Lib "kernel32"
Alias "FindNextFileA" (ByVal hFindFile As Integer, lpFindFileData As WIN32_FIND_DATA) As Integer
Declare Function FindClose Lib "kernel32"
Alias "FindClose" (ByVal hFindFile As Integer) As Integer
Sub GetFileNames (ByVal sPath As String, ByVal sFilespec As String, sList() As String)
Dim hFindFile, nStatus As Integer
Dim f As WIN32_FIND_DATA
Dim i As Integer
hFindFile = FindFirstFile (sPath + sFilespec, f)
If hFindFile <> INVALID_HANDLE_VALUE Then
Do
If (f.dwFileAttributes \ 16) Mod 2 = 0 Then
i = i + 1
ReDim sList(i)
sList(i) = f.cFilename
End If
nStatus = FindNextFile (hFindFile, f)
Loop While nStatus = 1
End If
nStatus = FindClose (hFindFile)
End Sub
And the command is;
Dim sTables() As String
Dim sDir As String
Call GetFileNames(sDir, "*.tab", sTables)
Cheers,
Nick Lawrence
From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com]
On Behalf Of Uffe Kousgaard
Sent: Monday, 29 August 2016 4:21 PM
To: mapi...@googlegroups.com
Subject: Re: [MI-L] 64-bit version of Scan / Search directory and sub directories using Mapbasic and Windows API
Yes. A key thing may be using IntPtr rather than Integer for pointers returned from the winapi.
--
Hi Peter,
I understand the flexibility of your FileLib.dll, but for me, I want a solution that is portable in that the functionality is completely within the mapbasic code.
Cheers,
Nick Lawrence
From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On Behalf Of Uffe Kousgaard
Sent: 29. august 2016 08:21
To: mapi...@googlegroups.com
Subject: Re: [MI-L] 64-bit version of Scan / Search directory and sub directories using Mapbasic and Windows API
Yes. A key thing may be using IntPtr rather than Integer for pointers returned from the winapi.
--
Hi Nick
You need to modify your structs and declares to something along these lines:
'64-bit number specifying the elapsed time since January 1, 1601, in 100-nanosecond increments
Type FILETIME
dwLowDateTime As Integer
dwHighDateTime As Integer
End Type
Type WIN32_FIND_DATA Align4 'Used on 64 bit systems, Align[n] is a new keyword with MapBasic 15.2.2
dwFileAttributes As Integer
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Integer
nFileSizeLow As Integer
dwReserved0 As Integer
dwReserved1 As Integer
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Declare Function WAPIFindFirstFile Lib "kernel32.dll" Alias "FindFirstFileA"
( ByVal lpFileName As String
, lpFindFileData As WIN32_FIND_DATA
) As IntPtr
'http://msdn.microsoft.com/en-us/library/windows/desktop/aa364418(v=vs.85).aspx
Declare Function WAPIFindNextFile Lib "kernel32.dll" Alias "FindNextFileA"
( ByVal hFindFile As IntPtr
, lpFindFileData As WIN32_FIND_DATA
) As Integer
'http://msdn.microsoft.com/en-us/library/windows/desktop/aa364428(v=vs.85).aspx
Declare Function WAPIFindClose Lib "kernel32.dll" Alias "FindClose"
( ByVal hFindFile As IntPtr
) As Integer
'http://msdn.microsoft.com/en-us/library/windows/desktop/aa364413(v=vs.85).aspx
Notice the IntPtr variable types and the Align4 keyword
I have attached my latest WINAPI.def that should work with MapInfo Pro 15.2.
I say should because I haven’t put it thru a complete test.
Peter Horsbøll Møller
Pitney Bowes
Hi Peter,
Ta for that
I shall now install the mapbasic v15.2.2 patch J
Cheers,
Nick Lawrence
From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On Behalf Of Peter Horsbøll Møller
Sent: Tuesday, 30 August 2016 4:06 PM
To: mapi...@googlegroups.com
Subject: RE: [MI-L] 64-bit version of Scan / Search directory and sub directories using Mapbasic and Windows API
Hi Nick
You need to modify your structs and declares to something along these lines:
'64-bit number specifying the elapsed time since January 1, 1601, in 100-nanosecond increments
Type FILETIME
dwLowDateTime As Integer
dwHighDateTime As Integer
End Type
Type WIN32_FIND_DATA Align4 'Used on 64 bit systems, Align[n] is a new keyword with MapBasic 15.2.2
dwFileAttributes As Integer
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Integer
nFileSizeLow As Integer
dwReserved0 As Integer
dwReserved1 As Integer
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Declare Function WAPIFindFirstFile Lib "kernel32.dll" Alias "FindFirstFileA"
( ByVal lpFileName As String
, lpFindFileData As WIN32_FIND_DATA
) As IntPtr
'http://msdn.microsoft.com/en-us/library/windows/desktop/aa364418(v=vs.85).aspx
Declare Function WAPIFindNextFile Lib "kernel32.dll" Alias "FindNextFileA"
( ByVal hFindFile As IntPtr
, lpFindFileData As WIN32_FIND_DATA
) As Integer
'http://msdn.microsoft.com/en-us/library/windows/desktop/aa364428(v=vs.85).aspx
Declare Function WAPIFindClose Lib "kernel32.dll" Alias "FindClose"
( ByVal hFindFile As IntPtr
) As Integer
'http://msdn.microsoft.com/en-us/library/windows/desktop/aa364413(v=vs.85).aspx
Notice the IntPtr variable types and the Align4 keyword
I have attached my latest WINAPI.def that should work with MapInfo Pro 15.2.
I say should because I haven’t put it thru a complete test.
Peter Horsbøll Møller
Pitney Bowes
From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On Behalf Of Nicholas G Lawrence
Sent: 30. august 2016 00:57
To: mapi...@googlegroups.com
Did you read thru the entire thread: https://groups.google.com/forum/#!topic/mapinfo-l/hjUb8_k6830
There are some suggestions for overcoming this.
Nick, were you able to make it work in 64 bit/MapBasic 15.2.2?
Peter Horsbøll Møller
Pitney Bowes
--
--
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
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.