RTTI...? and MFC...?
-
First the RTTI question. How is it possible to create an object without using MFC's CObject
CreateObject()
...??? I checked out the source code (MFC) and could only determine CreateObject returns a Function*...??? Could someone please explain how I can accomplish similar code using plain old platform independent C++...??? Can I do this using RTTI...??? Second question. I have asked this question before, but obviously didn't get it so i'll ask again... How does MFC wrap a Windows window HWND with a class and avoid using global or static functions...??? Are they fancy MACROS...? if so where do I find these...??? Thanx! :) "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr -
First the RTTI question. How is it possible to create an object without using MFC's CObject
CreateObject()
...??? I checked out the source code (MFC) and could only determine CreateObject returns a Function*...??? Could someone please explain how I can accomplish similar code using plain old platform independent C++...??? Can I do this using RTTI...??? Second question. I have asked this question before, but obviously didn't get it so i'll ask again... How does MFC wrap a Windows window HWND with a class and avoid using global or static functions...??? Are they fancy MACROS...? if so where do I find these...??? Thanx! :) "An expert is someone who has made all the mistakes in his or her field" - Niels Bohrfor the second question: you can have a look for winamp3.0 client src; this is free. u can get it form it's site, just use a defwindowproc and in this function use getwindowlong to get extra data, then we can do all the things we want.
-
First the RTTI question. How is it possible to create an object without using MFC's CObject
CreateObject()
...??? I checked out the source code (MFC) and could only determine CreateObject returns a Function*...??? Could someone please explain how I can accomplish similar code using plain old platform independent C++...??? Can I do this using RTTI...??? Second question. I have asked this question before, but obviously didn't get it so i'll ask again... How does MFC wrap a Windows window HWND with a class and avoid using global or static functions...??? Are they fancy MACROS...? if so where do I find these...??? Thanx! :) "An expert is someone who has made all the mistakes in his or her field" - Niels BohrHockey wrote: How is it possible to create an object without using MFC's CObject CreateObject()...??? Sure. Just use 'new CYourObject' or declare CYourObject as local/global variable. CreateObject stuff is needed, because framework needs to create objects of 'unknown' type. For example, if you have doc/view app, MFC creates CYourDoc and CYourView for you, but doesn't have full knowledge about these classes. You're just passing the RUNTIME_CLASS which, among other things, has the CreateObject method. Hockey wrote: I checked out the source code (MFC) and could only determine CreateObject returns a Function*...??? No, CRuntimeClass::CreateObject returns CObject *. There's also m_pfnCreateObject data member which has an address to function which is called by CreateObject. Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
-
First the RTTI question. How is it possible to create an object without using MFC's CObject
CreateObject()
...??? I checked out the source code (MFC) and could only determine CreateObject returns a Function*...??? Could someone please explain how I can accomplish similar code using plain old platform independent C++...??? Can I do this using RTTI...??? Second question. I have asked this question before, but obviously didn't get it so i'll ask again... How does MFC wrap a Windows window HWND with a class and avoid using global or static functions...??? Are they fancy MACROS...? if so where do I find these...??? Thanx! :) "An expert is someone who has made all the mistakes in his or her field" - Niels Bohrq1: Are you talking about dynamically creating an object at runtime? q2. I think the answer to this is in MFC's Handle Maps. Have a look at CWnd::FromHandle() Neville Franks, Author of ED for Windows. www.getsoft.com
-
Hockey wrote: How is it possible to create an object without using MFC's CObject CreateObject()...??? Sure. Just use 'new CYourObject' or declare CYourObject as local/global variable. CreateObject stuff is needed, because framework needs to create objects of 'unknown' type. For example, if you have doc/view app, MFC creates CYourDoc and CYourView for you, but doesn't have full knowledge about these classes. You're just passing the RUNTIME_CLASS which, among other things, has the CreateObject method. Hockey wrote: I checked out the source code (MFC) and could only determine CreateObject returns a Function*...??? No, CRuntimeClass::CreateObject returns CObject *. There's also m_pfnCreateObject data member which has an address to function which is called by CreateObject. Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
Tomasz Sowinski wrote: Sure. Just use 'new CYourObject' This i knew...but I want to replicate MFC
CObjects
ability to create objects at runtime usingCreateObject
...? Like the DOC/VIEW in MFC, but I can't use MFC because I want to make my code cross platform...??? I did a little more reading an it turns out this isn't accomplished via RTTI...so i'm lost as to where to look... I serach on google for objects dynamically and everything returnsCObject* pObject = new CObject;
Which is not exactly what I wanted to know... I what I want to accomplish not dynamic creation...? Cheers :) "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
-
for the second question: you can have a look for winamp3.0 client src; this is free. u can get it form it's site, just use a defwindowproc and in this function use getwindowlong to get extra data, then we can do all the things we want.
ttzzgg_80713 wrote: just use a defwindowproc and in this function use getwindowlong to get extra data, then we can do all the things we want. Is that how the MFC framework implements this...? How would you handle messages, would you hook the object...? Thanx "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
-
q1: Are you talking about dynamically creating an object at runtime? q2. I think the answer to this is in MFC's Handle Maps. Have a look at CWnd::FromHandle() Neville Franks, Author of ED for Windows. www.getsoft.com
Neville Franks wrote: q1: Are you talking about dynamically creating an object at runtime? Yes I think...but NOT using
new/delete
using something similar to MFCCObject
but I can't use this method because I want to keep my code cross platform. RUNTIME_CLASS macro takes a class and dynamically creates objects...I need this kinda functionality But without MFC... How is this accomplished...??? Thanx :) "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr -
Tomasz Sowinski wrote: Sure. Just use 'new CYourObject' This i knew...but I want to replicate MFC
CObjects
ability to create objects at runtime usingCreateObject
...? Like the DOC/VIEW in MFC, but I can't use MFC because I want to make my code cross platform...??? I did a little more reading an it turns out this isn't accomplished via RTTI...so i'm lost as to where to look... I serach on google for objects dynamically and everything returnsCObject* pObject = new CObject;
Which is not exactly what I wanted to know... I what I want to accomplish not dynamic creation...? Cheers :) "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
Hockey wrote: I did a little more reading an it turns out this isn't accomplished via RTTI... Well, it isn't accomplished with C++ RTTI (dynamic_cast, typeid, typeinfo). MFC has its own RTTI invented before VC had support for C++ RTTI. Hockey wrote: I what I want to accomplish not dynamic creation...? I'm not sure what do you mean here. If you want to get universal method for creating objects based on class name, you may find this article useful: http://www.microsoft.com/msj/defaulttop.asp?page=/msj/archive/S385.htm[^] The article is titled 'Roll Your Own Persistence Implementations to Go Beyond the MFC Frontier', but dynamic creation is the base for serialization. Any reading which takes on 'factory' design pattern may also give you additional understanding of this subject. Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
-
Hockey wrote: I did a little more reading an it turns out this isn't accomplished via RTTI... Well, it isn't accomplished with C++ RTTI (dynamic_cast, typeid, typeinfo). MFC has its own RTTI invented before VC had support for C++ RTTI. Hockey wrote: I what I want to accomplish not dynamic creation...? I'm not sure what do you mean here. If you want to get universal method for creating objects based on class name, you may find this article useful: http://www.microsoft.com/msj/defaulttop.asp?page=/msj/archive/S385.htm[^] The article is titled 'Roll Your Own Persistence Implementations to Go Beyond the MFC Frontier', but dynamic creation is the base for serialization. Any reading which takes on 'factory' design pattern may also give you additional understanding of this subject. Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
Tomasz Sowinski wrote: I'm not sure what do you mean here MFC DOC/VIEW uses a form of dynamic creation when instantiating the CView/CDoc derived classes however the dynamic creation is based on the new/delete operators...??? It uses a different method in creating objects dynamically...?? It is this method I wish to learn about...not the plain jane new and delete methods... Thanx for the URL...i'll check it out... Cheers! "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
-
Tomasz Sowinski wrote: I'm not sure what do you mean here MFC DOC/VIEW uses a form of dynamic creation when instantiating the CView/CDoc derived classes however the dynamic creation is based on the new/delete operators...??? It uses a different method in creating objects dynamically...?? It is this method I wish to learn about...not the plain jane new and delete methods... Thanx for the URL...i'll check it out... Cheers! "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
Hockey wrote: MFC DOC/VIEW uses a form of dynamic creation when instantiating the CView/CDoc derived classes however the dynamic creation is based on the new/delete operators...??? In the MFC slang, 'dynamic creation' is creation of object on heap given a class name (class name as a string) at runtime. However, deep inside, it always boils down to some 'new CYourObject' in your code. The MFC magic works with macros. Basically, if you mark CYourObject with DECLARE_DYNCREATE/IMPLEMENT_DYNCREATE will have corresponding function which calls 'new CYourObject'. This function (along with class name) is hooked into list of available factory functions. Implementation of factory function is done for you by - guess what - IMPLEMENT_DYNCREATE. So, you can look at the 'dynamic creation' problem like this: having a string with class name like 'CYourObject', you have to find a function which will call 'new CYourObject'. Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
-
Neville Franks wrote: q1: Are you talking about dynamically creating an object at runtime? Yes I think...but NOT using
new/delete
using something similar to MFCCObject
but I can't use this method because I want to keep my code cross platform. RUNTIME_CLASS macro takes a class and dynamically creates objects...I need this kinda functionality But without MFC... How is this accomplished...??? Thanx :) "An expert is someone who has made all the mistakes in his or her field" - Niels BohrDo a search on Google for stuff like "RTTI dynamic objects/creation", "C++ Persistance" etc. Also see what the various cross-platform libraries do to handle this. It might be a good idea to post another question here stating what you are trying to achieve and asking people how they would go about. Dynamic creation of objects isn't something you need to do very often. Neville Franks, Author of ED for Windows. www.getsoft.com