RE: Example DLL translation from VBA into Xbasic
Peter,
I'll take a look at your code. Maybe it answers some question I have and can help you.
In the meantime I post here some stuff where I don't know why I can't get WIN32_FIND_DATA structure filled. I'm translating this from the Win32 Programmer's Reference. It was code I'd examined several months ago to overcome some problems with the File Attributes command. Here are some problems such as translating the array[] construction in a c-type declaration. Xbasic doesn't do this job. Another point is how can I pass the WIN32_FIND_DATA by reference so the function can fill the structure.
It is also possible that I'm trying something to do that can't be done in Xbasic simple because the structure translating lacks. However here some premature code.
Peter,
I'll take a look at your code. Maybe it answers some question I have and can help you.
In the meantime I post here some stuff where I don't know why I can't get WIN32_FIND_DATA structure filled. I'm translating this from the Win32 Programmer's Reference. It was code I'd examined several months ago to overcome some problems with the File Attributes command. Here are some problems such as translating the array[] construction in a c-type declaration. Xbasic doesn't do this job. Another point is how can I pass the WIN32_FIND_DATA by reference so the function can fill the structure.
It is also possible that I'm trying something to do that can't be done in Xbasic simple because the structure translating lacks. However here some premature code.
Code:
'Purpose 'Trying to get the structure WIN32_FIND_DATA filled by dll function FindFirstFileA(). 'Possible problems will arise with the array based structure members. 'Question: '- How is a - TCHAR cAlternateFileName[14] - structure part handled by Xbasic. ' in C this is a array of 14 characters closed with a \0 constant MAX_PATH = 260 '#define INVALID_HANDLE_VALUE (HANDLE)(0xffffffff) 'This is C constant INVALID_HANDLE_VALUE = hex_to_dec("ffffffff") 'C-code 'The FILETIME structure is a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC). 'typedef struct _FILETIME { ' DWORD dwLowDateTime; ' DWORD dwHighDateTime; '} FILETIME, *PFILETIME; 'Xbasic version type FILETIME dwLowDateTime as Integer dwHighDateTime as Integer end type 'C-code 'The WIN32_FIND_DATA structure describes a file found by the FindFirstFile, FindFirstFileEx, or FindNextFile function. 'typedef struct _WIN32_FIND_DATA { ' DWORD dwFileAttributes; ' FILETIME ftCreationTime; ' FILETIME ftLastAccessTime; ' FILETIME ftLastWriteTime; ' DWORD nFileSizeHigh; ' DWORD nFileSizeLow; ' DWORD dwReserved0;' ' DWORD dwReserved1; ' TCHAR cFileName[MAX_PATH]; ' TCHAR cAlternateFileName[14]; '} WIN32_FIND_DATA, *PWIN32_FIND_DATA; 'Xbasic version 'Note Using Arrays are not allowed in a structure.. Is this sitting Duck or not? type WIN32_FIND_DATA dwFileAttributes as Integer ftCreationTime as {FILETIME} ftLastAccessTime as {FILETIME} ftLastWriteTime as {FILETIME} 'This is allowed nFileSizeHigh as Integer nFileSizeLow as Integer dwReserved0 as Integer dwReserved1 as Integer cFileName as C cAlternateFileName as C ' cAlternateFileName[14] as Byte 'This doesn't work. end type 'Declare the external functions in KERNEL32.DLL 'The FindFirstFile function searches a directory for a file whose name matches the specified file name. 'FindFirstFile examines subdirectory names as well as file names. The FindFirstFile function opens a search 'handle and returns information about the first file whose name matches the specified pattern. It searches 'both the long and short file names. After the search handle has been established, use the FindNextFile 'function to search for other files that match the same pattern. When the search handle is no longer needed, 'close it by using the FindClose function declare KERNEL32 FindFirstFileA LC(WIN32_FIND_DATA) 'The FindClose function closes the specified search handle. The FindFirstFile, FindFirstFileEx, and FindNextFile 'functions use the search handle to locate files with names that match a given name. declare KERNEL32 FindClose LL dim hFind as N 'Search handle dim filepointer as P 'Create a pointer for passing the filename to the function. 'Give the WIN32_FIND_DATA structure a memory mask. dim findfiledata as {win32_find_data} dim filepointer.filename as C dim findfiledata.wFileAttributes as N dim findfiledata.ftCreationTime as {FILETIME} dim findfiledata.ftLastAccessTime as {FILETIME} dim findfiledata.ftLastWriteTime as {FILETIME} dim findfiledata.nFileSizeHigh as N dim findfiledata.nFileSizeLow as N dim findfiledata.dwReserved0 as N dim findfiledata.dwReserved1 as N dim findfiledata.cAlternateFileName as C 'Initialize. filepointer.filename = "" findfiledata.wFileAttributes = 0 findfiledata.ftCreationTime.dwLowDateTime = 0 findfiledata.ftCreationTime.dwHighDateTime = 0 findfiledata.ftLastAccessTime.dwLowDateTime = 0 findfiledata.ftLastAccessTime.dwHighDateTime = 0 findfiledata.ftLastWriteTime.dwLowDateTime = 0 findfiledata.ftLastWriteTime.dwHighDateTime = 0 findfiledata.nFileSizeHigh = 0 findfiledata.nFileSizeLow = 0 findfiledata.dwReserved0 = 0 findfiledata.dwReserved1 = 0 findfiledata.cAlternateFileName = "" 'debug(1) filepointer.filename = "C:\\*.*" 'Whatever there is find the first. hFind = FindFirstFileA(filepointer,findfiledata) ' if hFind = INVALID_HANDLE_VALUE then ui_msg_box("Error", "INVALID_HANDLE_VALUE") else ui_msg_box("Succeed", "HANDLE_VALUE_OK") ui_msg_box("hFind", convert_type(hFind, "C")) ui_msg_box("Filename", convert_type(findfiledata.cFileName, "C")) ui_msg_box("INVALID_HANDLE_VALUE", convert_type(INVALID_HANDLE_VALUE, "C")) ui_msg_box("wFileAttributes", convert_type(findfiledata.wFileAttributes, "C")) ui_msg_box("dwLowDateTime", convert_type(findfiledata.ftCreationTime.dwLowDateTime, "C")) FindClose(hFind) end if undeclare FindFirstFile undeclare FindClose End
Comment