|
Maybe you noticed another thread a started a few lines down about a bug in my code, where I called delete on a pointer I shouldn't have. I have decided the best way to approach the problem is to copy the memory rather than return the pointer itself. Much the same as many of the standard api functions do. So I'm basicaly creating a function like:
GetRegionData( LPRGNDATA, DWORD dwSize )
And as you can guess, the first call with a NULL pointer should return the size required.
It's no big deal, I just added a new member to the class, but I was wondering if there was a similar method to _msize() in C.
|
|
|
|
|
WalderMort wrote: It's no big deal, I just added a new member to the class...
I suppose if it gets out of hand (you have so many LPRGNDATA/dwRgnSize pairs) you could write
a little wrapper class that encapsulates the pointer and the size.
|
|
|
|
|
I thought of that, in my instance though it's not really warrented. I did however try subclassing the RGNDATA struct adding a new DWORD dwSize member, but due to the layout of the origional struct the new member is overwritten as soon as the RECT's are written.
|
|
|
|
|
I have not done a lot of work with regions, but is that information not available in the RGNDATAHEADER?
Otherwise, I am not aware of such a function as I have never had the need for one.
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
PJ Arends wrote: but is that information not available in the RGNDATAHEADER
no, the data header states the number of rectangles in the struct, from which the size can again be calculated, but not the size itself. Like I said though, it's no big deal.
|
|
|
|
|
Ok, so the data is there, just not in the convenient form that you would like to see.
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
yeah. I was hoping for something like sizeof() which would guarantee the allocated size. Calculating it from the data within the struct could lead to problems if the data was deleted or incorrect.
And once again, your 'Image Viewer' is making my life easier I just re-coded a lot of my region creating functions only to find the output is not what I expected. My first thought was "$%^&# I calculated the rectangles wrong", so fire up the old viewer, and guess what, the regions are perfect. Without your work I would have spent all night tearing my functions apart trying to find the fault, at least now I know where not to look. Thankyou
|
|
|
|
|
WalderMort wrote: Thankyou
Hey, I am just glad that someone finds that little app useful.:->
WalderMort wrote: My first thought was "$%^&# I calculated the rectangles wrong", so fire up the old viewer, and guess what, the regions are perfect. Without your work I would have spent all night tearing my functions apart trying to find the fault, at least now I know where not to look.
And now you know exactly why I wrote it to begin with. Been there, done that
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
Well I found the problem ( a region being inverted when it no longer needs to be ). I still say you should sell it, even if you sell the development rights, it's a great tool and I'm sure many coders would benefit from it.
|
|
|
|
|
You know the size when you do the alloc. If you need to keep that size around for later use, then you have to store it somewhere.
An alternative is to use a vector of bytes:
vector<BYTE> vec(1000);
RGNDATA* pData = (RGNDATA*) &vec[0];
vector<BYTE>::size_type cbyBuffer = vec.size();
|
|
|
|
|
WalderMort wrote: Why is it that C has a whole bunch of other functions like calloc(), realloc() and _msize()? The latter is what pains me today.
C is a pain
WalderMort wrote: Most of you will say to use a vector,
Yes...
WalderMort wrote: For example I need to allocate space for a RGNDATA struct which is a little more than a simple array. Allocating the space is no problem, but how is it possible to later find out how much memory was allocated? In C a call to _msize() would do the job, but experience tells me not to mix C and C++ when it comes to memory.
The way that classes like vector do it is to store the size in a variable, I am sure.
WalderMort wrote: Is there a way to do this other than storing the size when it was allocated?
There are tricks with sizeof that I've seen used, such as sizeof(x)/sizeof(char) for the size of a char array. But, I'd be inclined to use vector, the address of item [0] is the address of the whole array. Or, write your own class to handle it.
Christian Graus - C++ MVP
|
|
|
|
|
WalderMort wrote: Allocating the space is no problem, but how is it possible to later find out how much memory was allocated?
This *might* work:
int *x = new int[345];
printf("You allocated %lu bytes\n", *((unsigned long *) x - 4));
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I am making a SDI application.In that when a user click a tool bar button a dialog box opens up in that user have to fill sum values n then he has to press save button ...
what i want to do is when user click on save button that particular dialog box s'ld colse down n the values from that dialog box should go in list ctrl made in sdi application
I m not getting the way to it..may be post message or send message is helpful in it but i do not knw how to use them
can anyone help in this
thanxs
|
|
|
|
|
Hi,
Actually, you'd use PostMessage if your dlg were modeless.
Probably not. The save button closes the dlg, but after that you hold the C++ object of that dlg. So you can retrieve the entered values from the dlg and pass them to the list ctrl;
<br />
CMyDlg dlg;<br />
if (IDOK == dlg.DoModal())<br />
{
CString val1 = dlg.m_val1;<br />
<br />
m_list.Add (val1);
}
--
======
Arman
|
|
|
|
|
After adding ATL Aupport to MRFC application, then i added ATL COM object ,but this object is not registering.... how can i register?
|
|
|
|
|
kiranin wrote: After adding ATL Aupport to MRFC application, then i added ATL COM object ,but this object is not registering.... how can i register?
what error is it giving~
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
no error, just it cant registered in registry, for example when i add context menu items to textfiles it cannot displayed when create through MFC. Now what i want is how can i register ATL COM object in MFC Application
|
|
|
|
|
how can i Add context menu item through MFC Application,
i saw many examples, in all examples context menu item is added through ATL COM wizard,
but my application is MFC, when i launch my application context menu item will be added .
|
|
|
|
|
kiranin wrote: i saw many examples, in all examples context menu item is added through ATL COM wizard,
but my application is MFC, when i launch my application context menu item will be added .
Handle OnLButtonDown Message and generate your own context menu there
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
i want to add shell context menu item to explorer not to my application items.
|
|
|
|
|
I think I saw examples of this object on codeproject did you search?
|
|
|
|
|
|
Hi all.
In my application I am calling a SHGetFolderLocation() function to load a browse Folder dialog.
I have included Shlobj.h and also I have added shell32.lib file in
Project->Settings->Lib tab.
The version of shell32.dll is 6.0.2900.2180.
But when I tried to compile a program, it gives me a compile time error
" error C2065: 'SHGetFolderLocation' : undeclared identifier "
Can anybody help?
Thanks
Rakesh Thakur
|
|
|
|
|
Try to#define _WIN32_IE 0x0500
|
|
|
|
|
Thanks for reply.
I tried adding #define _WIN32_IE 0x0500
but didn't worked-out.
Thanks
Rakesh Thakur
|
|
|
|