Print Page | Close Window

CXTButton crashes

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=3191
Printed Date: 20 June 2025 at 5:52pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: CXTButton crashes
Posted By: rock
Subject: CXTButton crashes
Date 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.




Replies:
Posted By: Oleg
Date Posted: 10 November 2005 at 3:16am

Do you have standard structure package - 8?



-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: rock
Date 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?


Posted By: rock
Date 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)



Posted By: jigarmehtamscit
Date 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


Posted By: rock
Date 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.



Posted By: jigarmehtamscit
Date 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


Posted By: rock
Date 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




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net