Probably simple problem w/ RECT members

This is a discussion on Probably simple problem w/ RECT members within the Windows Programming forums, part of the Platform Specific Boards category; I'm trying to do what I thought would be as straightforward a task as there can be. All I want ...

  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,789

    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, 09:49 AM
  3. Fairly simple problem
    By fatdunky in forum C Programming
    Replies: 1
    Last Post: 11-14-2005, 10:34 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. Simple? winsock client - server problem
    By knutso in forum Windows Programming
    Replies: 2
    Last Post: 03-26-2003, 03:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21