SetCustomFilenameTemplate

 

 

#include “BlackIceDEVMODE.h”

 

BOOL            SetCustomFilenameTemplate (BlackIceDEVMODE* pDevMode, LPCWSTR pszFilenameTemplate);

Description

Sets the template string of the custom file name. This function can be used only when the filename generation method is set to ‘Custom file naming’.

Parameters

BlackIceDEVMODE* pDevMode                           - pointer to the BlackIceDEVMODE structure.

LPCWSTR pszFilenameTemplate                        - template string to set

Return value

TRUE on success, otherwise FALSE.

Programming Notes

The function checks the validation of the template string.

The format of the template string has to be to following:

 

[prefix][optional_field1][custom_field][optional_field2].[extension]

 

[prefix] can be the following:

The prefix is a maximum 4 characters long string. Prefix can contain any characters, except invalid filename characters, such as ? or *. The prefix can be an empty string.

[optional_field1], [optional_field2] can be the following:

<<NONE>>

The optional field is not used.

<<DOCNAME>>

Name of the document. This name is came from the printing application.

<<PAGENUM>>

Actual page number. It uses zero padding for 4 characters, for example 0005.

<<USERNAME>>

Name of the current logged in user.

<<COMPUTER>>

The host name of the computer.

<<DATE>>

Actual system date when printing in format of system default.

<<TIME>>

Actual system time when printing in format of system default.

<<TIMEMS>>

Local time with millisecond accuracy.

<<COUNTER>>

Sequential document number in 7 digits format.
The counter <<COUNTER>> can be rest manually at the following registry location:

HKEY_CURRENT_USER\Software\Black Ice Software LLC\[Black Ice Pinter driver name]      (dword) LastDocNumber

[custom_field] can be the following:

Custom_field is a maximum 64 character long string. Custom_field can contain any characters, except invalid filename characters, such as ? or *.

[extension] can be the following:

<<ORIGINAL>>

In this case the extension is the original extension of the selected file format. For example if the selected file format is JPEG the extension of the printed image will be .jpg.

Exteinsion also can be a maximum 4 charater long string, such as PDF, TIFF. This field can be empty.

 

These are some examples for the template string:

 

AAA<<NONE>><<NONE>>.<<ORIGINAL>>

<<DATE>>_printed_<<TIME>>.jpg

IMG<<DOCNAME>>printedby<<USERNAME>>.<<ORIGINAL>>

 

Field explanations:

 

prefix

optional_field1

custom_field

optional_field2

.extension

Result example

AAA

<<NONE>>

 

<<NONE>>

.<<ORIGINAL>>

AAA.PDF

 

<<DATE>>

_printed_

<<TIME>>

.jpg

4-19-2017_printed_10-44-33 AM.PDF

IMG

<<DOCNAME>>

printedby

<<USERNAME>>

.<<ORIGINAL>>

IMGDocumentprintedbyJohn.PDF

 

Code Example

C# example

 

Please see the following example for IMPORTING the BlackIceDEVMODE.dll functions in C# code:

        [DllImport("BlackIceDEVMODE.dll", EntryPoint = "LoadBlackIceDEVMODE", CharSet = CharSet.Unicode)]

        private static extern IntPtr LoadBlackIceDEVMODE(string szPrinter);

 

        [DllImport("BlackIceDEVMODE.dll", EntryPoint = "SaveBlackIceDEVMODE", CharSet = CharSet.Unicode)]

        private static extern bool SaveBlackIceDEVMODE(string szPrinter, IntPtr lDevmode);

 

        [DllImport("BlackIceDEVMODE.dll", EntryPoint = "ReleaseBlackIceDEVMODE", CharSet = CharSet.Unicode)]

        private static extern bool ReleaseBlackIceDEVMODE(IntPtr lDevmode);

 

        [DllImport("BlackIceDEVMODE.dll", EntryPoint = "SetFileGenerationMethod", CharSet = CharSet.Unicode)]

        private static extern bool SetFileGenerationMethod(int iNamegen, IntPtr lDevmode);

 

        [DllImport("BlackIceDEVMODE.dll", EntryPoint = "SetCustomFilenameTemplate", CharSet = CharSet.Unicode)]

        private static extern bool SetCustomFilenameTemplate(IntPtr lDevmode, string filenameTemplate);

 

Once imported, one can use the SetCustomFilenameTemplate function in the C# code as in the following example:

       //Set printer name

       string sPrinterName = "Black Ice ColorPlus";

           

       //Load BlackIceDEVMODE

       IntPtr ipDevmode = LoadBlackIceDEVMODE(sPrinterName);

 

       //Set exact filename type

       int iMethode = 7;

       SetFileGenerationMethod(iMethode, ipDevmode);

 

       //Set custom filename

       string sCustomFileName = "IMG <<DOCNAME>>printedby<<USERNAME>>.<<ORIGINAL>>";

       bool bRet = SetCustomFilenameTemplate(ipDevmode, sCustomFileName);

 

       //Save settings for printer driver

       SaveBlackIceDEVMODE(sPrinterName, ipDevmode);

 

       //Release BlackIceDEVMODE

       ReleaseBlackIceDEVMODE(ipDevmode);

 

VB.NET example

 

Please see the following example for IMPORTING the BlackIceDEVMODE.dll functions in VB.NET code:

       Private Declare Unicode Function LoadBlackIceDEVMODE Lib "BlackIceDEVMODE.dll" (ByVal szPrinter As String) As IntPtr

       Private Declare Unicode Function SaveBlackIceDEVMODE Lib "BlackIceDEVMODE.dll" (ByVal szPrinter As String, ByVal pHandle As IntPtr) As Boolean

       Private Declare Unicode Function ReleaseBlackIceDEVMODE Lib "BlackIceDEVMODE.dll" (ByVal pHandle As IntPtr) As Boolean

      

       Private Declare Unicode Function SetFileGenerationMethod Lib "BlackIceDEVMODE.dll" (ByVal iNamegen As Integer, ByVal pHandle As IntPtr) As Boolean

       Private Declare Unicode Function SetCustomFilenameTemplate Lib "BlackIceDEVMODE.dll" (ByVal pHandle As IntPtr, ByVal sCustomName As String) As Boolean

 

Once imported, one can use the SetCustomFilenameTemplate function in the VB.NET code as in the following example:

       'Set printer name

        Dim sPrinterName As String = "Black Ice ColorPlus"

 

        'Load BlackIceDEVMODE

        Dim ipDevmode As IntPtr = LoadBlackIceDEVMODE(sPrinterName)

 

        'Set exact filename type

        Dim methode As Integer = 7

        SetFileGenerationMethod(methode, ipDevmode)

 

        'Set custom filename

        Dim sCustomFileName As String = "IMG <<DOCNAME>>printedby<<USERNAME>>.<<ORIGINAL>>"

        Dim bRet As Boolean = SetCustomFilenameTemplate(ipDevmode, sCustomFileName)

 

        'Save settings for printer driver

        SaveBlackIceDEVMODE(sPrinterName, ipDevmode)

 

        'Release BlackIceDEVMODE

        ReleaseBlackIceDEVMODE(ipDevmode)