11-27-2012 03:04 PM - edited 11-27-2012 03:23 PM
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...
Solved! Go to Solution.
11-27-2012 03:25 PM - edited 11-27-2012 03:25 PM
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...
11-27-2012 09:13 PM
No. You actually did NOT allocated memory in your VI.
Here is how to allocated memory, the old way:
11-27-2012 09:19 PM
Or you can do it in pure G: