|
Hi!
Can anyone pls help me with this problem. I need to test my activex control in a very simple atl application. So I would really appreciate it if anyone here could be so kind to post code that I can use to test the control in ATL.
I basically just needs to be able to call one of the controls methods and write the returning value out to console for example!!
Thank you in advance!
|
|
|
|
|
Can't you use the MS ActiveX Test Container application (tstcon32.exe) that ships with Visual Studio? Check in the Microsoft Visual Studio Common7\Tools folder.
|
|
|
|
|
Thx for your time!
I know the control is working in the test container AND in MFC applications, but it has been reported that it doesnt work properly in ATL applications, which I find strange. Therefore I wanted to create a simple atl project and see if could reproduce the problem or not!
Thanks
|
|
|
|
|
Hi,
I've encountered decent issue with validity of CWndClassInfo structure of ATL's CWindowImpl. Suppose following scenario:
1. There is a control class derived from ATL's CWindowImpl and rich edit (available via RichEdit20.dll)
2. This control is instantiated - RichEdit20.dll is loaded, CWndClassInfo gets initialized (this time only, as a static content of our class), control gets created
3. Control is destroyed and the dll gets unloaded.
4. Control is instantiated again - dll gets loaded again, to different base address this time. No reinitialization of CWndClassInfo occurs, as it is static and 'valid' from last time.
5. Application crashes as it tries to use rich edit's window procedure (through CWndClassInfo, containing outdated information)
I 'solved' this by clearing m_atom member of CWndClassInfo explicitely; in such case CWndClassInfo gets reinitialized in #4. My knowledge of ATL is fairly limited, but I don't expect this to be correct solution, of course.
Where is the problem here? Should I invalidate the CWndClassInfo in some 'standard way'? Or should the dll not get unloaded at all?
Thx. for any hints
|
|
|
|
|
Howdy! I have been learning C++ and windows programming with MFC since I got canned from my mainframe job last year. I had bought the COM and ATL 3.0 book years ago, and decided to read it a few weeks ago. However, I get to chapter 9 and see that the stuff covered has been redesigned with ATL 7.0. There is only one book out there written since 3.0 that covers 8.0. I have VS pro 2005, so I could continue to learn ATL 8.
But I am unsure if it is worth it for me to learn ATL/COM now, or if I should dive into C# and .NET, which I know nothing about, but have just bought some books on for .NET 2.0. Does the lack of books on the "older" technologies, like MFC, ATL, and COM mean that they are perhaps only supported by legacy systems, and potential employers would be more likely to want .NET experience?
What to do?
Thanks.
|
|
|
|
|
I should add that I have been learning DirectX, and writing a 3D modeler in C++/MFC, and was thinking of learning ATL/COM to separate the loading of models from various file formats, and support a plug-in capability (though I know nothing about this).
|
|
|
|
|
Probably not worth making the effort to learn ATL/COM now.
CPP_Student wrote: Does the lack of books on the "older" technologies, like MFC, ATL, and COM mean that they are perhaps only supported by legacy systems
Pretty much - unless you're writing e.g., the next version of MS Office or something!
CPP_Student wrote: and potential employers would be more likely to want .NET experience?
Yes.
Put it this way, whether or not you should learn ATL/COM you'll definitely need to learn .NET as well. So at the least you would have to learn both. My guess is that while you will continue to see requirements for C++ and even ATL/COM in the Windows world it will be increasingly combined with a requirement for .NET.
Kevin
|
|
|
|
|
That makes sense! Thank you.
I just want to be sure I learn something really well rather than a bunch of things a little bit. But, every job offering lists a different set of requirements. So, I want to concentrate on the harder ones (like .NET) and learn the easier stuff (like SOAP and many other accronyms) on the job.
-- modified at 13:55 Monday 31st July, 2006
|
|
|
|
|
CPP_Student wrote: Howdy! I have been learning C++ and windows programming with MFC since I got canned from my mainframe job last year. I had bought the COM and ATL 3.0 book years ago, and decided to read it a few weeks ago. However, I get to chapter 9 and see that the stuff covered has been redesigned with ATL 7.0. There is only one book out there written since 3.0 that covers 8.0. I have VS pro 2005, so I could continue to learn ATL 8.
I would at least finish reading the ATL 3.0 book first. The reason is simple: in many of the new books, they refer to "this has been changed from version 3.0 ... and this is why." If you have at least a mild understanding of the way things were, you will gain and understanding of why they changed it and what may have to be changed in systems that are upgrading their libraries. From experience, that is a popular interview question.
CPP_Student wrote: But I am unsure if it is worth it for me to learn ATL/COM now, or if I should dive into C# and .NET, which I know nothing about, but have just bought some books on for .NET 2.0. Does the lack of books on the "older" technologies, like MFC, ATL, and COM mean that they are perhaps only supported by legacy systems, and potential employers would be more likely to want .NET experience?
Don't let the mass flooding of the bookshelves at Barnes and Noble with all the books on .Net convince you that MFC, ATL, COM, STL, etc are out of date. As it stands right now, .Net is a very small segment of the programming jobs available (and for the most part, among the lowest paying positions as well). If you understand the fundamentals, you won't have any problems answering interview questions dealing with general programming nor .Net specific stuff (though, generally it is a bad idea for interviewers to ask language/library specific questions in the interview ... it is, and should be, expected that the applicant will have a learning curve to get up to speed with what a firm is doing). COM is especially important since it is one of the foundation technologies for .Net (.Net does a very nice job of hiding that from you).
CPP_Student wrote: I should add that I have been learning DirectX, and writing a 3D modeler in C++/MFC, and was thinking of learning ATL/COM to separate the loading of models from various file formats, and support a plug-in capability (though I know nothing about this).
If you are looking to apply for a gaming company or a company that does a lot of modelling/simulation, you will want to understand COM, but the biggest part of your studies should be on solid C/C++ programming and mathematics. As for plugins, you don't need COM to create a plugin architecture (though, I have written a couple articles on here that describe how you can do so).
I assume you are looking to add some new skillsets to your portfolio while you are job searching. With that in mind, I will answer your question with a series of questions:
1) What type of job would you like to land (realistically)?
2) What areas do you think that job most likely be using (STL? COM? MFC? ANSI C?)?
3) How strong are you in those areas?
With answers to those questions, you can figure out which areas you should focus on.
By the way, if you are a strong C/C++ programmer, you should be able to pick up C# (and even Java) with only a week or 2 as your learning curve.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Zac Howland wrote: Don't let the mass flooding of the bookshelves at Barnes and Noble with all the books on .Net convince you that MFC, ATL, COM, STL, etc are out of date.
They're not quite out-of-date but IMO if they're all you can offer it won't be enough to keep you in work. That's certainly been my experience as a contractor.
Zac Howland wrote: .Net is a very small segment of the programming jobs available (and for the most part, among the lowest paying positions as well).
Well, in the Windows world at least this is not the case.
Zac Howland wrote: COM is especially important since it is one of the foundation technologies for .Net (.Net does a very nice job of hiding that from you).
Maybe so but you won't need to know it for 99% of interviews.
Zac Howland wrote: By the way, if you are a strong C/C++ programmer, you should be able to pick up C# (and even Java) with only a week or 2 as your learning curve.
Well, it needs a bit more than that. The main learning-curve is the .NET framework. Moreover, even if it does take you only a few weeks to be comfortable you somehow have to convince employers that you've got a year or two's commercial experience just to get a look-in. It shouldn't be this way but that's life.
Kevin
|
|
|
|
|
Kevin McFarlane wrote: They're not quite out-of-date but IMO if they're all you can offer it won't be enough to keep you in work. That's certainly been my experience as a contractor.
As a contractor, things are a bit different. You are expected to come in and not have a learning curve. This is mainly because companies generally farm out the work that their people could do, but their attention is focused on higher priority (e.g. more difficult matters, or ones that require much more domain knowledge).
When you are looking to be an employee, things are not so strict. Companies don't expect you to know everything when you come in; they expect that you will be able to learn quickly. With a solid foundation in C/C++ and the common libraries (STL and MFC in particular), 95% of companies will call you back for second and third interviews.
I can tell you from experience that because of my strong C++ background, when I was job searching, I had offers coming in from companies begging me to do .Net programming. The learning curve is not very high when you know C++ and are trying to go to any other language.
Kevin McFarlane wrote: Well, in the Windows world at least this is not the case.
A huge percentage of programming postions don't even touch Windows. Even those that do, the majority of them still deal with C/C++. Keep in mind ... the second largest consumer software producer is EA. 85% of their code (non-script code that is) is written in C/C++ and has nothing to do with .Net.
Kevin McFarlane wrote: Maybe so but you won't need to know it for 99% of interviews.
If you are just looking to answer interview questions in hopes that they won't ask you anything dealing with the word "how", then you are correct.
Kevin McFarlane wrote: Well, it needs a bit more than that. The main learning-curve is the .NET framework. Moreover, even if it does take you only a few weeks to be comfortable you somehow have to convince employers that you've got a year or two's commercial experience just to get a look-in. It shouldn't be this way but that's life.
Again, this is the case if you are an independent contractor. It is not the case when you are applying for a position within the company.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Thanks for the replies! Until I got canned I was a mainframe TPF IBM assembler programmer who had spent 12 years applying my trade to online credit card authorization processing at Visa. Before that I worked for two airlines over 4 years. It is a very niche business app as well as language and OS. The airlines are the only ones hiring now, but I would have to move to Denver, India, or China. My family is here, and I live in Silicon Valley. So, I want to stay, and see the job market as complex, with each job posting listing a different set of accronyms
So, having already studied C++ and MFC, and a little VB .NET (BORING!), I decided to learn DirectX, because it interests me. I decided to build a 3D modeling program, instead of writing a game, becasue it would enable me to learn C++ better, MFC, Win32, and basic Windows concepts.
Recently, I wondered if it would be a good idea to learn COM/ATL, and I could put the functions that load .x files into it. But then I encountered the dilemna I posted about here.
I figure that getting a new job using languages I have no commercial experience with would be easier if I have an actual application to show. So, that is why I am looking to expand my understand of the different tools out there, and I see COM in some job postings that also mention C++ and MFC.
Basically I feel like I am floundering at times. I was hoping that eventually there will be a need for .Net or C++ programmers that know DirectX, which is why I am wondering now about whether I should do COM or go to .NET. Every job posting wants people who have a deep knowledge of one or two languages and list of tools (those accronyms and programming platforms).
The hardest part in any programming job is learning the business application, not the programming language(s). I decided long ago (when learning VB .NET put me to sleep) that I need an application that is more complicated (and interesting) than the usual internet business model. So I ignore any job posting that wants SQL knowledge or the building of an internet/intranet app.
I don't want to end up in another niche like the one I just came from. I became one of the top experts of online credit card authorization processing, and I enjoyed it when I had something to work on, but the politics of working for a larger company that is owned and run by bankers who are so far removed from the work we do that they make incredibly stupid decisions, along with the inner politics of my area that included major cronyism, killed my work ethic. I actually wanted to get laid off so I could get a severance, which would enable me to retool. And I did get exactly that.
I am 43 and looking to make a new start. But I have a strong aptitude for programming and solving business problems. So, management is out (for now anyway). I also wonder about the usefulness of learning from books, since NONE use actual business solutions as part of the teaching.
I am hoping that the need for 3D programmers will increase in applications other than just games, as the hardware gets better and Microsoft improves its support with managed DirectX and Vista's better support of it.
-- modified at 16:36 Monday 31st July, 2006
|
|
|
|
|
CPP_Student wrote: Basically I feel like I am floundering at times. I was hoping that eventually there will be a need for .Net or C++ programmers that know DirectX
While this may change a bit if Microsoft actually gets Vista out the door, managed code (VB.Net, C#.Net, and Managed C++) are not optimal for DirectX programming. It is good to understand COM because DirectX makes heavy use of it, and it is the foundation of the entire .Net library system, but in most cases, you won't find a need to create your own COM components.
CPP_Student wrote: but the politics of working for a larger company that is owned and run by bankers who are so far removed from the work we do that they make incredibly stupid decisions, along with the inner politics of my area that included major cronyism, killed my work ethic.
I feel your pain there. The place I use to work for was just like that ... only it was run by marketing "gurus" instead of bankers ... same end result (aka stupid decisions on things they had no business trying to decide anyway).
CPP_Student wrote: I am hoping that the need for 3D programmers will increase in applications other than just games, as the hardware gets better and Microsoft improves its support with managed DirectX and Vista's better support of it.
When Vista comes out, that may help you a bit. If you aren't too opposed to it, you may find that several government contractors dealing with Modelling and Simulation are constantly looking for graphics programmers (both DirectX and OpenGL). There aren't many in Silicon Valley, but if you look more towards southern CA, I know of a couple few that are almost always looking (Lockheed Martin, Raytheon, Alion to name a few).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Zac Howland wrote: As a contractor, things are a bit different. You are expected to come in and not have a learning curve.
True.
Zac Howland wrote: When you are looking to be an employee, things are not so strict.
Not quite. But not far off. When I'm looking for work on job boards I receive both contract and perm and there's little difference between the two these days - in the UK anyway. Possibly the reality is different when you get into the actual job but in the actual job ads this isn't the case.
Zac Howland wrote: With a solid foundation in C/C++ and the common libraries (STL and MFC in particular), 95% of companies will call you back for second and third interviews.
I have such a foundation and this has not been my experience.
Zac Howland wrote: The learning curve is not very high when you know C++ and are trying to go to any other language.
I agree. I've yet to find any high level language as difficult as C++. Unfortunately, most employers don't see it that way.
Zac Howland wrote: A huge percentage of programming postions don't even touch Windows.
I know, but this guy has had an MS background and suggests by his interest in COM that he plans to remain in this domain in the near future. If so, it would seem advisable to pick up .NET whether he likes it or not.
Zac Howland wrote: Keep in mind ... the second largest consumer software producer is EA. 85% of their code (non-script code that is) is written in C/C++ and has nothing to do with .Net.
Yep, games is about the only other thing to do if you want to escape .NET (or else get into Unix/Linux in which case they probably want Java as well).
Zac Howland wrote: If you are just looking to answer interview questions in hopes that they won't ask you anything dealing with the word "how", then you are correct.
I've never been asked about COM for interviews for .NET roles, even when they do ask you "how." I'm not saying that I agree with the way most interviews are conducted but the fact is most of them do just concentrate on silly "what is" questions. You either go along with this and study accordingly or go and do something else.
Zac Howland wrote: Again, this is the case if you are an independent contractor. It is not the case when you are applying for a position within the company.
Yes, it is.
There was a time many years ago where for perm roles you would see ads such as:
"If you have 2 years' experience in C++ we will X-train you into Delphi. "
Today, such ads. are few and far between. And where you do see them they're often aimed at recent graduates rather than more senior developers.
Kevin
|
|
|
|
|
Kevin McFarlane wrote: Possibly the reality is different when you get into the actual job but in the actual job ads this isn't the case.
Keep in mind (at least in the US), Job ads tend to be written by HR people who have no knowledge of problem solving (in a computer-related sense) nor programming. I've seen ads that as for "MSCE and MCP certification required" (anyone who knows much about the certifications realizes that MCSE IS a MCP certification). I tend to look at the ads from more of a high-level view; that is, I see that they are looking for someone ... and that they want a programmer. The ads that specifically mention .Net, I tend to skip over because at least over here, every single one I have answered has been looking for an ASP.Net "programmer".
Kevin McFarlane wrote: I know, but this guy has had an MS background and suggests by his interest in COM that he plans to remain in this domain in the near future. If so, it would seem advisable to pick up .NET whether he likes it or not.
Granted, though, I wouldn't limit myself to such a small domain (being in his position). I've found (as both a job seeker and as a hiring manager) that the most successful interviewees tend to be those that focused on the fundamentals during their off-time between jobs. Then again, I've been lucky enough to run into several companies that actually do proper interviews (that is, ask you how you could go about solving a problem instead of asking you to describe the code you would write to do a specific task ... if you can google the answer, the question shouldn't be in your interview).
Kevin McFarlane wrote: most of them do just concentrate on silly "what is" questions
My recent experience with this was just the opposite (at least with the companies that I would have wanted to work for). I did get a few "how do you do X in this language with this library" questions in a couple interviews. And generally, it was those companies that I came away from the interview saying, "I don't care if I get a callback ... I don't want to work for them." (not for that reason, mind you, but it tends to go along with the culture of advocating drone programmers that produce massive amounts of code quickly instead of taking the time to think about the problem and what problems may come along with it down the road before writing the code).
Kevin McFarlane wrote: "If you have 2 years' experience in C++ we will X-train you into Delphi. "
Today, such ads. are few and far between. And where you do see them they're often aimed at recent graduates rather than more senior developers.
Perhaps they would place ads like that in the UK, but in the US, I've never seen one like that. In my experience, if you can show that you understand basic programming fundamentals and the ability to problem-solve, you won't have any trouble going through any interviews.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hi Zac,
Maybe I should emigrate to the US? Probably a bit difficult in the current climate and at my age.
Zac Howland wrote: it tends to go along with the culture of advocating drone programmers that produce massive amounts of code quickly instead of taking the time to think about the problem and what problems may come along with it down the road before writing the code
Tell me about it! I'm not the kind of person who can produce lots of code quickly - I like to think things through - and this tends to go against me.
Kevin
|
|
|
|
|
Zac wrote:
I would at least finish reading the ATL 3.0 book first. The reason is simple: in many of the new books, they refer to "this has been changed from version 3.0 ... and this is why." If you have at least a mild understanding of the way things were, you will gain and understanding of why they changed it and what may have to be changed in systems that are upgrading their libraries. From experience, that is a popular interview question.
The differences between 3.0 and 8.0 are not that great. What I stumbled on was the difference between the book's explanation of the CComModule class and DLLxxxx functions and how 7.0 has re-designed that processing with a template class and nested inheritance. The ultimate functionality is the same. And yes, it did occur to me that I could just look it up in the MSDN docs and the actual code to see what the differences are when I come across them. But this is what caused me to wonder if I should even learn it.
MS likes to rewrite their SDKs all the time. DirectX 10 is a complete rewrite. ATL 7-8 just seem to have smallish changes, and although they improved MFC with 8.0, it is not much different than before. And .NET 2.0 is a major change from 1.1, and lord knows what they will do with .Net 3.0.
I just don't want to get another job where most of what I do is just tweak/maintain existing old code all the time.
-- modified at 18:38 Monday 31st July, 2006
|
|
|
|
|
Hello,
I would like to put some objects in an (STL)vector. I know, that the vector needs a base class of all my object, so the classes of these objects are inheritance from the base class. In the example code you see how I fill the vector 'V' with object 'a'. But when I call the method 'reset()' the base class 'basis' is called and not the from class A. Furthermore it isn't allowed to call specials methods like 'loadGUI()' in class A. I know that the STL-Vector work with templates, so the call 'V.insert(V.begin(), a);' transforme the object a to the instance of 'Basis'. So, are there other possibilities to call methods from inheritance classes (like 'A::reset()') and special methods (like 'A::loadGUI()')?
I'm glad for answers,
Thomas
<br />
#include <vector><br />
<br />
using namespace std;<br />
<br />
class Basis {<br />
public:<br />
virtual void reset(void);<br />
};<br />
<br />
void Basis::reset(void)<br />
{<br />
cout << "Basis reset ! \n";<br />
}<br />
<br />
class A : public Basis {<br />
public:<br />
virtual void reset(void);<br />
<br />
void loadGUI(void);<br />
};<br />
<br />
void A::reset(void)<br />
{<br />
cout << "Class A reset ! \n";<br />
}<br />
<br />
void A::loadGUI(void)<br />
{<br />
cout <<"Class A loadGUI! \n";<br />
}<br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
vector<Basis> V;<br />
<br />
A a;<br />
<br />
V.insert(V.begin(), a);<br />
<br />
V[0].reset();
<br />
<br />
cin.get();<br />
<br />
return 0;<br />
}<br />
-- modified at 11:10 Sunday 30th July, 2006
|
|
|
|
|
SodomFighter666 wrote: I know, that the vector needs a base class of all my object
Base class pointer. Only if for some reason you need to keep all of them in the same collection (ie, they all support a particular interface), in which case the exact type shouldn't matter to you. If their actual types do matter, then you should have a pretty good reason for putting them in the same collection. Your base class should also have a virtual destructor.
vector<Basis*> V;
A *a = new A;
V.push_back(a);
V[0]->reset();
for(vector<Basis*>::iterator i = V.begin(); i != V.end(); i++)
{
delete *i;
}
SodomFighter666 wrote: I know that the STL-Vector work with templates, so the call 'V.insert(V.begin(), a);' transforme the object a to the instance of 'Basis'.
You might want to note the distinction between making a copy of an object, and storing a pointer to an object.
SodomFighter666 wrote: ... and special methods (like 'A::loadGUI()')?
So what is the reason loadGUI isn't a virtual member of your Basis class? If you still want to do something like this you would have to have a method on Basis that can tell you at runtime what kind of derived class pointer it is and cast it to that class.
|
|
|
|
|
Hi hfry,
thank you for your help. Your advise for the 'Base class pointer' works fine.
hfry: So what is the reason loadGUI isn't a virtual member of your Basis class?
The reason is, that I can't change the base class. The base class is from the Qt library (It's a QWidget class).
In my application I call for every QWidget object (like pointer object 'a') the appropriate method (like 'loadGUI()').
The result is like this:
a->loadGUI();
b->loadGUI();
c->loadGUI();
d->loadGUI();
...
I would like to have these calls in a for-loop where 'V' is the vector to the QWidget objects:
for (int i=0; i < V.size(); i++)
{
V[i]-loadGUI();
}
/////////////////////////////////////////////////////////////////////////////
class B : public Basis {
public:
virtual void reset(void);
void loadGUI(void);
};
void B::reset(void)
{
cout << "Class B reset ! \n";
}
void B::loadGUI(void)
{
cout <<"Class B loadGUI! \n";
}
....
vector<Basis*> V;
//Build up object a
A* a = new A();
V.push_back(a);
//Build up object b
B* b = new B();
V.push_back(b);
for(int i = 0; i <V.size(); i++)
{
V[i]->reset(); //It works fine.
}
//Now, try to call loadGUI()
//First version
A* a1 = static_cast<A*>(V[0]);
a1->loadGUI();
B* b1 = static_cast<B*>(V[1]);
b1->loadGUI();
//Second version
for(int i = 0; i <V.size(); i++)
{
// V[i]->loadGUI(); //It doesn't work.
}
/////////////////////////////////////////////////////////////////////////////
If there isn't a solution with STL, I will tried with design pattern (maybe the decorator pattern). But this is an other topic and doesn't belong to this forum.
Kinds regard,
Thomas
|
|
|
|
|
You might want to look into delegates, there should be a few articles on codeproject on this.
Alternatively, here's a hack. You might want to get a second opinion before doing this though.
struct ICommon
{
virtual ~ICommon(){};
virtual void loadGUI() = 0;
virtual void reset() = 0;
};
template <class T, bool t_bManaged = true>
class Wrapper : public ICommon
{
public:
Wrapper(T* pObject)
{
m_pObject = pObject;
}
~Wrapper()
{
if(t_bManaged) delete m_pObject;
}
void reset()
{
m_pObject->reset();
}
void loadGUI()
{
m_pObject->loadGUI();
}
T* m_pObject;
};
class A {
public:
void reset(void)
{
cout << "Class A reset ! \n";
}
void loadGUI(void)
{
cout <<"Class A loadGUI! \n";
}
};
class B {
public:
void reset(void)
{
cout << "Class B reset ! \n";
}
void loadGUI(void)
{
cout <<"Class B loadGUI! \n";
}
};
vector<ICommon*> V;
V.push_back(new Wrapper<A>(new A));
V.push_back(new Wrapper(new B));
for(vector<ICommon*>::iterator i = V.begin(); i != V.end(); i++)
{
(*i)->reset();
(*i)->loadGUI();
}
for(vector<ICommon*>::iterator i = V.begin(); i != V.end(); i++)
{
delete *i;
}
-- modified at 16:37 Sunday 30th July, 2006
|
|
|
|
|
From what you are saying, you really don't want a vector or QtWidgets, you want a vector of QtWidgets that have a loadGUI method. Thus, you can do this:
class Base
{
public:
virtual void loadGUI() = 0;
virtual void reset() = 0;
};
class MyWidget : public QtWidget,
public virtual Base
{
virtual void loadGUI() {}
virtual void reset() {}
};
Then, in your code, you will create your MyWidgets and place them in a vector:
vector<Base*> myVector;
for (int i = 0; i < 5; ++i)
{
myVector.push_back(new MyWidget);
}
Then, whenever you decide to call your methods:
void loadGUIs(const MyWidget*& widget)
{
widget->loadGUI();
}
for_each(myVector.begin(), myVector.end(), loadGUIs);
As a side note: You will notice that I did not create a loop to iterate through the vector. You should use the algorithms as much as possible -- it will save you a LOT of headaches.
-- modified at 15:04 Monday 31st July, 2006
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Thank you for your help,
@hfry:
My compiler (Visual Studio 2003) has problems with the following lines:
V.push_back(new Wrapper(new A));<br />
V.push_back(new Wrapper(new B));
The code output is "If you use a template class a template argument list is nessesary!" (translation from german).
After playing with the code I'm able to compile the wrapper class without pointer:
Wrapper<A> myWrapper(A); // with class 'A'
@Zac:
At this morning I produced a similar solution like you:
class Base : public QWidget<br />
{<br />
public:<br />
virtual void loadGUI() = 0;<br />
virtual void reset() = 0;<br />
};<br />
<br />
class MyWidget : public Base<br />
{<br />
virtual void loadGUI() {}<br />
virtual void reset() {}<br />
};<br />
<br />
vector<Base*> V;<br />
<br />
V.push_back(new MyWidget);<br />
...
But your solution is better. First your base class doesn't care about QWidgets (= less/simple code). Second your advise to use stl-algorithms for a good health (I only want headaches with a lot of beer at the next party!).
Bye,
Thomas
|
|
|
|
|
How to CComBSTR convert to char *?
alantop
|
|
|
|
|
USES_CONVERSION;
CComBSTR *pBString;
...
...
char *pString = OLE2T(pBString);
This should work.
The original point and click interface was a Smith & Wesson.
|
|
|
|
|