|
I was in good old Chapters the other day I picked up one of the Stroustrup series books and read up a little on the topic, but I did not have time to finish. Does any one know of a good web site that explains the concepts behind implementing the visitor concept?
Thanks,
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
|
Sweet! thanks a bunch Tomasz!
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
Whats the difference....
(char*) blah
char* blah
|
|
|
|
|
(char*) blah is a C style cast - its telling the complier to treat the expression blah as a pointer to char.
char* blah is a declaration of blah, or possibly just an argument type if used in the decl of a function argument.
|
|
|
|
|
I've got a project here that's supposed to open a custom-formatted text file (its just a record file delimited with the | (pipe) symbol) and I'm having the darnedest trouble trying to figure out how to open it, work with the CArchive, and assign values to the variables I already have.
I know this is easy, but I don't know enough MFC/STL to do this. I generated a project with the MFC AppWiz (SDI, no database support), so I've got standard Wizard-generated code to work with. It'll be easiest if someone has example code for me, because I am totally at a loss.
|
|
|
|
|
Say goodbye to CArchive. If your program has a custom format, you need to override OnOpenDocument and OnSaveDocument in your CDocument-derived class. Use stdio's FILE, MFC's CFile, STL's iostream or Windows API to read/write file contents - CArchive will not help here.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
I had a practice DOS version of this program running, using fstream, but unfortunately, the read/write operations are slow. In the Windows version I'm writing now, I'd like to have immediate response when moving back and forth between records.
Will fstream be more responsive in Windows than it was in DOS, or can I expect the same delay when it reads/writes the disk? I'm assuming it'll be as slow, because fstream isn't buffered like CArchive/CFile.
Right now I'm reading Leo Moll's Property Sheet View article. It looks like it can help me out. I think I'm missing a lot more information than just working with the file I/O.
|
|
|
|
|
Is fstream the usual way how people do file IO. In my case I wanted to save a string to a file. I didnt know whether htis should go into a CArchive object. in fact I havent got a clue when it comes to CArchive and serialisation. It seems a complicated subject.... Can I put strings/ints etc into archives and then pass them to serialize()
thanks in advance
|
|
|
|
|
If you're using MFC, just (typing from memory here, not pasting - so excuse any typos -the help for CFile::Write has examples I believe)
-----
CFile savestring;
savestring.Open("Myfile.txt", CFile::modeWrite);
size = myString.getLength()+1; //use whatever you need. Not sure if buffer rqd.
savestirng.Write( myString.getBuffer(size), size);
savestring.Close();
If you have a format for the line, you can just as easily write out your storage class in the 'Write'.
CArchive seemed like more of a hassle than just writing things out myself - I messed with it for awhile but had problems with the arrangement of the various macros for Implement_Dynamic and whatnot.
--Mark Terrano
www.ensemblestudios.com
(Creators of the Age of Empires series)
|
|
|
|
|
template < template < class TYPE > class COORD >
class vector : public COORD
{
public:
TYPE& operator[]( const int nIndex )
{
return ( ( TYPE *) this[ nIndex] );
}
};
|
|
|
|
|
|
Infinite recursion... the subscript operator (I think that’s what its called) calls itself over and over again...
BTW: Are you using the STL's? I don’t think you should be using ‘vector’ as a class name (unless you've wrapped it all in a common namespace).
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
I think I find what is the problem.
The problem become from VC++ which doesn't support nested templates.
|
|
|
|
|
> The problem become from VC++ which doesn't support nested templates.
sure it does, how would the STL work? All the iterators declared within the class that they apply to. e.g. vector::iterator.
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
> The problem become from VC++ which doesn't support
> nested templates.
Hmmm... Are you simply trying to derive vector from template class COORD?
If yes, it should look like this:
template <class T>
class vector : public COORD<T>
{
// vector members here
};
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
The problem is that I want different Dimension Coords
template < typename TYPE >
struct Coord3
{
TYPE x;
TYPE y;
TYPE z;
typedef TYPE TYPE_NAME;
};
template < typename TYPE >
struct Coord4
{
TYPE x;
TYPE y;
TYPE z;
TYPE w;
typedef TYPE TYPE_NAME;
};
template < class dimention >
class vector : public dimention
{
private:
typedef dimention::TYPE_NAME TYPE;
TYPE& operator[]( const int nIndex )
{
ASSERT( 0 >= nIndex && nIndex < sizeof(this ) / sizeof( TYPE ) );
return ( ( TYPE *) this)[ nIndex ];
};
};
typedef vector< Coord3< float > > vector3f;
typedef vector< Coord4< float > > vector4f;
|
|
|
|
|
> The problem is that I want different Dimension Coords
> [...]
> typedef vector< Coord3< float > > vector3f
So where's the problem related to nested templates?
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
Hey,
I have a WTL MDI project and i search to implement Drag&drop.
Is it possible ??
Thanks,
Ptit Seb
|
|
|
|
|
WTL does not have any drag&drop support built-in.
There is a DragImg sample on the Platform SDK that may help if you are trying to get items onto the OLE clipboard:
Samples\WinUI\Shell\DragImg
For other WTL questions, in the future you may want to try the WTL newsgroup:
http://egroups.yahoo.com/group/wtl
|
|
|
|
|
I am encountering a problem when I try to append to the end of a CString, specifically in unicode. I can append several times, but it seems that there is some sort of limit to how long a CString can be? After I "+=" up to about 167 characters, it no longer displays the additional characters, yet continues to increase the size when I call GetLength(). Any ideas on what is going on?
|
|
|
|
|
What function are you using for output? Maybe it's ANSI variant and 167th character contains zero?
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
I found the problem. Important lesson: make sure you _T() EVERY literal and not just some, or in this case, all but one.
Thanks
|
|
|
|
|
Hi,
I previously posted a thread to ask how it is possible to detect that an application is launched.
Indeed I don't want to detect that a *particular* program is launched, but to detect that an application (not a specific one) has been launch.
This can allow to have a sleeping process that wakes-up only each time an application is launched, do something, then goes back sleeping.
This way the "monitoring" process does not consume CPU by always checking if there is something new among the list of the process.
--Francois
|
|
|
|
|
Seems that you need a global hook DLL. Windows will map your DLL into memory space of every process in the system, so you'll be able to detect new processes right after launching them - DllMain of hook DLL will receive DLL_PROCESS_ATTACH as dwReason. This should work on Win9X and NT.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|