www.digitalmars.com         C & C++   DMDScript  

c++.windows.32-bits - What am I doing wrong?

reply Alexis Golzman <agolzman ciudad.com.ar> writes:
Hello,

I tried to compile hwprint.cpp (Below) as a Windows NT executable and
I got the following errors:

sc hwprint.cpp -mn -C -WA -S -3 -a8 -c -gf -ohwprint.obj 
link /CO /NOI /DE /NOPACKF /XN /NT /ENTRY:WinMainCRTStartup
/BAS:4194304 /A:512  hwprint.LNK 
Error: C:\TEMP\HWPRINT\hwprint.OBJ(hwprint)  (15693456): Symbol
Undefined _PrintDlgA 4
Lines Processed: 124510  Errors: 1  Warnings: 0
Build failed

So I assumed I had to include the comdlg32.lib library. I checked the
"Embed Library Named:" option, added comdlg32.lib and rebuilt all, but
I still get the following errors:

sc hwprint.cpp -mn -C -WA -S -NLcomdlg32.lib -3 -a8 -c -gf
-ohwprint.obj 
link /CO /NOI /DE /NOPACKF /XN /NT /ENTRY:WinMainCRTStartup
/BAS:4194304 /A:512  hwprint.LNK 
Error: No Match Found for Export/ENTRY -  : WinMainCRTStartup
Error: C:\TEMP\HWPRINT\hwprint.OBJ(hwprint)  : Symbol Undefined
__acrtused
Error: C:\TEMP\HWPRINT\hwprint.OBJ(hwprint)  : Symbol Undefined
_memset
Lines Processed: 124510  Errors: 3  Warnings: 0
Build failed

What am I doing wrong? Please help...

Here's hwprint.cpp:

/*********************************************************************
 *
 * hwprint.cpp by Tom Lee
 *
 * Example program to demonstrate printing using the Win32 API/GDI.
 * I'm new to printing with the Win32 GDI myself (although I've
 * used the GDI heaps before for gfx etc.) - I've been
 * trying for a long time to find useful info on the Internet
 * about this very thing, but came across next to nothing.
 * I thought it'd be a disservice to the Internet not to get
 * something about printing with Win32/GDI out the door ASAP!
 *
 * -------------------------------------------------------------------
 *
 * Libraries to link in:
 *
 *	kernel32.lib, user32.lib, gdi32.lib, comdlg32.lib
 *
 ********************************************************************/
#include <windows.h>

