1. Rosalind Powell
  2. PowerBuilder
  3. Thursday, 15 March 2018 20:06 PM UTC

This function is found in the pfcapsrv.pbl.pfc_n_cst_filesrvwin32

​My code:

date dt_test
time tm_test

pfc_n_cst_filesrvwin32 lnv_file

if NOT IsValid(lnv_file) then
   lnv_file = CREATE pfc_n_cst_filesrvwin32
end if

li_rc =  lnv_file.of_GetLastWriteDateTime( 'C:\Users\Public\PBApps\Material_Dropdown.txt',dt_test, tm_test)

 

I see it in debug, but this functions calls the external local function:

ll_handle = FindFirstFileA(as_FileName, lstr_FindData) and the handle is returned as -1 (bad)

What am I doing wrong?

Arthur Hefti Accepted Answer Pending Moderation
  1. Friday, 16 March 2018 04:49 AM UTC
  2. PowerBuilder
  3. # 1

Hi

As the other answers stated this is a Ansi / Unicode problem.

You do a wrong creation of lnv_file. The file service and platform service provide a function  to create the object using the environment object. This returns the n_cst_filesrvunicode for PB 10+. In addition it checks if the object exists and won't create it in this case. 

pfc_n_cst_filesrv     lnv_file

lnv_file = f_SetFileSrv( lnv_File, TRUE)
 

Regards
Arthur

Comment
  1. Rosalind Powell
  2. Friday, 16 March 2018 13:22 PM UTC
Thanks all. Arthur's comment got me on my way. I didn't want to add a new local External Function so I didn't try it.



This is the code that worked:



pfc_n_cst_filesrvunicode lnv_file



if NOT IsValid(lnv_file) then

   li_rc = f_SetFileSrv( lnv_File, TRUE)

end if



li_rc =  lnv_file.of_GetLastWriteDateTime( 'C:\Users\Public\PBApps\Material_Dropdown.txt',dt_test, tm_test)

  1. Helpful
There are no comments made yet.
Miguel Leeuwee Accepted Answer Pending Moderation
  1. Thursday, 15 March 2018 23:49 PM UTC
  2. PowerBuilder
  3. # 2

I think you are using a very old version of PFC's? Try using FindFirstFileW() instead of ...A().

Here are the external function declarations I see in our version of pfc;s: pfc_n_cst_fileserv_unicode:

// Win 32 calls
Function ulong GetDriveTypeW (string drive) library "KERNEL32.DLL"
Function boolean CreateDirectoryW (ref string directoryname, ref os_securityattributes secattr) library "KERNEL32.DLL"
Function boolean RemoveDirectoryW (ref string directoryname) library "KERNEL32.DLL"
Function ulong GetCurrentDirectoryW (ulong textlen, ref string dirtext) library "KERNEL32.DLL"
Function boolean SetCurrentDirectoryW (ref string directoryname ) library "KERNEL32.DLL"
Function ulong GetFileAttributesW (ref string filename) library "KERNEL32.DLL"
Function boolean SetFileAttributesW (ref string filename, ulong attrib) library "KERNEL32.DLL"
Function boolean MoveFileW (ref string oldfile, ref string newfile) library "KERNEL32.DLL"
Function long FindFirstFileW (ref string filename, ref os_finddata findfiledata) library "KERNEL32.DLL"
Function boolean FindNextFileW (long handle, ref os_finddata findfiledata) library "KERNEL32.DLL"
Function boolean FindClose (long handle) library "KERNEL32.DLL"
Function boolean GetDiskFreeSpaceW (string drive, ref long sectpercluster, ref long bytespersect, ref long freeclusters, ref long totalclusters) library "KERNEL32.DLL"
Function long GetLastError() library "KERNEL32.DLL"
 
// Win32 calls for file date and time
Function long OpenFile (ref string filename, ref os_fileopeninfo of_struct, ulong action) LIBRARY "KERNEL32.DLL"
Function boolean CloseHandle (long file_hand) LIBRARY "KERNEL32.DLL"
Function boolean GetFileTime(long hFile, ref os_filedatetime  lpCreationTime, ref os_filedatetime  lpLastAccessTime, ref os_filedatetime  lpLastWriteTime  )  library "KERNEL32.DLL"
Function boolean FileTimeToSystemTime(ref os_filedatetime lpFileTime, ref os_systemtime lpSystemTime) library "KERNEL32.DLL"
Function boolean FileTimeToLocalFileTime(ref os_filedatetime lpFileTime, ref os_filedatetime lpLocalFileTime) library "KERNEL32.DLL"
Function boolean SetFileTime(long hFile, os_filedatetime  lpCreationTime, os_filedatetime  lpLastAccessTime, os_filedatetime  lpLastWriteTime  )  library "KERNEL32.DLL"
Function boolean SystemTimeToFileTime(os_systemtime lpSystemTime, ref os_filedatetime lpFileTime) library "KERNEL32.DLL"
Function boolean LocalFileTimeToFileTime(ref os_filedatetime lpLocalFileTime, ref os_filedatetime lpFileTime) library "KERNEL32.DLL"
 
Public:
 
Function boolean MoveFile(REF String lpExistingFileName, REF String lpNewFileName) LIBRARY "KERNEL32.DLL" ALIAS FOR "MoveFileW"
 
Private:
 
FUNCTION unsignedLong GetLongPathName(REF String lpszShortPath, REF String lpszLongPath, Long cchBuffer) LIBRARY 'kernel32.dll' ALIAS FOR 'GetLongPathNameW'
FUNCTION unsignedLong GetShortPathName(REF String lpszLongPath, REF String lpszShortPath, Long cchBuffer) LIBRARY 'kernel32.dll' ALIAS FOR 'GetShortPathNameW'
Function unsignedInteger GetSystemDirectory(REF String lpBuffer, unsignedInteger uSize) LIBRARY "KERNEL32.DLL" ALIAS FOR "GetSystemDirectoryW"
Function unsignedInteger GetTempFileName(REF String lpPathName, REF String lpPrefixString, unsignedInteger uUnique, REF String lpTempFileName) LIBRARY "KERNEL32.DLL" ALIAS FOR "GetTempFileNameW"
Function unsignedLong GetTempPath(unsignedLong nBufferLength, REF String lpBuffer) LIBRARY "KERNEL32.DLL" ALIAS FOR "GetTempPathW"
Function unsignedInteger GetWindowsDirectory(REF String lpBuffer, unsignedInteger uSize) LIBRARY "kernel32.dll" ALIAS FOR "GetWindowsDirectoryW"
Comment
There are no comments made yet.
Miguel Leeuwee Accepted Answer Pending Moderation
  1. Thursday, 15 March 2018 23:43 PM UTC
  2. PowerBuilder
  3. # 3

How is the FindFirstFile declared? Maybe you have to add ";Ansi" at the end of the declaration or use a 64 bit declaration of the function.

Which version of the pfc's are you using?

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.