This is my code:
//============================
void InitPrinter (void)
{
char szPrinterName[255];
unsigned long lPrinterNameLength;
DOCINFO di;
int nError;
GetDefaultPrinter (szPrinterName, &lPrinterNameLength);
hPrinterDC = CreateDC("WINSPOOL\0", szPrinterName, NULL, NULL);
memset( &di, 0, sizeof(DOCINFO) );
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = "PrintIt";
di.lpszOutput = (LPTSTR) NULL;
di.lpszDatatype = (LPTSTR) NULL;
di.fwType = 0;
nError = StartDoc(hPrinterDC, &di);
if (nError == SP_ERROR)
{
printf("\nError - please check printer.");
// Handle the error intelligently
}
}
//============================
Should i add any *.lib to the project ? should i use any *.dll ?
Any help, example, link, documents would be great.
Thanks
Ofer
This implies but does not say that the linker error was that
GetDefaultPrinter was not found. By not giving the actual text of the linker
error anyone trying to help you is less certain as to the cause of the
problem.
Assuming that the linker error was a symbol not found error, which of
GetDefaultPrinter, GetDefaultPrinterA or GetDefaultPrinterW was what was
reported as not found?
You do not need to include winspool.h to make the compiler aware of the
function GetDefaultPrinter. Including windows.h already does that for you.
If you have not included windows.h, do so now and do it at the top of the
file.
> Should i add any *.lib to the project ? should i use any *.dll ?
> Any help, example, link, documents would be great.
As long as your project is configured to be for a Win32 target the IDE will
arrange for the correct library to be included in the link. In this case
that library is import32.lib
. Ed
> Ofer Gaatone wrote in message
> news:488d...@newsgroups.borland.com...
http://www.codeguru.com/forum/archive/index.php/t-137016.html
Also: TPrinter and TPrintDialog have the function without parameters
Ray Sittig
. Ed
> Ray Sittig wrote in message
> news:488f0c3f$1...@newsgroups.borland.com...
Ok.
Windows does not provide a function whose public name is _GetDefaultPrinter.
Pull up winspool.h in the editor and look for for the text GetDefaultPrinter
Do not select "whole word" in your search. You should find something like
this
-------------------
#ifdef UNICODE
#define GetDefaultPrinter GetDefaultPrinterW
#else
#define GetDefaultPrinter GetDefaultPrinterA
#endif
-------------------
Later in the file there should be a function prototype something like this
-------------------
BOOL WINAPI GetDefaultPrinterA(
LPSTR pszBuffer,
LPDWORD pcchBuffer);
-------------------
The idea is that if you are writing a normal (ASCII based) Windows program
then the public symbol used in the program will be GetDefaultPrinterA (A for
ASCII) and if a Unicode program it will be GetDefaultPrinterW (W for Wide
String, essentially what Unicode means).
If a program is C language or if C++ but the function prototype or the
section of the file the prototype is in is decorated with extern "C" then
the external symbol is the same as seen in the source code except that a
leading underscore is added. That is what you reported.
The two problems here are that Winspool.h decorates the function prototype
with WINAPI (a macro for __stdcall) which means the leading underscore is
not used and the actual function prototype is provides ends in A or W which
the error message you show does not have.
The result is that one of
the winspool.h you are using is flawed
or
winspool.h is not being included in a place or manner where
it applies to the program line where you call GetDefaultPrinter
My guess is that winspool.h is just fine. Look for where you put the
include and if it is blocked out by some macro.
. Ed
> Ofer Gaatone wrote in message
> news:488e...@newsgroups.borland.com...
Winspool.h does NOT have a function prototype for GetDefaultPrinter.
Do this:
Save a copy of BC5\INCLUDE\WIN32\winspool.h
Open BC5\INCLUDE\WIN32\winspool.h in a text editor or the IDE editor
Find this line
#define DeletePrintProvider DeletePrintProviderW
Below it is this line
#endif // !UNICODE
Add a blank line following it and then add these lines
BOOL WINAPI GetDefaultPrinterA(
LPSTR pszBuffer, LPDWORD pcchBuffer );
BOOL WINAPI GetDefaultPrinterW(
LPWSTR pszBuffer, LPDWORD pcchBuffer);
#ifdef UNICODE
#define GetDefaultPrinter GetDefaultPrinterW
#else
#define GetDefaultPrinter GetDefaultPrinterA
#endif // !UNICODE
Please let me know how it works out.
. Ed
> Ofer Gaatone wrote in message
> news:488e...@newsgroups.borland.com...
>The idea is that if you are writing a normal (ASCII based) Windows program
>then the public symbol used in the program will be GetDefaultPrinterA (A for
>ASCII)
Just a little semantic nit-picking:
I believe the "A" is for ANSI, as Windows originally used the ANSI
character set, unlike DOS which used the ASCII character set.
- Wayne
- Wayne A. King
wak...@idirect.com
. Ed
> Wayne A. King wrote in message
> news:4tu494to80dlih656...@4ax.com...
Ofer
Below is a copy of the message.
. Ed
--------------------------------------
Ok, I have finally managed to resurect the Win95 machine so that I can
look at the include files that came from the 11-year-old BC++ 5.02.
Winspool.h does NOT have a function prototype for GetDefaultPrinter.
Do this:
Save a copy of BC5\INCLUDE\WIN32\winspool.h
Open BC5\INCLUDE\WIN32\winspool.h in a text editor or the IDE editor
Find this line
#define DeletePrintProvider DeletePrintProviderW
Below it is this line
#endif // !UNICODE
Add a blank line following it and then add these lines
BOOL WINAPI GetDefaultPrinterA(
LPSTR pszBuffer, LPDWORD pcchBuffer );
BOOL WINAPI GetDefaultPrinterW(
LPWSTR pszBuffer, LPDWORD pcchBuffer);
#ifdef UNICODE
#define GetDefaultPrinter GetDefaultPrinterW
#else
#define GetDefaultPrinter GetDefaultPrinterA
#endif // !UNICODE
Please let me know how it works out.
--------------------------------------
> Ofer Gaatone wrote in message
> news:4895bfa6$1...@newsgroups.borland.com...