Public Group

Can't set RECT values?

This topic is 4889 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I have RECT* srcRectBg; declared in the private scope of a class. In the constructor's implementation, I have srcRectBg->left = 0; and it gives me an access violation. What the crap?

Share on other sites
The member itself is nothing but a pointer, are you sure it's been allocated properly (i.e. is pointing to valid data)?

Share on other sites
Hmm, I added srcRectBg = new Rectangle(0,0,0,640,480) above srcRectBg->left = 0;

Now I'm getting 100+ errors on the next piece of code in the exact same place?! This stuff compiled just fine before adding in the allocation.

Share on other sites
That does sound strange (your second post). Post some of your code. si it just that you wrote Rectungle instead of RECT?

One thing I would avoid is unnecessary use of memory allocation. Im almost 100% sure that you do NOT need to in your case.

Functions such as SetRect are misleading someitmes. They take a RECT* as a parameter, but that should not persuede you to declare your RECTS as pointers then allocate their memeory. Do this:

RECT rec;

SetRect( &rec,....);

Share on other sites
Rectangle? According to MSDN there's a Rectangle function at least but I can't find any matching type, especially not any inheriting from RECT.
If it really needs be allocated dynamically then shouldn't you allocate a RECT instead, and what's the fifth parameter supposed to do?

Share on other sites
Quote:
 Original post by doynaxRectangle? According to MSDN there's a Rectangle function at least but I can't find any matching type, especially not any inheriting from RECT.If it really needs be allocated dynamically then shouldn't you allocate a RECT instead, and what's the fifth parameter supposed to do?

Damn it, i tried rating you up to 1337, but barely missed....

Share on other sites
int myfunc{    RECT* srcRectBg;    srcRectBg = new Rectangle(0,0,0,640,480);}

isnt it supposed to be "srcRectBg = new RECT(...)" or sumthing like that?

Share on other sites
I don't think it's really necessary to dynamically allocated this structure. And, heh, I was calling Rectangle(HDC,left,...). It's not even related to what I'm doing. ;) I'm just gonna declare a RECT variable and not a pointer.

Share on other sites
And I get this error when doing srcRectBg = new RECT(0,0,640,480);

error C2661: 'tagRECT::tagRECT' : no overloaded function takes 4 parameters

Share on other sites
Quote:
 Original post by POLSKASHAnd I get this error when doing srcRectBg = new RECT(0,0,640,480);
The RECT structure doesn't have any constructor. Try simply allocating it instead.
srcRectBg = new RECT;

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 14
• 9
• 9
• 9
• 10
• Forum Statistics

• Total Topics
632912
• Total Posts
3009199
• Who's Online (See full list)

There are no registered users currently online

×