• Advertisement
Sign in to follow this  

cant attach CDC?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am not sure what I am doing wrong but it causes an exception. HDC dc = NULL; CDC* pdC = NULL; dc = GetDC(hWnd); pdC->Attach(dc); *Exception* I know hWnd is good, I use it in the same class to load an image before entering here, and the value is the same. thanks, Matt

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Code Is Your Friend
I am not sure what I am doing wrong but it causes an exception.

HDC dc = NULL;
CDC* pdC = NULL;

dc = GetDC(hWnd);
pdC->Attach(dc); *Exception*

I know hWnd is good, I use it in the same class to load an image before entering here, and the value is the same.

thanks,
Matt
At no point in that code do you initialise pdC. You probably want to do:

CDC dc = GetDC(hWnd);

Share this post


Link to post
Share on other sites
That works, but it creates a problem. It only works if the CDC isn't a pointer. And I need it to be a pointer for the next function called, so I either need to convert it to a CDC* somehow, or get the pointer to accept the dc.

Matt

[Edited by - Code Is Your Friend on January 15, 2009 9:35:00 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Code Is Your Friend
Still having problems with this, I have tried everything I can think of to get the CDC* to take a dc.

Is there just no way to do this?
Matt
No - a CDC* is a pointer to a CDC that already exists. You need to initialise the pointer before you use it.

Quote:
Original post by Code Is Your Friend
That works, but it creates a problem. It only works if the CDC isn't a pointer. And I need it to be a pointer for the next function called, so I either need to convert it to a CDC* somehow, or get the pointer to accept the dc.
What function? Can't you just use &dc?:

CDC dc = GetDC(hWnd);
SomeFuncThatTakesPointerToCDC(&dc);



Or:

CDC* pDC = new CDC;
pDC->Attach(GetDC(hWnd));
SomeFuncThatTakesPointerToCDC(pDC);

// When you're done with pDC:
delete pDC;


I doubt you need it to be a pointer though.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement