Thread: Probably simple problem w/ RECT members

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    35

    Probably simple problem w/ RECT members

    I'm trying to do what I thought would be as straightforward a task as there can be.

    All I want to do is set up a bunch of RECT objects to use in a DrawText call.

    But for some reason my program crashes, and this crash seems to have to do with assigning values to the RECT structures.

    I'm not a C person so I don't use structures too often. And I've only been programming C++ for a few months. So here's the code:

    Code:
    RECT *rctHeading;
    RECT *rctBody;
    RECT *rctFooter;
    
       rctHeading->left=0;
       rctHeading->top=0;
       rctHeading->right=639;
       rctHeading->bottom=60;
       rctBody->left=40;
       rctBody->top=80;
       rctBody->right=599;
       rctBody->bottom=449;
       rctFooter->left=0;
       rctFooter->top=460;
       rctFooter->right=639;
       rctFooter->bottom=479;
    When I comment out the assignments the program works fine. What am I doing wrong?

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793

    Re: Probably simple problem w/ RECT members

    RECT *rctHeading; is a pointer....and if you dont assign a pointer to something, and then try dereference it, you'll be lucky not to crash

    You could do;

    RECT *rctHeading = new RECT;

    that would allocate memory for the pointer to point to

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    35
    Gotcha.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A simple file I/O problem
    By eecoder in forum C Programming
    Replies: 10
    Last Post: 10-16-2010, 11:00 PM
  2. Simple File I/O problem
    By Ignited in forum C++ Programming
    Replies: 3
    Last Post: 01-07-2006, 10:49 AM
  3. Fairly simple problem
    By fatdunky in forum C Programming
    Replies: 1
    Last Post: 11-14-2005, 11:34 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. Simple? winsock client - server problem
    By knutso in forum Windows Programming
    Replies: 2
    Last Post: 03-26-2003, 04:51 AM