|
Remember that the address of an object (an instance of a class) is just a 32-bit value. Those can be stored and cast accordingly.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
First of all, let me take a shot at answering your little quiz (at the end of your post) about those birds sitting on a fence. How many are left? The answer is FIVE!! because three only decided to fly off. They actually didn't do it.
With regards to my question, your answer is pretty much the same as storing the addresses as type "void" and then re-cast them back to their original type. That is exactly what I had noted (but held back from using that approach because of something better I believe can be achieved).
Specifically, I'm thinking along the line of templates and some ingenuity.
Thanks anyway for your reply.
William
Fortes in fide et opere!
|
|
|
|
|
Templates, boost and STL can provide a type safe solution, but it still isn't perfect.
std::vector< boost::any >
may be what you're looking for. Boost::any uses three classes.
1/ Wrapper class, which stores a pointer to a 2
2/ Abstract implementation class
3/ Concrete template class which extends 2
You still need to use any_cast to retrieve your data, but it effectively only a static_cast, much better than using void*'s
It's worth looking into the theory behind boost::any because you may be able to avoid the use of the any_cast / static_cast if you roll your own with careful modifications to all of the classes.
I've spent a fair bit of time looking at exactly this type of problem and come up with no really satisfying solution. My context was with regards to data pipelining arbitrary data types between 'transforms'. I was trying to provide a generic system easy to use by the less experienced. The real problem when I dug down further was that relationships between our classes (cohesion / coupling) were causing delays in development because of long compile times. My advice? Consider your requirements very carefully - Why are you trying to write this code? What other tools or alternatives do you have - since then we've started looking at weakly typed scripting for rapid development.
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
Even if the individual classes where dirived from the same virtual base class you would still probably needed to eventualy re-cast any object object with aditional functionality
to the original type.
According to what you have written I would write a function to handle each of the possible individule class types stored in the array and cast the pointer base on the class id, or in your case class name, and pass it to the function designed to handle it.
If all the classes are related in some fundiment way then you should should create a base class common to all of them. For example: If your array is just used to draw a GUI object then you could use multiple inheritance (or not) with one of the base classes only containing a Draw() function that must be difine in all inherited casses, then you will not have to re-cast any of the pointers to retrieved from the array.
But if none of the classes has any thing in common then why would they be in the same array. That would not make since and you would have no choice but to re-cast them.
INTP
|
|
|
|
|
Thanks for your reply.
This is what I've come up with so far, and it pretty much gives an idea of the direction in which I'm heading.
template<typename T1>
struct MyStruct
{
typedef pair<string, T1<big>&</big>> CLASSINFO;
string className;
static CLASSINFO make_pair <string clsName, const T1<big>&</big> clsRef>
};
typedef int (*PF)(MyStruct<big>&</big> mySt); The compiler complained about, "use of class template requires template argument list". What is it that I'm missing?
typedef int (*PF)(MyStruct<T1><big>&</big> mySt); The proper "#include" statements are present.
Thanks.
William
Fortes in fide et opere!
|
|
|
|
|
How do i get folder path with CFiledialog? I know if I call the GetPathName()
It will return the Full path to specific folder. but in order to close the CFileDialog i have to click on either Save or Open.
Thanks
Shin
|
|
|
|
|
sdfdsfa wrote:
but in order to close the CFileDialog i have to click on either Save or Open.
Which is the whole reason for using CFileDialog in the first place. It sounds like you want to use SHBrowseForFolder() instead.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Thanks David,
I downloaded the sample program for SHBrowserForFolder() from codeproject.
That was it.
Thank you very much.
Shin
|
|
|
|
|
I have a CFormView with buttons in it. My application is a tic-tac-toe application, i would like to save the game before it is completed and be able to open it. how do i serialize it?
|
|
|
|
|
Search CP and MSDN for examples of serialization. Basically, the document object holds the state of the game. When the game is altered in any way (e.g., a move is made), the document should be marked as "dirty." Then when the game is exited, the document's Serialize() method will get called. It's at that point that you'll write to the CArchive object.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
See is how you are using CFormView I assume that you have a document class assotiated with it.
1) Open you document class and find Serialize().
2) if( ar.IsStoring() )
{
ar.Write(...);
}
else
{
ar.Read(...);
}
With a little effort and reasearch in MSDN you should have not problem.
P.S. This looks like a college assignment I had once add (accept in 'C' not MS 'C++').
After you get complete the assignment and get a grade, please send be a copy and I'll send you one of my versions (C,C++,VB), there are only to possibilies 1) possible and imposseble to beat.
INTP
|
|
|
|
|
Hello!
I have written small app in VC.NET and tried to run it on Win98. It complains about oleacc.dll. How to get rid of this dll from my app??
Anybody knows?
Please help
|
|
|
|
|
You have to delay the loading of the oleacc.dll file. By doing this, the dll will only get loaded if your app requires it, not automatically when your app starts.
1.) Link to delayimp.lib
#pragma comment (lib, "delayimp.lib")
2.) use the /DELAYLOAD:oleacc.dll linker option
Project
+-- Properties
+-- Linker
+-- Input
+-- Delay Loaded DLLs -> oleacc.dll
3.) use the /DELAY:UNLOAD linker option
Project
+-- Properties
+-- Linker
+-- Advanced
+-- Delay Loaded DLL -> Support Unload (/DELAY:UNLOAD)
Version 7.0 of Dev Studio
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Hello!
I didn't look correctly. Oleacc.dll is not loaded by me by explicit. It is loaded by shell32.dll. It is present on WinXP, but not on clean installation of Win98 secont edition.
Anyone knows sth about this horror dll?
Thanks for help!
|
|
|
|
|
|
called from here:
#include "file1.h"
func.cpp
{
AF_TXT_FILE = OPEN_AIRFIELD_TXT_FILE(FILENAME);
}
file1.ccp
FILE * OPEN_AIRFIELD_TXT_FILE(char *FILENAME)
{
//function here
}
file1.h
FILE * OPEN_AIRFIELD_TXT_FILE(char *FILENAME);
Here is the ERROR:
error LNK2001: unresolved external symbol "struct _iobuf * __cdecl OPEN_AIRFIELD_TXT_FILE(char *)" (?OPEN_AIRFIELD_TXT_FILE@@YAPAU_iobuf@@PAD@Z)
I hope this make sense as I've took out a lot of code and makde up short names and such.
|
|
|
|
|
Just guessing, but is file1.cpp part of the project and if not, does it compile with no errors in whatever project it is in? If it is in a separate project, do you link with the .lib or .o file produced in that project?
Chris Meech
It's much easier to get rich telling people what they want to hear. Chistopher Duncan
But for a man, barbecuing eggplant and portobello mushrooms is a sure way to have people question your sexual orientation. Kuro5hin
|
|
|
|
|
I have a dialog based application. The main dialog contains a tab control and several child dialogs, one per tab on the tab control. (The child dialogs are children of the main dialog, not of the tab control.) When a tab is selected, I hide the currently visible child dialog, move the child dialog associated with the newly selected tab so that it immediately follows the tab control in the Z-order, and make the newly selected child dialog visible.
This all seems to work fine, except sometimes list controls in the child dialogs disappear. I say they disappear, because they do get drawn, but are immediately erased. If I start clicking on portions of the list control, pieces of it will be drawn. For example, if I click on an item, the item will be drawn. If I click on a scroll bar, the scroll bar will get drawn.
Any ideas?
--------
There are 10 types of people in this world. Those who know binary and those who don't.
|
|
|
|
|
I had that problem too: Back then I've figured out that the reason for that behaviour was screwed up message pump: WM_PAINT from dialog becoming visible was getting processed before WM_ERASEBACKGROUND of hidden one is getting processed -- both containing same screen device context.
The only solution I came up with back then was: instead of playing with Z-order and visibility -- I was just moving window that becomes "invisible" somewhere to Hawaii without changing visibility, while moving "visible" one to the right position.
Another side effect as I recall right now was: if you use IE WebBrowser window as your property window and change it visibility to not-visible -- it's getting destroyed -- therefore moving technique in my case was the only appropriate solution...
Regards
"...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..."
Me
|
|
|
|
|
Thanks for the response.
I actually found the apparent "what was causing this", but I still don't understand the "why". I had a call to SetFocus that was setting the focus to the list control (before it would have been painted). Removing this SetFocus call appears to have solved the problem.
I had used Spy++ to look at the WM_PAINT and WM_ERASEBKGND messages. In agreement with your posting, the order of messages didn't make much sense and would fairly clearly cause the problem I experienced.
If anyone has any insight on the "why" of this problem, curiosity is killing this cat.
--------
There are 10 types of people in this world. Those who know binary and those who don't.
|
|
|
|
|
Where was SetFocus() being called from?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
It was being called after I was done adjusting the visibility and Z-order of the child dialogs but before the message pump was allowed to run. I'm pretty sure it was the last thing to happen before returning to the message pump.
--------
There are 10 types of people in this world. Those who know binary and those who don't.
|
|
|
|
|
i need to be able to load a bitmap and let the user split it up into multiple parts and save the parts to files but i don't know how to split it up... or do the saving...
the user just sets the rows across and down then the program cuts up the bitmap into pieces and save them to a folder...
thanks,
-Slim
*SlimGradey*
|
|
|
|
|
Spilling a bitmap into multiple parts is the easy part, so I'll address that.
If you are going to spilt the bitmap into equal parts then it is simply a matter of creating 1 bitmap for each part and then blitting from the origanal to the new bitmap.
Example:
(0,0) (100,0) (200,0)
+-----------+-----------+
| | |
| part 1 | part 2 |
| | |
(0,100) +-----------+-----------+ (200, 100)
| | |
| part 3 | part 4 |
| | |
(0,200) +-----------+-----------+ (200,200)
1) Create compatible bitmap 1 (100, 100)
part1.blit(0,0,100,100,hdcSource,0,0)
2) Create compatible bitmap 2 (100, 100)
part2.blit(0,0,100,100,hdcSource,100,0);
3) Create compatible bitmap 3 (100, 100)
part3.blit(0,0,100,100,hdcSource,0,100);
4) Create compatible bitmap 4 (100, 100)
part4.blit(0,0,100,100,hdcSource,100,100);
Now you have 4 bitmaps that only contain a part of the origanal.
The trick is saving them to disk!
You can start with by searching for dibsection (and GetDIBits()) in MSDN and at codeproject, codeguru, and sourceforceforge. To use dibsection (or GetDIBit()) you will need to use CBitmap:Bitmap() or ::GetObject(pBmp,sizeof(BITMAP)) and do some calculations in order to figure out what the BITMAPFILEHEADER and BITMAPINFOHEADER will need to contain in order to save the file.
Note: GetDIBits() is your best bet. All you need to to do is create a BITMAPINFOHEADER and pass it to GetDIBits() let it fill in the BITMAPINFOHEADER for you, then let it calculate the amount of storage needed for the image (pixel bits) then call it again to retrieve the image. Then create the BITMAPFILEHEADER and write the results to disk. In reality it's a bit more complicated, but a search of MSDN and the WEB should ease you burdon.
I leave the rest up to you! Search MSDN on how to use GetDIBits().
INTP
|
|
|
|
|
How do i handle events for a Cbutton object created at run time ? Are there many ways of doing this ?
|
|
|
|