LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Win32 API StartDocPrinter parameter Help?

I'm trying to convert a VB example (see http://support.microsoft.com/default.aspx?scid=kb;en-us;154078) of sending data directly to the print spooler and I am having trouble with the StartDocPrinter function because of a special parameter. The function prototype looks like:

DWORD StartDocPrinter(
HANDLE hPrinter, // handle to printer object
DWORD Level, // information level
LPBYTE pDocInfo // information buffer
);
and pDocInfo as:
typedef struct _DOC_INFO_1 {
LPTSTR pDocName;
LPTSTR pOutputFile;
LPTSTR pDatatype;
} DOC_INFO_1;

I configured the Call Library Function as following:
stdcall(WINAPI) calling convention,
DWORD return parameter as U32,
HANDLE hPrinter as U32 pass by value,
DWO
RD Level as U32 pass by value,
LPBYTE pDocInfo as ???.

Right now for pDocInfo, I am using a 2D array of U8 with nothing in it which allows the function to at least be called without an exception error but does not return a passing indication of proper use (always returns a 0).

This would make sending HPGL plot files to a LaserJet a breeze. Thanks.
0 Kudos
Message 1 of 5
(4,390 Views)
Ralph,

You will need to write a wrapper function in C to do what you want. This is because LabVIEW cannot directly handle pointers in structures. What you should do is pass put all of the fuction parameters and the three strings from LabVIEW to a fuction that you write. Then, create a pointer to each of the strings, place them into a structure (probably have a static structure that you replace the values), and then call the Win32 API function. I apologize that this is a little harder than what you might have thought it would be, but this is the best way to do what you want.

Randy Hoskin
Applications Engineer
National Instruments
http://www.ni.com/ask
0 Kudos
Message 2 of 5
(4,390 Views)
Thanks. I vaguely understand. I was hoping to fool the StartDocPrinter with LV so I wouldn't have to write any extra external code.
Now the question, Do I write the C wrapper or convert the working VB example to an activex server. Both involve more research.
The ultimate goal was to send a file to the print spooler without any overhead or formatting or going thru any windows apps. I appreciate your reply.

RH
0 Kudos
Message 3 of 5
(4,390 Views)
Ralph,

I would do the C wrapper function because doing it throug ActiveX will cause another process to start in memory and will probably be slower.

Your C wrapper function (you could do this in s CIN instead of a DLL so that it is all in LabVIEW; see the Using External Code in LabVIEW manual in the LabVIEW Bookshelf for more information) would look like this:

Uint32 WrapStartDocPrinter(
Uint32 hPrinter, // handle to printer object
Uint32 Level, // information level
CStr pDocName, // information buffer
CStr pOutputFile,
CStr pDatatype)
{
DOC_INFO_1 mdi1;
mdi1.pDocName = pDocName;
mdi1.pOutputFile = pOutputFile;
mdi1.pDatatype = pDatatype;
return StartDocPrinter(
hPrinter, // handle to printer object

Level, // information level
(void*)(&mdi1) // information buffer
);
}

Use what I have written and the Using External Code in LabVIEW manual to get how to set it up and build it and you will be on your way. This should be about 30 - 45 minutes worth of work for doing it the first time with the manual.

Randy Hoskin
Applications Engineer
National Instruments
http://www.ni.com/ask
0 Kudos
Message 4 of 5
(4,390 Views)
I always enjoy hearing from someone who knows what they're talking about. Since I don't currently have a C compiler (dooh!), I went the activeX route.

It was my first attempt but with a good example in the MS help files, I succeeded in doing it in VB6. I may have to spruce it up when I have time in order to be able to select a printer to use. The code defaults to the first printer in the system. That is okay for the job I'm doing since it is the only printer. (now that I deleted the HP LJ 1000 DOS printer that was automatically installed)

I appreciate the simple solution to the wrapper and will file it for later.

Ralph
0 Kudos
Message 5 of 5
(4,390 Views)