Microsoft Cardfile Import DLL

What is cardfile?
If you ask this question, youe propably don’t need this dll. Anyway – the
screenshot is showing Cardfile in action (with the contents of my CD-archive.)

CardFile.exe came with windows 3.1 and 3.11 (maybe before)
but was not included with Windows 95 and later. That is a shame because I think lot’s of
people was using this small, but inferior, piece of software.

What is the CardFile Import DLL?
I have written a small DLL (28 Kb) that will take care of importing the Cardfile binary
format into something that can be understood by C++ and maybe other programming languages.
I will not take any responsibility
for the outcome of using this DLL. The Cardfile file format is not documented, and the
only thing I know is that it works fine on my machine. I cannot guarantee that this
will be the case on any system in the world.

Usage
The DLL only contains two functions:

ImportCardFile and FreeCardFilePtr.

These funtions are loaded dynamically. This approach makes
using the functions a bit cumbersome, but on the other hand it means that the dll should
also be usable to any programming language supporting dll function calls. You are however
free to remove the header and implementation files from dll and link them statically to
your own project, if you do not like DLLs.

The code snippet below is taken from the sample
accompanying the cardfile dll.

BOOL CCrdFileDriverDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
// It is not necessary to call the base clas implementation of OnOpenDocument()
//	if (!CDocument::OnOpenDocument(lpszPathName))
//		return FALSE;

	HINSTANCE        hInst;
	LPCSTR		     lpszDllPath = "CardFile.dll";
	IMPORTCARDFILE	 ImportCardFile;
	FREECARDFILEPTR	 FreeCardFilePtr;
	LPCARDFILECARD	 cfc;
	DWORD		     dwNumCards, dwResult;
	LPCSTR			 lpszDivider = "========================================";
	CString			 strFormat;

	// Load the carfile dll, and obtain a pointer to the import function
	hInst = LoadLibrary(lpszDllPath);
	if (!hInst)
	{
		AfxMessageBox("Cannot load the cardfile DLL");
		return FALSE;
	}

	ImportCardFile = (IMPORTCARDFILE)GetProcAddress(hInst, "ImportCardFile");
	if (!ImportCardFile)
	{
		AfxMessageBox("Cannot find the \"ImportCardFile\" process");
		return FALSE;
	}

	// Empty the string that will be shown in the edit control of the child window
	m_strText.Empty();

	// call the function that imports the cardfile. Each car will be loaded into a separate structure
	dwResult = ImportCardFile(lpszPathName, &cfc, &dwNumCards);

	// The cards was imported successfully
	if (dwResult == CF_SUCCESS)
	{
		// For each of the cards create string and add it to the main string m_strText
		// The main string will eventually be shown in the edit window
		for (DWORD i=0 ; i < dwNumCards; i++)
		{
			strFormat.Format("%s\r\n%s\r\n%s\r\n",
				lpszDivider, cfc[i].szHeading, cfc[i].szBodyText);
			m_strText += strFormat;
		}
	}
	else
	{
		// Error - show a message
		switch (dwResult)
		{
		case CF_FILETOSMALL:
			AfxMessageBox("The file was to small.");
			break;
		case CF_NOTACARDFILE:
			AfxMessageBox("This is not a valid cardfile database.");
			break;
		default:
			AfxMessageBox("Cardfile import failed.");
		}

		return FALSE;
	}

	// Load the process that will perform clean up of the imported cards
	FreeCardFilePtr = (FREECARDFILEPTR)GetProcAddress(hInst, "FreeCardFilePtr");
	if (!FreeCardFilePtr)
	{
		AfxMessageBox("Cannot find the \"FreeCardFilePtr\" process");
		return FALSE;
	}

	FreeCardFilePtr(&cfc, dwNumCards);
	FreeLibrary(hInst);

	// Make sure that the contents of the string with the cardfiles are shown
	UpdateAllViews(NULL);

	return TRUE;
}

The Sample Program
I have provided a small sample program that will demonstrate how the dll is used, and what
can be accomplished with it.
You can use the sample program to extract the information from your old Cardfile archives
and copy and paste the information from cardfile into a database system of your choice.
If you decide to create a program using my code – CardFile98 maybe 😉 I would appreciate
if you would mail a copy.

A sreenshot from the sample program is shown below

Download demo project – 37 KB

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read