|
-
July 21st, 2010, 01:45 PM
#1
[RESOLVED] Access violation (VS2008, VC++ & MFC)
Hi everyone, i'm having a very strange and annoying issue on a code i'm working on, i've tried a lot of things but none of them has worked so any help will be greatly appreciated.
Here's the problem:
I'm coding a framework for using custom controls, with the ability of using skin files packed inside a zip file and using xml for the skin definition. I've created some base classes to implement a 'skinned' dialog (wich doesn't seem to give any problem) and another to encapsulate a custom control: this handles painting, responds to mouse/keyboard/focus events and provides the basic skinning support, so i can create a derived class and, by overriding its procedures, receive events and so on.
I've coded label, textbox and button controls to use this framework; the label works without any problem, getting the colors from the skin file. The textbox is a plain window that shows an EDIT window inside when clicked, only the container has painting support, but i can't create two textbox controls on the same dialog or i end up getting an 'Access violation' exception. The button is a 5-state bitmapped control with simple caption, works ok, but has a very strange bug: it has a CRect member (m_rcMargins) to clip drawing and i can't change it or i get an 'Access Violation' too.
The members of the CSkinButton class are:
...
class CSkinButton: public CSkinCtrl {
protected:
CString m_szUIDefId;
COLORREF m_crForeColor;
COLORREF m_crBackColor;
BOOL m_bAutoSize;
UINT m_uStyle;
CRect m_rcMargins;
...
As you can see, none of them are dynamically allocated, so an Access violation doesn't make any sense when trying to modify them from inside the same class code:
...
BOOL CSkinButton::OnSkinChanged()
{
if (m_uStyle == 1)
{
m_uBltMode = 5;
m_pSkin->GetThemeBitmap(_T("button"), _T("background"), m_bmBkgnd);
m_rcMargins.SetRect(3,3,3,3); // This generates an exception!!!
}
...
The control is not dinamically declared on the CDialog-based container, so there isn't any dinamically-allocated memory there, and i'm getting an exception...
There is also another strange thing: I've shuffled the variable positions inside the CSkinButton class declaration because m_uStyle was giving me the same problem, and it was solved by changing its position.
I don't know what's wrong with my code, i've checked everything, i doesn't use any strcpy's or another function that may lead to heap corruption, i'm not using dynamic arrays, but i'm getting those access violations and some 'heap around the variable is corrupted' messages when changing the code.
I'm using zlib, minizip and tinyxml in static libraries, so i don't think they could be causing the problem. There are two projects also: the controls library (static lib) and the test app (exe), i'm working with both of them on a single VS solution, the project dependencies are OK, compiler settings, etc.
I don't want to have to re-write the entire library, but i don't know what to do.
Please help me
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|