Initialize Imaging Toolkit. For more information, see Understanding Imaging Toolkit initialization.
Create a context. For more information, see Understanding context creation.
If applicable, set the port range. For more information, see Understanding the port range.
Set the scan settings. For more information, see Understanding scan settings specification.
Set the output directory and filename.
If applicable, register a callback function. For more information, see Registering a callback function.
Call one of the scan functions. For more information, see Calling the scan functions.
Uninitialize the Imaging Toolkit. For more information, see Uninitializing.
Retrieve the created scan context. For more information, see Understanding scan context retrieval.
MFPSB_Initialize()
The
function lets the Imaging Toolkit library initialize internal data structures, read the Windows registry, and configure Imaging Toolkit. If is set to , then the function also creates a receiving socket. We recommend calling this API when initializing the application, if is set to .MFPSB_CreateScanContext()
The
function returns an value that is used as a handle to refer to a particular scan job.To create a handle, provide the following:
Printer IP address
Profile name
TCP port number
The function fails when it cannot communicate with the printer. If
is set to , then the port value is ignored.MFPSB_HCTX hCtx; hCtx = MFPSB_CreateScanContext("myprinter.lexmark.com", "mylabel", 9700); if (hCtx == NULL) { //There was an error creating the context. }
The
function designates the ports that Imaging Toolkit uses for receiving images. Lower and upper port range values are passed as a parameter, and must be set between 1024 and 65535. To disable the port range function and delete specified values, set the lower and upper port numbers to .If isEmptyLowPort = True And isEmptyUpperPort = True Then //Disable the port range nLowerPort = -1 nUpperPort = -1 lError = MFPSB_SetPortRange(nLowerPort, nUpperPort) //Error code handling. ......... Else .............. //Setting the port range. nLowerPort = Val(txtLowerPort) nUpperPort = Val(txtUpperPort) lError = MFPSB_SetPortRange(nLowerPort, nUpperPort)
int lowerport = 1024; int upperport = 65535; DWORD dwd = MFPSB_SetPortRange(lowerport,upperport); if(dwd == 0) //Success else //Show error message
MFPSB_SetScanSetting()
Imaging Toolkit allows scan parameters for contexts. Each context has its own set of parameters. To query the parameters, use the
function.dwError = MFPSB_SetScanSetting(hCtx, “RESOLUTION”, “200”); if (dwError != MFPSB_E_SUCCESS) { //Your code to handle this error } Char sValue[32]; Long sValueLen = 32; //Get the value for the resolution parameter dwError = MFPSB_QueryScanSetting(hCtx, “RESOLUTION”, sValue, &sValueLen); if (dwError != MFPSB_E_SUCCESS) { //Your code to handle the error }
To retrieve a list of all scan settings for a specified context ID, use
.DWORD MFPSB_GetScanSettingsAsString(HANDLE hCtx, LPSTR sValue, LONG *sValueLen)
Where:
is the handle or ID of the context.
retrieves as a string delimited by Full Search and End of Transmission Block.
is the number of context IDs.
Notes:
Declare Function MFPSB_GetScanSettingsAsString Lib "mfpsb.dll"_ (ByVal hContext As Long,_ ByVal IpSettingValue As String,_ ByRef IpLength As Long) As Long
hCtx = IbContexts.Text IStringLength = 400 IErrorCode = MFPSB_GetScanSettingsAsString(hCtx, sValue, IStringLength) FS = Chr(28) For I = 0 To 14 nStartPos = 0 nEqualPos = 0 nFSPos = 0 sSetting = sScanSetting(i) nStartPos = InStr(1, sValue, sSetting, vbTextCompare) If nStartPos > 0 The nEqualPos = nStartPos + Len(sSetting) nFSPos = InStr(Right(sValue, Len(sValue) - nEqualPos), FS) If I = 14 Then sEdgeToEdgeVal = Mid$(sValue, nEqualPos +1, nFSPos - 1) If sEdgeToEdgeVal = True Then Check1.Value = 1 Else Check.Value = 0 End If Else tbScanSetting(i).Text = Mid$(sValue, nEqualPos + 1, nFSPos - 1) End If End If
CHAR value[10]; LONG valueLen = 10; LONG* pValueLen = &vanlueLen; dwd = MFPSB_GetScanSettingsAsString(contextid,value,pValueLen); if(dwd==0) { //Success } else { //Show error message }
MFPSB_RegisterCallback()
When registering the callback function, determine the events that must cause the Imaging Toolkit library to initiate the callback function. If a handle to a window is provided in the function, then the initialization of the callback occurs in the window procedure of this window. The imaging process runs on its own separate thread, and the calling application may require the callback to run in the same thread as the application. This process is the same for Visual Basic programs.
VOID_stdcall myCallback (MFPSB_HCTX hCtx, LONG lpId, LPVARIANT lpInfo) { //Your own code representing what should be done } . . . DWORD dwError; dwError = MFPSB_RegisterCallBack(hCtx, (MFPSB_PFNCALLBACK) myCallback, MFPSB_SBALLEVENTS, hWnd);
MFPSB_StartScanBack() MFPSB_StartScanBackNoBlock()
The two scan function options let you scan with or without a blocking function. The non-blocking versions allow the application to respond to your input. When you call the function, the profile is sent to the printer, and the Toolkit waits for the printer to connect back to it.
//Start the scan process. dwError = MFPSB_StartScanBackNoBlock(hCtx); if (dwError != MFPSB_E_SUCCESS) { //The imaging process failed to start //handle the error }
MFPSB_Uninitialize()
This function releases all resources used by the library and deletes any remaining contexts.
We recommend calling these APIs when creating an instance of the application.
—Determines the number of context IDs.
—Retrieves the following details of each scan context and identified by a context ID:
Profile name
MFP IP address
Output directory
Output file name
Declare Function MFPSB_GetInitContexts Lib "mfpsb.dll"_ (ByRef address As Any,_ ByRef numContexts As Integer) As Long
Declare Function MFPSB_GetInitContextProfileInfo Lib "mfpsb.dll"_ (ByVal IContextID As Long,_ ByVal sProfileName As String,_ ByVal sMFPIP As String,_ ByVal sOutputFileDir As String,_ ByVal sOutputFileName as String,_ ByVal sIconFile as String) As Long
sProfileName = Space$(35) sMFPIP = Space$(16) sOutputDir = Space$(225) sOutputFileName = Space$(35) sIconFile = Space$(260) IError = MFPSB_GetInitContexts(ByVal VarPtr(cList.ctx(oneIndex), sProfileName, sMFPIP, sOutputFileDir, sOutputFileName, sIconFile) If IError = 0 Then IbContexts.AddItem (cList.ctx(oneIndex)) Conexts(oneIndex, 0) = cList.ctx(oneIndex)) Conexts(oneIndex, 1) = sMFPIP Conexts(oneIndex, 2) = sProfileName Conexts(oneIndex, 3) = sOutputFileDir Conexts(oneIndex, 4) = sOutputFileName Conexts(oneIndex, 5) = sIconFile numContexts = numContexts + 1 End If Next oneIndex
LONG64 context[24]; MFPSB_HCTX initcontextPtr = context; int numContexts = 24; DWORD dwd = MFPSB_GetInitContexts(initcontextPtr, numContexts); if(dwd == 0 ) { for(int iIndex=0 ; iIndex< numContexts; iIndex++) { //Show context ID } } else { //Show error message } CHAR directory[32]; CHAR sIPAddress[32]; CHAR sOutputfilename[32]; CHAR sIconfile[32]; CHAR sProfileName[32]; dwd = MFPSB_GetInitContextProfileInfo(contextid,sProfileName,sIPAddress,directory,sOutputfilename,sIconfile); if(dwd == 0) { //Success } else //Show error message
We recommend using a C# application from the <install-dir>\native\bin folder, where <install-dir> is the installation directory of the application.
The sample application sends scan profiles to a printer, and then receives the scanned images. To facilitate the imaging process, the MFPSB API exposed by the DLL consists of 16 functions. You can run the sample application from the bin folder of this package.
To copy the sample to another location, store all DLL files from the bin folder in the application folder. You can also copy the sample in the PATH environment variable.
If an icon is used when creating profiles, then the style sheets contained in the bin folder must be in the following:
PATH environment
Application directory
From the application, create a context.
Enter the IP address or host name of the printer.
Type the profile name.
Click Create Context.
An integer appears in the Contexts list box. The default values for the scan settings also appear. Create Context calls the
function to create the context, and then calls the when successful.The callback function for this application writes information in the output window.
Set the port range.
Set the lower and upper port range. The value can be from 1024 to 65535.
Click Set Port Range.
The port range is set by calling
.If port range settings are not specified, then the server attempts to open a socket on the first available port.
Enter the scan settings.
Enter a value for each scan setting.
Click Set Values.
To test the value, click Get Values.
is called for each setting.
Get Values calls the
for each setting and updates the fields with the result.Select a directory and file name for the output.
Type the name of the directory and the output file. If these fields are not specified, then the directory used is the one where the application is running. The file name matches the profile name. These names can be entered at any time before Do Scan is selected, and files are overwritten without prompting.
If you select Do Scan, then the
API function is called before .Type the full path of the icon file.
If the printer has a control panel with a welcome screen, then send an icon to the printer, and then show it on the welcome screen. If the Icon field is not empty when Do Scan is selected, then the
function is called.Perform the scan.
Clicking Do Scan sends a profile to the printer by calling the
API function. This function is a non-blocking call. Updates on status come through the callback function which shows text into the output window. The scan job is initiated when the shortcut number or icon at the printer is used.Setting | Description |
---|---|
Cancel Scan | Cancels the scan job |
Exit | Closes the application |
Remove | Deletes the profile currently selected in the Profile Name field |
Release Context | Releases any resources used by the scan context |
Open Scanned Images | Executes a shell command on the output file for opening the scanned image |
Error message | Error number | What it means | Functions that can return the error |
---|---|---|---|
0 | A successful operation has completed. | N/A | |
1 | An error occurred when binding to a TCP port where the printer is connecting. | ||
3 | The timeout value specified in has elapsed while waiting for a printer to connect. | ||
4 | An invalid value is passed to one of the API functions. | ||
5 | An invalid setting name is passed to or . | ||
6 | An invalid setting value is passed to . | ||
8 | A null pointer is passed as a parameter to a function that does not accept for the argument. | ||
10 | One of the StartScanBack functions failed because is called. | ||
13 | The printer responded with invalid data when applying or removing the scan profile. | ||
15 | The printer closed the connection while sending scan data. | ||
17 | Imaging Toolkit is unable to connect to the printer. | ||
18 | Imaging Toolkit is unable to open the output file to save the scanned image. | ||
19 | The requested operation is unsupported. This error occurs when trying to set a welcome screen icon for a printer that does not have a control panel. | ||
20 | Corrupted data is received from the printer. | ||
21 | One of the profile fields for the printer is bad. This error usually occurs when a profile is given an existing name on the printer. | ||
22 | The printer cannot store any more profiles due to space limitations. Delete profiles from the printer. | ||
23 | The printer disabled the requested function. | ||
25 | The has already been called without completing the supplied context. | ||
27 | An error occurred when verifying the HTTP response preceding an attempt to upload a profile to the printer. | ||
28 | The printer is at maximum capacity and discarded the profile, and then another profile was submitted. | ||
29 | A communication error occurred when applying the profile to the printer. | ||
30 | There are no shortcuts left in the range [MinShortcut, MaxShortcut]. | ||
31 | The profile sent to the printer is removed. | ||
32 |
| ||
33 | The server socket cannot be created because a port is not available. | ||
34 | The target directory does not exist, or the target file name is invalid. | ||
53 | The context list is not found when Imaging Toolkit initialized. | ||
54 | The profile from the MFP is not found. |