LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

GetDefaultPrinters (WinAPI call) Crashes Labview

Solved!
Go to solution

Hi all,

 

For several reasons I need to use the windows API to get the default printer. I know about labview's activex solutions but those are not universal. 

 

See attached VI. This winapi call crashes labview rather consistently. It runs fine and returns correctly the default printer. However, some time later, a few seconds or a few operations later it will always crash labview. Why? I've tried changing it to "Run in UI thread" instead of any thread but neither seems to help... 

 

To get it to crash immediately, try closing the VI. That seems to do it every time. Access violations... 

0 Kudos
Message 1 of 4
(2,501 Views)
Solution
Accepted by topic author pobrepablo1

Solved it. 

This is the definition according to msdn:

BOOL GetDefaultPrinter(
  _In_     LPTSTR pszBuffer,
  _Inout_  LPDWORD pcchBuffer
);

 

That buffer is pretty important. Although I had allocated more than enough, in the CLN itself I had to select "minimum size" for the pszBuffer to be pcchBuffer. That resolves the crashing. Not sure why this worked...

0 Kudos
Message 2 of 4
(2,495 Views)

No.  You actually did NOT allocated memory in your VI.

Here is how to allocated memory, the old way:

untitled.PNG

 

George Zou
0 Kudos
Message 3 of 4
(2,479 Views)

Or you can do it in pure G:

 

untitled.PNG

 

 

George Zou
Message 4 of 4
(2,477 Views)