|
Thats what I thought, but does this mean then that the HIMAGELIST handle is left floating around?
Wouldn't this waste or cause memory leaks of any kind or are these objects destroyed when your application ends?
I'm curious basically becuz I have 2 functions, one which initializes an CImageList by attaching it to the system HIMAGELIST returned by SHGetFileinfo , but before attaching I always do a Detach . I figure I would be a bad idea to Destroy() this image list? I do however Detach again in destructor. My second function doesn't use the system image list but rather initializes it with icons I have collected. So I Destroy , then Create and Destroy() again inside destructor.
In MFC I've always assumed that destructor took care of everything?
Thanks
The word of the day is legs, let's go back to my house and spread the word
|
|
|
|
|
Hockey wrote:
but does this mean then that the HIMAGELIST handle is left floating around?
Yes, but...
Hockey wrote:
Wouldn't this waste or cause memory leaks of any kind or are these objects destroyed when your application ends?
No, because when your process exits, all memory and resources it was using go away too (memory gets reclaimed by the OS). However, it's still good practice to not be sloppy, and properly free/destroy/delete resources in your cleanup code.
If you want a class that destroys the image list in the destructor, check out this page[^]
--Mike--
Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber
Pinky, are you pondering what I'm pondering?
I think so Brain, but if we shaved our heads, we'd look like weasels!
|
|
|
|
|
although most WTL classes take care of releasing the object they manage (if they manage it), CImageList is a sore exception. I guess it is not an ideal world! Perhaps it is because imagelists have window semantics and as "windows" you need to destroy them manually
To answer your question, yes you should destroy all imagelists you create yourself, ideally at the moment you no longer require them. However the "system" imagelist returned by SHGetFileInfo is a shared resource which you needn't (shouldn't in 9x) destroy
most of the other WTL classes have a managed and unmanaged "flavor". E.g. you have CBitmap and CBitmapHandle; the first is managed, destroying the bitmap whenever it goes out of scope, the second is meant for temporary assignments.
|
|
|
|
|
I created a rich edit control with ES_MULTILINE | ES_WANTRETURN in CComCompositeControl dialog.
I am able to edit text but pressing Enter key has no effect.
|
|
|
|
|
I need to implement drag & drop feature support to composite control. My Composite Control contains Tree control and list view controls, i need to drag the list view control data and drop into the Tree view control. Please send me some samples and necessary information to implement the same.
|
|
|
|
|
Hi everybody
My problem related to ini file using map. i have solve this problem using vector.in vector i used two structures one for keys and second for section.i want to it compatible with map. i m confused to how insert section and its key using map. plz help me to solve this problem.
// st_key
// This structure stores the definition of a key. A key is a named identifier
// that is associated with a value. It may or may not have a comment. All comments
// must PRECEDE the key on the line in the config file.
//header file using vector
typedef struct st_key
{
t_Str szKey;
t_Str szValue;
t_Str szComment;
st_key()
{
szKey = t_Str("");
szValue = t_Str("");
szComment = t_Str("");
}
} t_Key;
typedef std::vector<t_key> KeyList;
typedef KeyList::iterator KeyItor;
// st_section
// This structure stores the definition of a section. A section contains any number
// of keys (see st_keys), and may or may not have a comment. Like keys, all
// comments must precede the section.
typedef struct st_section
{
t_Str szName;
t_Str szComment;
KeyList Keys;
st_section()
{
szName = t_Str("");
szComment = t_Str("");
Keys.clear();
}
} t_Section;
typedef std::vector<t_section> SectionList;
typedef SectionList::iterator SectionItor;
/// General Purpose Utility Functions ///////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
void Report(e_DebugLevel DebugLevel, char *fmt, ...);
t_Str GetNextWord(t_Str& CommandLine);
int CompareNoCase(t_Str str1, t_Str str2);
void Trim(t_Str& szStr);
int WriteLn(fstream& stream, char* fmt, ...);
/// Class Definitions ///////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
// CDataFile
class CDataFile
{
// Methods
public:
// Constructors & Destructors
/////////////////////////////////////////////////////////////////
CDataFile();
CDataFile(t_Str szFileName);
virtual ~CDataFile();
// File handling methods
/////////////////////////////////////////////////////////////////
bool Load(t_Str szFileName);
bool Save();
// Data handling methods
/////////////////////////////////////////////////////////////////
// GetValue: Our default access method. Returns the raw t_Str value
// Note that this returns keys specific to the given section only.
t_Str GetValue(t_Str szKey, t_Str szSection = t_Str(""));
// GetString: Returns the value as a t_Str
t_Str GetString(t_Str szKey, t_Str szSection = t_Str(""));
// GetFloat: Return the value as a float
float GetFloat(t_Str szKey, t_Str szSection = t_Str(""));
// GetInt: Return the value as an int
int GetInt(t_Str szKey, t_Str szSection = t_Str(""));
// GetBool: Return the value as a bool
bool GetBool(t_Str szKey, t_Str szSection = t_Str(""));
// SetValue: Sets the value of a given key. Will create the
// key if it is not found and AUTOCREATE_KEYS is active.
bool SetValue(t_Str szKey, t_Str szValue,
t_Str szComment = t_Str(""), t_Str szSection = t_Str(""));
// SetFloat: Sets the value of a given key. Will create the
// key if it is not found and AUTOCREATE_KEYS is active.
bool SetFloat(t_Str szKey, float fValue,
t_Str szComment = t_Str(""), t_Str szSection = t_Str(""));
// SetInt: Sets the value of a given key. Will create the
// key if it is not found and AUTOCREATE_KEYS is active.
bool SetInt(t_Str szKey, int nValue,
t_Str szComment = t_Str(""), t_Str szSection = t_Str(""));
// SetBool: Sets the value of a given key. Will create the
// key if it is not found and AUTOCREATE_KEYS is active.
bool SetBool(t_Str szKey, bool bValue,
t_Str szComment = t_Str(""), t_Str szSection = t_Str(""));
// Sets the comment for a given key.
bool SetKeyComment(t_Str szKey, t_Str szComment, t_Str szSection = t_Str(""));
// Sets the comment for a given section
bool SetSectionComment(t_Str szSection, t_Str szComment);
// DeleteKey: Deletes a given key from a specific section
bool DeleteKey(t_Str szKey, t_Str szFromSection = t_Str(""));
// DeleteSection: Deletes a given section.
bool DeleteSection(t_Str szSection);
// Key/Section handling methods
/////////////////////////////////////////////////////////////////
// CreateKey: Creates a new key in the requested section. The
// Section will be created if it does not exist and the
// AUTOCREATE_SECTIONS bit is set.
bool CreateKey(t_Str szKey, t_Str szValue,
t_Str szComment = t_Str(""), t_Str szSection = t_Str(""));
// CreateSection: Creates the new section if it does not allready
// exist. Section is created with no keys.
bool CreateSection(t_Str szSection, t_Str szComment = t_Str(""));
// CreateSection: Creates the new section if it does not allready
// exist, and copies the keys passed into it into the new section.
bool CreateSection(t_Str szSection, t_Str szComment, KeyList Keys);
// Utility Methods
/////////////////////////////////////////////////////////////////
// SectionCount: Returns the number of valid sections in the database.
int SectionCount();
// KeyCount: Returns the total number of keys, across all sections.
int KeyCount();
// Clear: Initializes the member variables to their default states
void Clear();
// SetFileName: For use when creating the object by hand
// initializes the file name so that it can be later saved.
void SetFileName(t_Str szFileName);
// CommentStr
// Parses a string into a proper comment token/comment.
t_Str CommentStr(t_Str szComment);
protected:
// GetKey: Returns the requested key (if found) from the requested
// Section. Returns NULL otherwise.
t_Key* GetKey(t_Str szKey, t_Str szSection);
// GetSection: Returns the requested section (if found), NULL otherwise.
t_Section* GetSection(t_Str szSection);
// Data
public:
t_Section* GetSectionName( t_Str SectionName);
long m_Flags; // Our settings flags.
protected:
SectionList m_Sections; // Our list of sections
t_Str m_szFileName; // The filename to write to
bool m_bDirty; // Tracks whether or not data has changed.
};
thanks
fefgfgfgfgfg
|
|
|
|
|
Hi:
I´m trying to use WTL in an AX control. With previous ATL version you just needed to change CComModule to CAppModule. But now that CComModule was splitted this doesn´t work anymore.
What else should i change???
Thanks
Gabriel
Old C programmers never die. They just cast into void
|
|
|
|
|
I have a class like this that wraps the webbrowser
template <typename T><br />
class IEHost : public IDispEventSimpleImpl<1, IEHost<T>, &__uuidof(DWebBrowserEvents2)><br />
{<br />
...<br />
BEGIN_SINK_MAP(IEHost)<br />
SINK_ENTRY_INFO(1, __uuidof(DWebBrowserEvents2), 259, DocumentComplete, &DocumentCompleteInfo)<br />
SINK_ENTRY_INFO(1, __uuidof(DWebBrowserEvents2), 250, BeforeNavigate2, &BeforeNavigate2Info)<br />
SINK_ENTRY_INFO(1, __uuidof(DWebBrowserEvents2), 102, StatusTextChange, &StatusTextChangeInfo)<br />
END_SINK_MAP()<br />
...<br />
}
And an atl dialog class that uses it
class StartDlg : public CAxDialogImpl<StartDlg> ,<br />
public CStrDlg<StartDlg>,<br />
public CDialogResize<StartDlg>,<br />
public IEHost<StartDlg><br />
{<br />
}
This compiled fine with VC6, but with VC7
i get this error.
I tried all i can think of to get it to compile but with no luck.
Anyone knows how to get it to work in VC7
c:\Program Files\Microsoft Visual Studio .NET\Vc7\atlmfc\include\atlcom.h(4016): error C2440: 'initializing' : cannot convert from 'const ATL::_ATL_EVENT_ENTRY<T> *' to 'const ATL::_ATL_EVENT_ENTRY<T> *'<br />
with<br />
[<br />
T=IEHost<StartDlg><br />
]<br />
and<br />
[<br />
T=StartDlg<br />
]
/Magnus
- I don't necessarily agree with everything I say
|
|
|
|
|
Don't know, I don't have all info, but just wild shot - try:
<br />
template <typename T><br />
class IEHost : public IDispEventSimpleImpl<1, T, &__uuidof(DWebBrowserEvents2)><br />
{<br />
...<br />
BEGIN_SINK_MAP(T)<br />
...<br />
}<br />
Then it should at least compile
|
|
|
|
|
No, dont compile then either, i get 21 errors on the BEGIN_SINK_MAP/SINK_ENTRY_INFO macros.
Tried changing those params every way that seems somewhat resonable with no luck.
/Magnus
- I don't necessarily agree with everything I say
|
|
|
|
|
_Magnus_ wrote:
BEGIN_SINK_MAP(IEHost)
That should probably be BEGIN_SINK_MAP(IEHost<T> )
--Mike--
Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber
There is a saying in statistics that a million monkeys pounding on typewriters would eventually create a work of Shakespeare. Thanks to the Internet, we now know that this is not true.
|
|
|
|
|
No, that dont make any difference.
Found what it was, ATL7 have added an AdviseEventSink() call in
OnInitdialog() so i got sinked from the wrong class.
Should be possible to get a callstack on the freakin template errors..
/Magnus
- I don't necessarily agree with everything I say
|
|
|
|
|
Hi,
The ActiveX control may be used in several occasions simultaneously within one process, but all the control instances are the same one. This is not what I expected,
I think there is some wrong with the project setup, but I do not no where. Can you give me some advice.
Thanks in advance!
|
|
|
|
|
Never heard about - they reside in the same dll (of course) that is loaded once to the process = they share the static parts and global variables , but the instances are always created by the new operator using the class factory.
Only think you can do is to change the class factory from standard to some singletone implementation, but this cannot be done accidentally or through some project setting AFAIK...
Can you be more specific?
|
|
|
|
|
I have some wise of the problem,it is because I implemented all the interfaces in the header file.
And there is another question, can I restrict the sharing
of the global variables?
Tnank you!
|
|
|
|
|
Sorry for delay, I had to travel a bit.
Hmm, only way how to restrict sharing of global variables is to... well... make them non-global
|
|
|
|
|
Say I have a COM object that I want to create inside a library, modify something internally and then pass it on to something externally would the folling seem an okay thing to do in ATL:
IThingy *pIThingy NULL;
HRESULT hr = CThingy::CreateInstance(IID_IThingy, &pIThingy);
if(SUCCEEDED(hr))
{
CThingy *pThingy = dynamic_cast<CThingy*>(pIThingy);
if(pThingy)
{
pThingy->SomeInternalMemberFunction();
}
}
What I'm worried about is casting from an interface pointer to the internal class. Is this okay, or if not why?
It works, most of the time, but when you enable things like #define _ATL_DEBUG_INTERFACES in stdafx.h, then the address acrording to the this pointer internaly to the CThingy instance no longer matches pIThingy that is returned from CreateInstance. Very worrying. Seems to be offset by about 8 bytes.
|
|
|
|
|
Doing such things is in total violation of COM and will not work properly.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
You're going down the inheritance tree (IThingy to CThingy ) which puts the responsibility on you to make sure it's safe. If you go the other way, up the tree, it's always safe by C++ language rules:
CComObject<CThingy>* pThingy;
if ( FAILED( CComObject<CThingy>::CreateInstance ( &pThingy ) ))
return NULL;
pThingy->AddRef();
pThingy->SomeInternalStuff();
return (IThingy*) pThingy; CComObject is the most-derived class, derived from CThingy , which is derived from IThingy .
--Mike--
Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber
Kosh reminded me of some of the prima-donna programmers I've worked with. Knew everything but when you asked them a question; never gave you a straight answer.
-- Michael P. Butler in the Lounge
|
|
|
|
|
|
I think it is best we use the QueryInterface() for that.
I also have a question for you guys. How about the reverse? If I already have a pointer to the interface, how can I safely cast it back to the ATL COM class?
I have tried this:
CComObject<cthingy>* pThingy = (CComObject<cthingy>*)pItfThingy;
But the address of the class pThingy is moved back 4 bytes from the original adress, plus the addresses of the internal member variables are skipped one ahead?
It is great if you can help me out here. Thanks in advance.
Trong
Trong
|
|
|
|
|
Hi,
My urgent requirement is to implement Stacked Dialog using ATL/VC++6.0 windowing classes. The implementation is similar to MFC's whcih is provided in the Codeguru site. Can any body tell me how to implement it? Sample code would be greatly helpful.
Thanks,
Sai.
Help Ever, Hurt Never
|
|
|
|
|
I would like my control being able to disply an image such as an icon or a bitmap taking this image directly from the resources of its container, if they are available. Furthermore I would like to give the opportunity of selecting the image at the design time....
The problem is I have been able to access only the resource of the OCX but not those of the container
coul you help me to work it out with this?
thank you
Rob
Or just tell me that this is not possible at all at least!
|
|
|
|
|
An ATL simple object of mathematic stuctures and functions,need overload operator to give facilties to user.
|
|
|
|
|
How to gray checkbox in tree control (from WTL).
|
|
|
|
|