BookmarkSubscribeRSS Feed
stuerzl
Calcite | Level 5

Using Libref SASCBTBL Windows DLLs can be used within SAS. This works very performantly since Windows 95. But some routines from kernel32.dll do no longer work under Windows 7 x64 whereas kernel32.dll still exist. e.g. FindFirstFileA, FindNextFileA, FindClose. => ERROR:  Write Access Violation DATASTEP.

Any idea how these routines can be reactivated unter Win 7 64 bit?

Below you find an Win x32 working example, which gets the first two entries for C:\*.*

Any suggestions are wellcome.

Heinrich

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

FILENAME SASCBTBL "C:\Temp\DLLAttributeTable.txt";

* Create Attribute Table with the description of the routines; 
DATA _NULL_;
FILE SASCBTBL;
INPUT;
PUT _INFILE_;
CARDS4;
* SASCBTBL Attribute Table for Description of external DLLs used by SAS;
* DLL used: KERNEL32.DLL;
* Routines: FindFirstFileA, FindNextFileA, FindClose;

*************************************************
HANDLE FindFirstFile(
LPCTSTR lpFileName, // file name
LPWIN32_FIND_DATA lpFindFileData // data buffer
);

ROUTINE FindFirstFileA
minarg=11
maxarg=11
stackpop=called
module=Kernel32
returns=long;

  arg 1 char input format=$CSTR260.; * LPCTSTR lpFileName, // address of name of file to search for ;
* LPWIN32_FIND_DATA lpFindFileData // address of returned information ;
arg 2 num output fdstart format=pib4.; * DWORD dwFileAttributes ;
arg 3 num output format=pib8.; * FILETIME ftCreationTime ;
arg 4 num output format=pib8.; * FILETIME ftLastAccessTime ;
arg 5 num output format=pib8.; * FILETIME ftLastWriteTime ;
arg 6 num output format=pib4.; * DWORD nFileSizeHigh ;
arg 7 num output format=pib4.; * DWORD nFileSizeLow ;
arg 8 num output format=pib4.; * DWORD dwReserved0 ;
arg 9 num output format=pib4.; * DWORD dwReserved1 ;
arg 10 char output format=$CSTR260.; * TCHAR cFileName[ MAX_PATH ] ;
arg 11 char output format=$CSTR14.; * TCHAR cAlternateFileName[ 14 ] ;

*************************************************
BOOL FindNextFile(
HANDLE hFindFile, // search handle
LPWIN32_FIND_DATA lpFindFileData // data buffer
);

ROUTINE FindNextFileA
minarg=11
maxarg=11
stackpop=called
module=Kernel32
returns=long;

  arg 1 num input byvalue format=pib4.; * HANDLE hFindFile, // handle of search ;
* LPWIN32_FIND_DATA lpFindFileData // address of structure for data on found file;
arg 2 num output fdstart format=pib4.; * DWORD dwFileAttributes ;
arg 3 num output format=pib8.; * FILETIME ftCreationTime ;
arg 4 num output format=pib8.; * FILETIME ftLastAccessTime ;
arg 5 num output format=pib8.; * FILETIME ftLastWriteTime ;
arg 6 num output format=pib4.; * DWORD nFileSizeHigh ;
arg 7 num output format=pib4.; * DWORD nFileSizeLow ;
arg 8 num output format=pib4.; * DWORD dwReserved0 ;
arg 9 num output format=pib4.; * DWORD dwReserved1 ;
arg 10 char output format=$CSTR260.; * TCHAR cFileName[ MAX_PATH ] ;
arg 11 char output format=$CSTR14.; * TCHAR cAlternateFileName[ 14 ] ;

*************************************************
BOOL FindClose(
HANDLE hFindFile // file search handle
);

ROUTINE FindClose
minarg=1
maxarg=1
stackpop=called
module=Kernel32
returns=long;

  arg 1 num input byvalue format=pib4.; * HANDLE hFindFile // file search handle ;

;;;;
RUN;

***************** Usage in Data Step;
data dirlist;
length Path $256 Name $256 DosName $14 Attributes 8;

  path="C:\*.*";

  handle=modulen ("FindFirstFileA", path,
Attributes, created, accessed, written, sizeH, sizeL,
reserve0, reserve1, Name, DosName);
put _all_;
handle=modulen ("FindNextFileA", handle,
Attributes, created, accessed, written, sizeH, sizeL,
reserve0, reserve1, Name, DosName);
put _all_;
handle=modulen ("FindClose", handle);
put _all_;
run;

1 REPLY 1
stuerzl
Calcite | Level 5

Working solution of the SAS hotline:

For Windows 7 x64 (SAS 9.3) use format pibunaln8. instead of pib8. and pib8. instead of pib4. in arg1 of FindNextFile and FindClose in the SASCBTBL definition table.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 778 views
  • 0 likes
  • 1 in conversation