I would have never imagined that finding a cookie would be so much work as it turned out to be. I originally started out using my quick and dirty little DLL called IsFile (available on my [website]), which contains just one function which returns a zero if it find your file and a 1 if it does not find your file.
Well cookies have a certain amount of complexity built in. First the cookie name is not simply the name of the cookie that you expect you have written. The filename also includes the user name and a revision number as well. Second, and probably worst is that cookies are not always in the same place from system to system and from OS to OS. These problems rendered the use of my simple DLL obsolete. They also made the use of the native Liberty Basic FILES command very unattractive. I suppose I could have used a recursively called routine to located the cookies by searching through all file and folders, but I needed instant answers, that would be too slow!
So a new, specific, DLL was born. In fact, due to an untimely hard disk crash it was born twice! The day after I finished writing the DLL the first time, I lost the it in a complete failure of my system. They say all tragedies have a silver lining, and I found mine. The original DLL worked great on my 98 machine, but I realized when recreating the DLL that to original was seriously flawed on any NT based machine. It was not able to locate the directory in which the cookies were being stored. To do this on the NT equipment, one must get the user profile and read the registry to learn where the cookies are being stored. This DLL does this with finesse.
So, here it is - a specific DLL for locating a cookie file on any 32 bit based windows PC using a file name fragment as search criteria. The DLL returns not only all qualifying cookies, but also the directory where the cookies are stored for this user and OS.
using the COOKIEUTIL DLL:
A DLL for locating all cookies that conform to the search string passed to it. The DLL has one exported function FindCookies for accomplishing the task.
The interface between the DLL and the calling application is through a user defined datatype. In Liberty Basic language it is a STRUCT. The format of the User Defined Datatype is detailed below.
The DLL is optimized for all 32bit versions of windows. It will not run on Windows 3.1 or less. Because of the variations in user configuration which both the system and the user can make, there is no certain location where cookies will be stored. However every user configuration has the location coded in the registry. This DLL reads a registry setting to determine where to find cookies.
The search string is passed in the search buffer and remains unaltered by the DLL. The search buffer is just a simple string. Wild card characters are assumed, do not pass wild card characters.
Results of the search are returned in a 2048 character result buffer. To facilitate the usefulness of the returned data the result buffer will be loaded with the location where cookies are stored for this user and OS as its first parameter. The cookie path is counted as the first hit as well. The actual number of cookies located will be equal to the number of hits minus one. This count (hits) is also passed back by DLL in the User Defined Datatype interface.
The result buffer will be loaded with all cookie names that match the search criteria, (as well as the cookie path) each separated by "|" (pipe) delimiter. The buffer needs to be initialized with 2048 spaces or something when calling the DLL from Liberty Basic. Use the command:
lBuffer$ = space$(2048)
This will initialize a buffer string called lBuffer$ with 2048 space characters.
The DLL will also return a positive one (1) for a successful call and a zero (0) for an unsuccessful call (errors were encountered). This result value is passed back as a long.
The DLL was written with Liberty Basic in mind, however it should work for most languages. For those interested in Liberty Basic - please check them out on the web at the [Liberty Basic Homepage].
Calling the DLL
This DLL has one function:
FindCookie (values as cookieSearch) Result as Long
values : A user defined data type of type cookieSearch. It is defined as: cookieSearch = searchString as string * 128, resultString as string * 2048 hits as long Result : A long integer value that specifies success or error conditions. 1 = success 0 = failure
The DLL ships with an example basic program called testCoookie.bas. It will allow you to test the DLL using Liberty Basic version 3.x. The key elements to using the DLL are to first set up the STRUCT for the DLL communications buffer and open the DLL. Use the following code:
struct cookieSearch, _ searchString$ As char, _ resultString$ As char, _ hits As long Open "cookieutil.dll" For DLL As #cookie
Next initialize the buffer by loading it with spaces, and set your search criteria. Then simply call the DLL. Use the following code:
cookieSearch.searchString$.struct = "amazon" cookieSearch.resultString$.struct = Space$(2048) CallDLL #cookie, "FindCookie",cookieSearch As ptr, result As long
The results will be returned in the follow variables in the communications buffer. Total number of cookies located (that would fit into the 2048 character return buffer) and also the actual return buffer. If hits is zero then no cookies qualified. It will never return a one. If cookies did qualify based on the search criteria then the first item passed back is the path to where the cookies are on this system, followed by all the cookie file names - each separated by a pipe "|" character. Here is an example of simply dumping the output to the mainwin.
print cookieSearch.resultString$.struct print cookieSearch.hits.struct
This DLL is demonstrated in the more elaborate program called LBNoteBoard. An article on this program appears elsewhere in this publication or on this website. The DLL described in this article, the sample program and some basic documentation are all included in a zip archive that accompanies this newsletter.
This was written by Brad Moore - email@example.com