Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - CXTButton crashes
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

CXTButton crashes

 Post Reply Post Reply
Author
Message
rock View Drop Down
Groupie
Groupie


Joined: 27 October 2005
Status: Offline
Points: 19
Post Options Post Options   Thanks (0) Thanks(0)   Quote rock Quote  Post ReplyReply Direct Link To This Post Topic: CXTButton crashes
    Posted: 09 November 2005 at 2:46pm

I have discoved that if I try to use more than one CXTButton in any of my dialog box classes, my application will crash inside of XTPImageManager.cpp in the CXTPImageManagerIconHandle::IsEmpty() function.

I've also found out that if I try to use a CXTButton in a CView derived class, I get an assertion error when calling CXTButton::SetIcon() when the function SAFE_DELETE(m_pIcon) is called.  The code I use is similar to what I found in the Explorer GUI sample:

myheader file:

CImageList m_ilButton:

CXTButton m_addBtn;

my cpp file:

m_ilButton.Create(XT_IDB_BTN_OUT, 16, 1, RGB(255,0,255));

if (m_btnAdd.Create(NULL, WS_VISIBLE | BS_ICON | BS_OWNERDRAW | BS_CENTER | BS_VCENTER, CRect(0,0,0,0), this, IDC_BTN_CREATE))

{

m_btnAdd.SetIcon(CSize(16, 15), m_ilButton.ExtractIcon(2));

m_btnAdd.SetTheme(xtThemeDefault);

m_btnAdd.SetXButtonStyle(BS_XT_WINXP_COMPAT);

}

I added a watch to m_btnAdd.m_pIcon and it is NULL before I enter SetIcon(), but then once I'm into the CXTButton code it is no longer NULL.  I've tried increasing the application stack size but there is no difference, it still crashes.  Have I missed something obvious.  I'm using Visual Studio 2003.

Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 10 November 2005 at 3:16am

Do you have standard structure package - 8?

Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
rock View Drop Down
Groupie
Groupie


Joined: 27 October 2005
Status: Offline
Points: 19
Post Options Post Options   Thanks (0) Thanks(0)   Quote rock Quote  Post ReplyReply Direct Link To This Post Posted: 10 November 2005 at 8:29am
That thought did occur to me after I got away from working on it and was able to think about it.  And no, our app has it set to 1.  Unfortunately the engine dll for our app requires us to have structure package set to 1.   Is there any harm in recompiling the CodeJock libraries with the setting at 1 instead of 8?
Back to Top
rock View Drop Down
Groupie
Groupie


Joined: 27 October 2005
Status: Offline
Points: 19
Post Options Post Options   Thanks (0) Thanks(0)   Quote rock Quote  Post ReplyReply Direct Link To This Post Posted: 10 November 2005 at 10:32am

A simplier soultion that works fine rather than recompile the CodeJock libraries was for me to add the following to my stdafx.h file

#pragma pack(push, 8)

#include <XTToolkitPro.h> // Xtreme Toolkit Pro component library

#pragma pack(pop)

Back to Top
jigarmehtamscit View Drop Down
Groupie
Groupie
Avatar

Joined: 29 October 2005
Location: India
Status: Offline
Points: 64
Post Options Post Options   Thanks (0) Thanks(0)   Quote jigarmehtamscit Quote  Post ReplyReply Direct Link To This Post Posted: 10 November 2005 at 3:19pm
Hi rock,

can you please explain what these statements does ?? And how this solves the problem ?
Regards,
Jigar Mehta
Back to Top
rock View Drop Down
Groupie
Groupie


Joined: 27 October 2005
Status: Offline
Points: 19
Post Options Post Options   Thanks (0) Thanks(0)   Quote rock Quote  Post ReplyReply Direct Link To This Post Posted: 11 November 2005 at 9:06am

Jigar,

I'll do my best to explain.  The "Struct Member Alignment" option in the C++ Code Generation section of the project properties tells the compiler how to pack the members of structures in memory based on byte boundries.

My application has this set to 1 byte.  While the default for Visual Studio apps is set to 8; which is also what the XTreme libraries are set to.  Passing data between 2 sets of code with different settings could cause memory corruption.

The #pragma pack(push, 8)  tells the compiler to use 8 byte alignment for any code following that statement.  In this case the XTreme Toolkit libs.  Then #pragma pack(pop) just restores the orignal setting (in my case 1 byte alignment) for the remainder of the code or until another #pragma or other instruction is encountered.  With these statements, any data passed to the XTreme Libs uses 8 byte alignment while the rest of my code uses 1 byte (I hope)

I'm neither a teacher or an expert, but I hope this helps.

Back to Top
jigarmehtamscit View Drop Down
Groupie
Groupie
Avatar

Joined: 29 October 2005
Location: India
Status: Offline
Points: 64
Post Options Post Options   Thanks (0) Thanks(0)   Quote jigarmehtamscit Quote  Post ReplyReply Direct Link To This Post Posted: 11 November 2005 at 2:09pm
perfect rock.. you are a good teacher indeed..

I understood it well..

But one question that arise in my mind that, if a structure object that is passed to xtreme libs as we as used by your application.. so, how will that be packed ?? will that on the fly change the packing type ? (I dont think that would be the way..)

And what I understood by your answer is,

If we want to have our data to be differently aligned for some snippet of code, we need to pack that snippet accordingly by the statement,

#pragma
pack(push, X)

Tell me if i am wrong anywhere..

Thx for the valuable information..
Regards,
Jigar Mehta
Back to Top
rock View Drop Down
Groupie
Groupie


Joined: 27 October 2005
Status: Offline
Points: 19
Post Options Post Options   Thanks (0) Thanks(0)   Quote rock Quote  Post ReplyReply Direct Link To This Post Posted: 11 November 2005 at 3:51pm

It would be my understanding that the different byte alignment would only apply to the functions within the scope of the #pragma statements.

You are right about the #pragma pack(push, X) statements

This link might also provide more information:

http://msdn.microsoft.com/library/default.asp?url=/library/e n-us/vccore/html/_core_.2f.zp.asp

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.027 seconds.