Use LlGetPrinterFromPrinterFile in VBA

we want read printer from file but not understand how to use functio. we receive error -44
You ha a sample ?

Dim ret As Long
Dim tmpBuffer As String * 1000
Dim MyDevMode As DEVMODEA
Dim sizeBuffer1 As Long
Dim sizeBuffer2 As Long

ret = LlGetPrinterFromPrinterFile(ListLabel1.hJob, LL_PROJECT_CARD, App.Path & “\devmode.crd”, 0, tmpBuffer, sizeBuffer1, MyDevMode, sizeBuffer2)

Debug.Print ret

To read the printer name in VBA from a P-file, the declaration of the function has to be adapted a bit. Add the following line to the declaration file “cmll??.bas”:

Declare Function LlGetPrinterFromPrinterFile2 Lib "CMLL28. DLL" Alias "LlGetPrinterFromPrinterFileA" (ByVal hJob As Long, ByVal nObjType As Long, ByVal pszObjectName 
As String, ByVal nPrinter As Long, ByVal pszPrinter As String, pnPrinterBufSize As Long, ByVal pDevMode As Long, ByVal pnDevModeBufSize As Long) As Long

The call to the function would then be as follows:

Dim sPRNName As String 'Printer name
sPRNName = String(255, vbNull)
Dim nPRNSize As Long ' Size of the printer driver
nPRNSize = Len(sPRNName)

ret% = LlGetPrinterFromPrinterFile2(ListLabel1.hJob, LL_PROJECT_LABEL, App.Path & 
"\devmode.crd", -1, sPRNName, nPRNSize, 0, 0)

MsgBox left(sPRNName, nPRNSize)
1 Like

thanks a lot, it works perfectly.
just a problem because I hadn’t seen the space
Lib “CMLL28.DLL”
and then I kept getting the error 53

1 Like

Sorry,
sorry i was implementing in code.
If I pass LL_PROJECT_CARD as parameter to a report which I’m sure is like this (indeed edit calls use this parameter) I get an error message saying that the file may be password protected, invalid format and created with a newer version of the software. Despite this in the variable I find the name of the printer. If I pass as parameter LL_PROJECT_LIST I have no error messages and the printer name is correct.
The same thing also happens vice versa.
Am I wrong in passing the parameter ??

Strange, I can’t reproduce it that way. Can you upload the corresponding reports and p - files here (if that is possible). Please also post the corresponding call of the function.

Declare Function LlGetPrinterFromPrinterFile2 Lib “CMLL28.DLL” Alias “LlGetPrinterFromPrinterFileA” (ByVal hJob As Long, ByVal nObjType As Long, ByVal pszObjectName As String, ByVal nPrinter As Long, ByVal pszPrinter As String, pnPrinterBufSize As Long, ByVal pDevMode As Long, ByVal pnDevModeBufSize As Long) As Long

Dim sPRNName As String 'Printer name
Dim nPRNSize As Long ’ Size of the printer driver

sPRNName = String(255, vbNull)
nPRNSize = Len(sPRNName)

ret% = LlGetPrinterFromPrinterFile2(LL.hJob, 2, “C:\TEMP\REPORTS\AC.lsp”, -1, sPRNName, nPRNSize, 0, 0)
MSGBOX ERROR, BUT sPRNName CONTAINS CORRECT VALUE
image


'ISTRUCTION FOR MODIFY REPORT - NO PROBLEM
ret% = LL.LlDefineLayout(Application.hWndAccessApp, Messaggio & " - Modifica Layout ", 2, “C:\TEMP\REPORTS\AC.MOW”)
REPORT.zip (6.6 KB)

Thanks,
I hope you find what I’m doing wrong

Can you try to pass the MOW file (which is the actual project file) instead of the lsp?

Like so:

ret% = LlGetPrinterFromPrinterFile2(LL.hJob, 2, “C:\TEMP\REPORTS\AC.MOW”, -1, sPRNName, nPRNSize, 0, 0)

Thank You very much,
so it works, but if i changed the extension of the files
with the function
ret = LL.LlSetFileExtensions(LL, LL_PROJECT_CARD, “FID”, “CRP”, “CRV”, 1)
automatically handle reading the correct printer definition file ?

No matter which extension you’re using, you need to pass the full and correct file name of the project file (!) to the API by design. Good to hear it’s working now for you :slight_smile:.

1 Like

Thank you so much for the clarification and support
Good work

1 Like