int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine,
int nCmdShow )
{
	PRINTDLG pd;

	memset( &pd, 0, sizeof( pd ) );

	pd.lStructSize = sizeof( pd );

	/*
	 * get rid of PD_RETURNDEFAULT on the line below if you'd like
to
	 * see the "Printer Settings" dialog!
	 *
	 */
	pd.Flags = PD_RETURNDEFAULT | PD_RETURNDC;

	// try to retrieve the printer DC
	if( !PrintDlg( &pd ) )
	{
		MessageBox( NULL, "PrintDlg( &pd ) failed!", "Fatal
Error", MB_OK | MB_ICONERROR );

		return -1;
	}

	DOCINFO di;
	HDC hPrinter = pd.hDC;

	// initialization of the printing!
	memset( &di, 0, sizeof( di ) );
	di.cbSize = sizeof( di );
	StartDoc( hPrinter, &di );

		// start the first and only page
		StartPage( hPrinter );

		// uncomment the following line to print in colour! :)
		SetTextColor( hPrinter, 0x0000FF );

		// write "Hello, World!" to the printer's DC
		TextOut( hPrinter, 100, 100, "Hello World!", 13);

		// finish the first page
		EndPage( hPrinter );

	// end this document and release the printer's DC
	EndDoc( hPrinter );
	DeleteDC( hPrinter );
	return 0;
}
Feb 08 2002
parent reply Jan Knepper <jan smartsoft.cc> writes:
I think you will need a .DEF file with:

NAME            "Name"
DESCRIPTION     'Descriptiuon'
EXETYPE         NT
SUBSYSTEM       WINDOWS,4.0
STUB            'WINSTUB.EXE'
CODE             EXECUTE READ
DATA             READ WRITE
STACKSIZE       1048576,4096
HEAPSIZE        1048576,4096

You need to include the .DEF file on the link command line.
Next is seems like for some reason the linker has trouble finding memset.
This might be solved by including the required header files and making
sure the linker can find the libraries.

Jan



Alexis Golzman wrote:

 Hello,

 I tried to compile hwprint.cpp (Below) as a Windows NT executable and
 I got the following errors:

 sc hwprint.cpp -mn -C -WA -S -3 -a8 -c -gf -ohwprint.obj
 link /CO /NOI /DE /NOPACKF /XN /NT /ENTRY:WinMainCRTStartup
 /BAS:4194304 /A:512  hwprint.LNK
 Error: C:\TEMP\HWPRINT\hwprint.OBJ(hwprint)  (15693456): Symbol
 Undefined _PrintDlgA 4
 Lines Processed: 124510  Errors: 1  Warnings: 0
 Build failed

 So I assumed I had to include the comdlg32.lib library. I checked the
 "Embed Library Named:" option, added comdlg32.lib and rebuilt all, but
 I still get the following errors:

 sc hwprint.cpp -mn -C -WA -S -NLcomdlg32.lib -3 -a8 -c -gf
 -ohwprint.obj
 link /CO /NOI /DE /NOPACKF /XN /NT /ENTRY:WinMainCRTStartup
 /BAS:4194304 /A:512  hwprint.LNK
 Error: No Match Found for Export/ENTRY -  : WinMainCRTStartup
 Error: C:\TEMP\HWPRINT\hwprint.OBJ(hwprint)  : Symbol Undefined
 __acrtused
 Error: C:\TEMP\HWPRINT\hwprint.OBJ(hwprint)  : Symbol Undefined
 _memset
 Lines Processed: 124510  Errors: 3  Warnings: 0
 Build failed

 What am I doing wrong? Please help...

 Here's hwprint.cpp:

 /*********************************************************************
  *
  * hwprint.cpp by Tom Lee
  *
  * Example program to demonstrate printing using the Win32 API/GDI.
  * I'm new to printing with the Win32 GDI myself (although I've
  * used the GDI heaps before for gfx etc.) - I've been
  * trying for a long time to find useful info on the Internet
  * about this very thing, but came across next to nothing.
  * I thought it'd be a disservice to the Internet not to get
  * something about printing with Win32/GDI out the door ASAP!
  *
  * -------------------------------------------------------------------
  *
  * Libraries to link in:
  *
  *      kernel32.lib, user32.lib, gdi32.lib, comdlg32.lib
  *
  ********************************************************************/
 #include <windows.h>

 int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine,
 int nCmdShow )
 {
         PRINTDLG pd;

         memset( &pd, 0, sizeof( pd ) );

         pd.lStructSize = sizeof( pd );

         /*
          * get rid of PD_RETURNDEFAULT on the line below if you'd like
 to
          * see the "Printer Settings" dialog!
          *
          */
         pd.Flags = PD_RETURNDEFAULT | PD_RETURNDC;

         // try to retrieve the printer DC
         if( !PrintDlg( &pd ) )
         {
                 MessageBox( NULL, "PrintDlg( &pd ) failed!", "Fatal
 Error", MB_OK | MB_ICONERROR );

                 return -1;
         }

         DOCINFO di;
         HDC hPrinter = pd.hDC;

         // initialization of the printing!
         memset( &di, 0, sizeof( di ) );
         di.cbSize = sizeof( di );
         StartDoc( hPrinter, &di );

                 // start the first and only page
                 StartPage( hPrinter );

                 // uncomment the following line to print in colour! :)
                 SetTextColor( hPrinter, 0x0000FF );

                 // write "Hello, World!" to the printer's DC
                 TextOut( hPrinter, 100, 100, "Hello World!", 13);

                 // finish the first page
                 EndPage( hPrinter );

         // end this document and release the printer's DC
         EndDoc( hPrinter );
         DeleteDC( hPrinter );
         return 0;
 }

Feb 08 2002
parent reply Alexis Golzman <agolzman ciudad.com.ar> writes:
I think you will need a .DEF file with:

NAME            "Name"
DESCRIPTION     'Descriptiuon'
EXETYPE         NT
SUBSYSTEM       WINDOWS,4.0
STUB            'WINSTUB.EXE'
CODE             EXECUTE READ
DATA             READ WRITE
STACKSIZE       1048576,4096
HEAPSIZE        1048576,4096

No, I guess it must be something else, these are the contents of my .DEF file: NAME "hwprint" DESCRIPTION 'hwprint' EXETYPE NT SUBSYSTEM WINDOWS STUB 'WINSTUB.EXE' CODE EXECUTE READ DATA READ WRITE STACKSIZE 1048576,4096 HEAPSIZE 1048576,4096
You need to include the .DEF file on the link command line.

How? Isn't it included already?
Next is seems like for some reason the linker has trouble finding memset.
This might be solved by including the required header files and making
sure the linker can find the libraries.

memset is in stdlib.h, but #include <stdlib.h> Doesn't solve anything. What's the correct way to include a lib file in a project? Why doesn't it compile hwprint.cpp? I would hate to use an old pirate version of some commercial compiler instead of DMC. So please help...
Feb 08 2002
parent reply Jan Knepper <jan smartsoft.cc> writes:
Actually, I tried to compile the program with
sc -mn <file>.cpp gdi32.lib comdlg32.lib
And it compiled just fine.

What do you have in your sc.ini???

Jan



Alexis Golzman wrote:

I think you will need a .DEF file with:

NAME            "Name"
DESCRIPTION     'Descriptiuon'
EXETYPE         NT
SUBSYSTEM       WINDOWS,4.0
STUB            'WINSTUB.EXE'
CODE             EXECUTE READ
DATA             READ WRITE
STACKSIZE       1048576,4096
HEAPSIZE        1048576,4096

No, I guess it must be something else, these are the contents of my .DEF file: NAME "hwprint" DESCRIPTION 'hwprint' EXETYPE NT SUBSYSTEM WINDOWS STUB 'WINSTUB.EXE' CODE EXECUTE READ DATA READ WRITE STACKSIZE 1048576,4096 HEAPSIZE 1048576,4096
You need to include the .DEF file on the link command line.

How? Isn't it included already?
Next is seems like for some reason the linker has trouble finding memset.
This might be solved by including the required header files and making
sure the linker can find the libraries.

memset is in stdlib.h, but #include <stdlib.h> Doesn't solve anything. What's the correct way to include a lib file in a project? Why doesn't it compile hwprint.cpp? I would hate to use an old pirate version of some commercial compiler instead of DMC. So please help...

Feb 08 2002
parent reply Alexis Golzman <agolzman ciudad.com.ar> writes:
Actually, I tried to compile the program with
sc -mn <file>.cpp gdi32.lib comdlg32.lib
And it compiled just fine.

I'll try that too, let's see what happens.
What do you have in your sc.ini???

[Version] version=7.51 Build 020 [Environment] PATH=%PATH% BIN=C:\PROGTO~1\DM\BIN INCLUDE=C:\PROGTO~1\DM\INCLUDE;C:\PROGTO~1\DM\MFC\INCLUDE;C:\PROGTO~1\DM\MFC\INCLUDE\32-BIT;C:\PROGTO~1\DM\INCLUDE\WIN32;%INCLUDE% LIB=C:\PROGTO~1\DM\LIB;C:\PROGTO~1\DM\MFC\LIB;%LIB% HELP="% P%\..\help" DMC is in c:\progtools\dm\ in my computer.
Feb 08 2002
parent reply Jan Knepper <jan smartsoft.cc> writes:
Ouch!

Try to install DMC in a directory other than "C:\Program Files" or any other
long file name!
I have heard too many problems with that!
Or... If you want to keep it that way.. Map a drive (subst) to the DMC
directory such as
subst s: c:\PROGTO~1\DM
And than change SC.INI to reflect S:\ instead of C:\PROGTO~1\

Jan



Alexis Golzman wrote:

Actually, I tried to compile the program with
sc -mn <file>.cpp gdi32.lib comdlg32.lib
And it compiled just fine.

I'll try that too, let's see what happens.
What do you have in your sc.ini???

[Version] version=7.51 Build 020 [Environment] PATH=%PATH% BIN=C:\PROGTO~1\DM\BIN INCLUDE=C:\PROGTO~1\DM\INCLUDE;C:\PROGTO~1\DM\MFC\INCLUDE;C:\PROGTO~1\DM\MFC\INCLUDE\32-BIT;C:\PROGTO~1\DM\INCLUDE\WIN32;%INCLUDE% LIB=C:\PROGTO~1\DM\LIB;C:\PROGTO~1\DM\MFC\LIB;%LIB% HELP="% P%\..\help" DMC is in c:\progtools\dm\ in my computer.

Feb 08 2002
parent Alexis Golzman <agolzman ciudad.com.ar> writes:
Ouch!

Try to install DMC in a directory other than "C:\Program Files" or any other
long file name!
I have heard too many problems with that!
Or... If you want to keep it that way.. Map a drive (subst) to the DMC
directory such as
subst s: c:\PROGTO~1\DM
And than change SC.INI to reflect S:\ instead of C:\PROGTO~1\

Jan

That wasn't the problem. The command line you gave me worked just fine. So I noticed that when you create a new project, two files appear: <filename>.cpp <filename>.DEF I first thought I had to add comdlg32.lib in the options dialog ("Code Generation" -> "Embed Library Named"). But I just had to add the necessary .lib files as another source file, just as I added hwprint.cpp to the project. That was all! Ooph... Thanks for your help! :oD
Feb 08 2002