Thread: CPen error!!!

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    42

    CPen error!!!

    I used the following code in my Paint program

    Code:
    switch (flag)
    	{
    		case 1:
    			//drawing freehand
    			CPen *penBlack,*newpen;  // Construct it, then initialize
                  if( newpen->CreatePen( PS_DOT, 2, RGB(255,0,0) ) )
                   {
                     // Select it into the device context
                     // Save the old pen at the same time
    				   penBlack = pDC->GetCurrentPen();
    				   pDC->SelectObject( newpen );
                   
    			if (nFlags && MK_LBUTTON)
    				{
    			    pDC->MoveTo (OldPoint.x, OldPoint.y);
    				pDC->LineTo (point.x,point.y);
    				}
    				// Restore the old pen to the device context
                    pDC->SelectObject( penBlack );
    			   }
                    break;
    In fact a good deal of it is from http://msdn.microsoft.com/library/de...ce_context.asp
    But although it compiles fine, when i try to run it, it gives me the following error message

    The instruction [-some number-] read memory address [0x....] which could not be read.

    What does this mean ???

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    148
    Code:
    CPen *penBlack,*newpen;  // Construct it, then initialize
     if( newpen->CreatePen( PS_DOT, 2, RGB(255,0,0) ) )
    You say it,but you don't do it.
    newPen points to nirvana,and the CPen Object is not constructed.
    You have to call new on it
    Code:
    newPen = new CPen(... //Don't know which parameter

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  3. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM