Switching between the 32-bit and 64-bit DLL versions of Foxit Quick PDF Library (Visual C#)
The DLL edition of Foxit Quick PDF Library includes support for 32-bit and 64-bit applications. If you’re absolutely sure that you will only want to use the 32-bit version or the 64-bit version then you can just hard code in the version that you want to use.
32-bit DLL
PDFLibrary DPL = new PDFLibrary("DebenuPDFLibraryDLL0916.dll");
64-bit DLL
PDFLibrary DPL = new PDFLibrary("DebenuPDFLibrary64DLL0916.dll");
But if you want to be able to easily switch between using the 32-bit DLL or the 64-bit DLL we’ve got instructions for your here that demonstrate how to do that.
Location of DLL
In order for your code to load the DLL correctly you need to pass the correct path to the library when it is initialized. If the Foxit Quick PDF Library is in the same folder as the executable for the application then it is not necessary to provide a path, just the DLL filename. But if the DLL is located in the Program Files folder for example then you must provide the folder path and file name. It’s often easiest to simply include the DLL in the same folder as the executable because this ensures that no matter which version of Windows your application is installed on, the folder path won’t be an issue.
So, lets get started:
1. Add the DLL import file, in this case the DebenuPDFLibraryDLL0916.cs import file for C#, to your Visual Studio project. It’s usually located at:
C:\Program Files (x86)\Debenu\PDF Library\DLL\Import\CSharp
To add the import file to your project just drag and drop it onto the project name in the Solution Explorer in Visual Studio or right-click on your project name and select “Add > Existing Item…” and browse to the location of the C# import file and add it. Once added it should show up like this:
2. Add the DebenuPDFLibraryDLL0916 namespace to the using directives section at the top of your .cs file. It should look like this:
3. Add the following code to your project.
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using DebenuPDFLibraryDLL0916;
namespace SwitchBetweenDQPLx86andx64
{
public partial class Form1 : Form
{
// DLL Library setup
PDFLibrary DPL;
int DPLVer = 0916;
public Form1()
{
InitializeComponent();
// Different filename for 32-bit and 64-bit DLL
string DLLprefix = "DebenuPDFLibraryDLL";
string DLL64prefix = "DebenuPDFLibrary64DLL";
string dllName;
// Check to see if IntPtr size is 4.
// If 4 then it's 32-bit, if 8 then
// it is 64-bit.
if (IntPtr.Size == 4)
{
dllName = DLLprefix + DPLVer.ToString("D4") + ".DLL"; // 32 bits
}
else
{
dllName = DLL64prefix + DPLVer.ToString("D4") + ".DLL"; // 64 bits
}
// Load the library
DPL = new PDFLibrary(@"C:\Program Files (x86)\Debenu\PDF Library\DLL\" + dllName);
// Check to see if library loaded successfully,
// LibraryVersion can be called before UnlockKey
// function is used
if (DPL.LibraryVersion() == "")
MessageBox.Show("The DPL DLL - " + dllName + " - has not been loaded.");
// Now we can unlock the library and get to work
if (DPL.UnlockKey("...insert_license_key_here...") == 0)
MessageBox.Show("The library could not be unlocked. Check your license key.");
}
private void button1_Click(object sender, EventArgs e)
{
// Create a simple PDF to check that it's working correctly.
// This is not required in your project. It's just a test.
DPL.SetOrigin(1);
DPL.DrawText(100, 100, "Hello World");
DPL.SaveToFile("TestFile.pdf");
}
}
}
4. That’s it, you can now change your projects settings to x86, x64 or AnyCPU and the DLL edition of Foxit Quick PDF Library will automatically handle all modes. Information on how to optimize for a particular CPU type can be found here.
Lastly, if you want to see if your application is running as a 32-bit or 64-bit application then you can use this code:
if(IntPtr.Size == 8)
{
// 64 bit machine
}
else if(IntPtr.Size == 4)
{
// 32 bit machine
}
This article refers to a deprecated product. If you are looking for support for Foxit PDF SDK, please click here.
Updated on May 16, 2022