The Unlock method can be used in multi-threading situations to avoid conflicts between multiple applications or multiple threads requesting simultaneous access to the Converter products. The CDIntf library uses the registry to interact with the printer drivers. This can cause conflicts when multiple applications use CDIntf to access the printer drivers.
System.Int32 Unlock(System.String szLockName, System.Int32 dwTimeout)
int Unlock(HANDLE hPrinter, LPCSTR szDocTitle, long dwTimeout)
szLockName, szDocTitle
Lock identifier, this should be the document title as it appears in the print spooler when printing any document.
dwTimeout
Timeout in milliseconds after which the function returns.
hPrinter
Handle to printer returned by any of the DriverInit function calls.
The return value is 0 if the function is successful or a Windows specific error code if the function fails.
The Unlock method is used after printing has ended to make sure another printout can start. The call to Unlock is needed only in the case where an error occurs; the printer will otherwise call Unlock internally as soon as printing starts to allow another printout to occur in parallel.
Member of CDIntfEx.CDIntfEx.
<Flags()>
Public Enum acFileNameOptions As Integer
'Please check FileNameOptions for the complete flags version
NoPrompt = &H1
UseFileName = &H2
EmbedFonts = &H10
BroadcastMessages = &H20
End Enum
Public Sub Sample()
'Constants for Activation codes
Const strLicenseTo As String = "DOCX Converter Developer Evaluation"
Const strActivationCode As String = "07EFCDAB010001002EE718DAABD90353AA8141F60B6762C695F4D5BA97F516CBE3EB407DC717EC1D28DE39A61F1ACE26924C99AFB190"
Const AMYUNIPRINTERNAME As String = "DOCX Converter Developer Evaluation"
' Declare a new cdintfex object if it does not exist in the form.
Dim PDF As New CDIntfEx.CDIntfEx
'Get a reference to the installed printer.
'This will fail if the printer name passed to the DriverInit method is
'not found in the printer’s folder
PDF.DriverInit(AMYUNIPRINTERNAME)
'The SetDefaultPrinter function sets the system default printer to the one
'initialized by the DriverInit functions.
PDF.SetDefaultPrinter()
'First, Lock Amyuni Printer
PDF.Lock("presentation.pptx")
'Second, configure the printer
'This method replaces the properties DefaultDirectory, DefaultFileName and FileNameOptions
PDF.SetDocFileProps("presentation.pptx", acFileNameOptions.NoPrompt, "C:\Temp", "")
'The EnablePrinter() method needs to be called right before each print job.
'Calling the EnablePrinter() method will start a 20 second time-out value
PDF.EnablePrinter(strLicenseTo, strActivationCode)
'The BatchConvert method converts a file to PDF.
PDF.BatchConvert("C:\Temp\presentation.pptx")
'Test Lock
MsgBox(PDF.TestLock("presentation.pptx"))
'Finally, unlock Amyuni Printer
PDF.Unlock("presentation.pptx", 1000)
'The RestoreDefaultPrinter function resets the system default printer
'to the printer that was the default before the call to SetDefaultPrinter.
PDF.RestoreDefaultPrinter()
'This function will simply detach from an existing printer because the handle was created using DriverInit
PDF.DriverEnd()
'Destroy PDF object
PDF = Nothing
End Sub
[Flags]
public enum acFileNameOptions
{
// Please check FileNameOptions for the complete flags version
NoPrompt = 0x00000001,
UseFileName = 0x00000002,
EmbedFonts = 0x00000010,
BroadcastMessages = 0x00000020,
}
public void Lock()
{
// Constants for Activation codes
const string strLicenseTo = "DOCX Converter Developer Evaluation";
const string strActivationCode = "07EFCDAB010001002EE718DAABD90353AA8141F60B6762C695F4D5BA97F516CBE3EB407DC717EC1D28DE39A61F1ACE26924C99AFB190";
const string AMYUNIPRINTERNAME = "DOCX Converter Developer Evaluation";
// Declare a new cdintfex object if it does not exist in the form.
CDIntfEx.CDIntfEx PDF = new CDIntfEx.CDIntfEx();
// Get a reference to the installed printer.
// This will fail if the printer name passed to the DriverInit method is
// not found in the printer’s folder
PDF.DriverInit(AMYUNIPRINTERNAME);
// The SetDefaultPrinter function sets the system default printer to the one
// initialized by the DriverInit functions.
PDF.SetDefaultPrinter();
// First, Lock Amyuni Printer
PDF.Lock("presentation.pptx");
// Second, configure the printer
// This method replaces the properties DefaultDirectory, DefaultFileName and FileNameOptions
PDF.SetDocFileProps("presentation.pptx", (int)acFileNameOptions.NoPrompt, "C:\\Temp", "");
// The EnablePrinter() method needs to be called right before each print job.
// Calling the EnablePrinter() method will start a 20 second time-out value
PDF.EnablePrinter(strLicenseTo, strActivationCode);
// The BatchConvert method converts a file to PDF.
PDF.BatchConvert("c:\\Temp\\presentation.pptx");
// Test Lock
MessageBox.Show(Convert.ToString(PDF.TestLock("presentation.pptx")));
// Finally, Unlock Amyuni Printer in case of error
PDF.Unlock("presentation.pptx", 1000);
// The RestoreDefaultPrinter function resets the system default printer
// to the printer that was the default before the call to SetDefaultPrinter.
PDF.RestoreDefaultPrinter();
// This function will simply detach from an existing printer because the handle was created using DriverInit
PDF.DriverEnd();
// Destroy PDF object
PDF = null;
}
// PDF Converter Cpp.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <Windows.h>
#include <string>
#include <iostream>
#include "CdIntf.h"
#pragma comment (lib, "CDIntf.lib")
using namespace std;
int main()
{
// Constants for Activation codes
#define strLicenseTo "DOCX Converter Developer Evaluation"
#define strActivationCode "07EFCDAB010001002EE718DAABD90353AA8141F60B6762C695F4D5BA97F516CBE3EB407DC717EC1D28DE39A61F1ACE26924C99AFB190"
#define AMYUNIPRINTERNAME "DOCX Converter Developer Evaluation"
// Get a reference to the installed printer.
// This will fail if the printer name passed to the DriverInit method is
// not found in the printer’s folder
HANDLE PDF = DriverInit(AMYUNIPRINTERNAME);
// The CDISetDefaultPrinter function sets the system default printer to the one
// initialized by the DriverInit functions.
CDISetDefaultPrinter(PDF);
// First, Lock Amyuni Printer
Lock(PDF, "presentation.pptx");
// Second, configure the printer
// This method replaces the properties DefaultDirectory, DefaultFileName and FileNameOptions
SetDocFileProps(PDF, "presentation.pptx", NoPrompt, "C:\\Temp", "");
// The EnablePrinter() method needs to be called right before each print job.
// Calling the EnablePrinter() method will start a 20 second time-out value
EnablePrinter(PDF, strLicenseTo, strActivationCode);
// The BatchConvert method converts a file to PDF.
BatchConvertEx(PDF, "c:\\Temp\\presentation.pptx");
// Test Lock
cout << TestLock(PDF, "presentation.pptx");
// Finally, Unlock Amyuni Printer in case of error
Unlock(PDF, "presentation.pptx", 1000);
// The RestoreDefaultPrinter function resets the system default printer
// to the printer that was the default before the call to SetDefaultPrinter.
RestoreDefaultPrinter(PDF);
// This function will simply detach from an existing printer because the handle was created using DriverInit
DriverEnd(PDF);
// Destroy PDF object
PDF = nullptr;
return 0;
}
package Example;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
public class GUnLock {
public enum acFileNameOptions
{
// Please check FileNameOptions for the complete flags version
NoPrompt(0x00000001),
UseFileName(0x00000002),
EmbedFonts(0x00000010),
BroadcastMessages(0x00000020);
public int value;
public acFileNameOptions(int value)
{
this.value = value;
}
public Object value(){
return value;
}
}
public static void main(String[] args)
{
// Constants for Activation codes
String strLicenseTo = "DOCX Converter Developer Evaluation";
String strActivationCode = "07EFCDAB010001002EE718DAABD90353AA8141F60B6762C695F4D5BA97F516CBE3EB407DC717EC1D28DE39A61F1ACE26924C99AFB190";
String AMYUNIPRINTERNAME = "DOCX Converter Developer Evaluation";
// Declare a new cdintfex object if it does not exist in the form.
ActiveXComponent pdf = new ActiveXComponent("CDIntfEx.CDIntfEx.6.5");
// Get a reference to the installed printer.
// This will fail if the printer name passed to the DriverInit method is
// not found in the printer’s folder
Dispatch.call(pdf,"DriverInit",AMYUNIPRINTERNAME);
// The SetDefaultPrinter function sets the system default printer to the one
// initialized by the DriverInit functions.
Dispatch.call(pdf,"SetDefaultPrinter");
// First, Lock Amyuni Printer
Dispatch.call(pdf,"Lock", "presentation.pptx");
// Second, configure the printer
// This method replaces the properties DefaultDirectory, DefaultFileName and FileNameOptions
Dispatch.call(pdf,"SetDocFileProps", "presentation.pptx", acFileNameOptions.NoPrompt.value, "C:\\Temp", "");
// The EnablePrinter() method needs to be called right before each print job.
// Calling the EnablePrinter() method will start a 20 second time-out value
Dispatch.call(pdf,"EnablePrinter", strLicenseTo, strActivationCode);
// The BatchConvert method converts a file to PDF.
Dispatch.call(pdf,"BatchConvert","c:\\Temp\\presentation.pptx");
// Test Lock
Dispatch.call(pdf,"TestLock", "presentation.pptx");
// Finally, Unlock Amyuni Printer in case of error
Dispatch.call(pdf,"Unlock", "presentation.pptx", 1000);
// The RestoreDefaultPrinter function resets the system default printer
// to the printer that was the default before the call to SetDefaultPrinter.
Dispatch.call(pdf,"RestoreDefaultPrinter");
// This function will simply detach from an existing printer because the handle was created using DriverInit
Dispatch.call(pdf,"DriverEnd");
// Destroy PDF object
pdf = null;
}
}
$acFileNameOptions = @{
NoPrompt = 0x00000001
UseFileName = 0x00000002
EmbedFonts = 0x00000010
BroadcastMessages = 0x00000020
}
#Please check FileNameOptions for the complete flags version
# Constants for Activation codes
$strLicenseTo = "DOCX Converter Developer Evaluation"
$strActivationCode = "07EFCDAB010001002EE718DAABD90353AA8141F60B6762C695F4D5BA97F516CBE3EB407DC717EC1D28DE39A61F1ACE26924C99AFB190"
$AMYUNIPRINTERNAME = "DOCX Converter Developer Evaluation"
#Declare a new cdintfex object if it does not exist in the form.
$PDF = New-Object -ComObject CDIntfEx.CDIntfEx.6.5
#Get a reference to the installed printer.
#This will fail if the printer name passed to the DriverInit method is
#not found in the printer’s folder
[System.__ComObject].InvokeMember('DriverInit',[System.Reflection.BindingFlags]::InvokeMethod,$null,$PDF,$AMYUNIPRINTERNAME)
#The SetDefaultPrinter function sets the system default printer to the one
#initialized by the DriverInit functions.
[System.__ComObject].InvokeMember('SetDefaultPrinter',[System.Reflection.BindingFlags]::InvokeMethod,$null,$PDF,$null)
#First, Lock Amyuni Printer
[System.__ComObject].InvokeMember('Lock',[System.Reflection.BindingFlags]::InvokeMethod,$null,$PDF, "presentation.pptx")
#Second, configure the printer
#This method replaces the properties DefaultDirectory, DefaultFileName and FileNameOptions
[System.__ComObject].InvokeMember('SetDocFileProps',[System.Reflection.BindingFlags]::InvokeMethod,$null,$PDF,
@("presentation.pptx", $acFileNameOptions::NoPrompt, "C:\Temp", ""))
#The EnablePrinter() method needs to be called right before each print job.
#Calling the EnablePrinter() method will start a 20 second time-out value
[System.__ComObject].InvokeMember('EnablePrinter',[System.Reflection.BindingFlags]::InvokeMethod,$null,$PDF, @($strLicenseTo, $strActivationCode))
#The BatchConvert method converts a file to PDF.
[System.__ComObject].InvokeMember('BatchConvert',[System.Reflection.BindingFlags]::InvokeMethod,$null,$PDF, "C:\Temp\presentation.pptx")
#Finally, Unlock Amyuni Printer in case of error
[System.__ComObject].InvokeMember('Unlock',[System.Reflection.BindingFlags]::InvokeMethod,$null,$PDF, @("presentation.pptx", 1000))
}
#The RestoreDefaultPrinter function resets the system default printer
#to the printer that was the default before the call to SetDefaultPrinter.
[System.__ComObject].InvokeMember('RestoreDefaultPrinter',[System.Reflection.BindingFlags]::InvokeMethod,$null,$PDF,$null)
#This function will simply detach from an existing printer because the handle was created using DriverInit
[System.__ComObject].InvokeMember('DriverEnd',[System.Reflection.BindingFlags]::InvokeMethod,$null,$PDF,$null)
#Destroy PDF object
$PDF = $null
'FileNameOptions constants
'Please check FileNameOptions for the complete flags version
Const NoPrompt = 1
Const UseFileName = 2
Const EmbedFonts = 16
Const BroadcastMessages = 32
'Constants for Activation codes
Const strLicenseTo = "DOCX Converter Developer Evaluation"
Const strActivationCode = "07EFCDAB010001002EE718DAABD90353AA8141F60B6762C695F4D5BA97F516CBE3EB407DC717EC1D28DE39A61F1ACE26924C99AFB190"
Const AMYUNIPRINTERNAME = "DOCX Converter Developer Evaluation"
' Declare a new cdintfex object
Dim PDF
Set PDF = CreateObject("CDIntfEx.CDIntfEx.6.5")
'Get a reference to the installed printer.
'This will fail if the printer name passed to the DriverInit method is
'not found in the printer’s folder
PDF.DriverInit AMYUNIPRINTERNAME
'The SetDefaultPrinter function sets the system default printer to the one
'initialized by the DriverInit functions.
PDF.SetDefaultPrinter
'First, Lock Amyuni Printer
PDF.Lock "presentation.pptx"
'Second, configure the printer
'This method replaces the properties DefaultDirectory, DefaultFileName and FileNameOptions
PDF.SetDocFileProps "presentation.pptx", NoPrompt, "C:\Temp", ""
'The EnablePrinter() method needs to be called right before each print job.
'Calling the EnablePrinter() method will start a 20 second time-out value
PDF.EnablePrinter strLicenseTo, strActivationCode
'The BatchConvert method converts a number of files to PDF.
PDF.BatchConvert "C:\Temp\presentation.pptx"
'Test Lock
WScript.Echo(PDF.TestLock("presentation.pptx"))
'Finally, Unlock Amyuni Printer in case of error
PDF.Unlock "presentation.pptx", 1000
'The RestoreDefaultPrinter function resets the system default printer
'to the printer that was the default before the call to SetDefaultPrinter.
PDF.RestoreDefaultPrinter
'This function will simply detach from an existing printer because the handle was created using DriverInit
PDF.DriverEnd
'Destroy pdf object
Set PDF = Nothing