|
I want to implement a "plug-in" style system where the plug-ins are derived classes based on a pure virtual base class in my application:
Application:
class CPlugInBase<br />
{<br />
public:<br />
virtual int DoSomething() = 0;<br />
int Calculate(int a, int b) {...}<br />
};
DLL:
class CPlugIn : public CPublicBase<br />
{<br />
virtual int DoSomething() {...Calculate(1,2);...}<br />
};
The CPlugIn class overrides a few virtuals in the base class, and also needs access to other methods in the base class.
An extra wrinkle is that I would actually like to be able to do this:
Application:
class CPlugInBase<br />
{<br />
virtual int DoSomething() = 0;<br />
};<br />
<br />
class CSpecialPluginBase : public CPlugInBase<br />
{<br />
virtual int DoSomething() { DoPart1(); return DoPart2();}<br />
virtual void DoPart1() = 0;<br />
virtual int DoPart2() = 0;<br />
};
DLL 1:
class CPlugIn : public CPublicBase<br />
{<br />
virtual int DoSomething() {...}<br />
};
DLL 2:
class CSpecialPlugIn : public CSpecialPlugInBase<br />
{<br />
virtual void DoPart1() {...}<br />
virtual int DoPart2() {...}<br />
}
where the CSpecialPlugInBase might override the virtuals from CPlugInBase , and then define new pure virtual functions that the CSpecialPlugIn class would have to override while still allowing access to members of both base classes.
Is this do-able in VC++ 6?
Thanks
-robin
|
|
|
|
|
rex666 wrote:
Is this do-able in VC++ 6?
Absolutely.
The nice thing is that since your CPlugInBase and CSpecialPluginBase classes are abstract, they won't really be part of any module (application or DLLs). In other words, they can just be placed inside a header file and then be shared among all the modules that use it.
Don't forget to add a pure virtual destructor to the CPlugInBase class. You can just leave it empty and implement it right where it's declared:
virtual ~CPlugInBase() { }
Regards,
Alvaro
All you need in this life is ignorance and confidence, and then success is sure. -- Mark Twain
|
|
|
|
|
What if there are extensive other methods in the base classes? Do I have to inline everything? Are there consequences of having a massive amount of inline code in the base class?
I had the example with one other method, but what about having a whole API available through the base class for the plug-ins to interact with the main program? Or would it be better to put that API somewhere else?
Thanks
-robin
|
|
|
|
|
If there's massive amounts of code in your base class, then it's best to build it into one module, so that it's easier to maintain -- when it comes time to change something, all you need to rebuild is that one module.
In your case, you can certainly go with putting the code for the base class inside the application (EXE) and exporting the class. That will generate a LIB file which you can then use when linking your DLLs. Thus, your DLLs will depend on the EXE and your EXE will depend on the DLLs -- a mutual dependency. Since your EXE is already running when it loads the DLLs, the DLLs will just use the base class code right out of it and they won't load another version of the EXE.
I've done this myself in the past and it's worked great. Instead of putting the code for the base class into yet another DLL (which is another option), you can just export it right out of the main app.
Regards,
Alvaro
All you need in this life is ignorance and confidence, and then success is sure. -- Mark Twain
|
|
|
|
|
I've got some binary data (hex represented).
I've got the values
01 ae
90 3d
and I want to convert these to a string representation in ATL with Minimial additional libraries involved
"AE01"
"3D90"
Is there a simple way to do this, or should I just import stdio etc?
|
|
|
|
|
str.Format("%.02X",bit[i])
-----------------------------
Mr.Whelk
-----------------------------
Zhuhai City ,Guangdong ,China
|
|
|
|
|
When I try to include a ressource item in my project.
I have a error that tell me that afxres.h cannot be found?
I use MFC with VS.net.
Any ideas?
Everything is beautiful if you look at it long enough...
|
|
|
|
|
check resource(!) include path
|
|
|
|
|
How can I determine the number of days between 2 dates?
How can I determine a date that is exctly 6 months away from a specified date:
e.g., if Today is 15 Jan 2003 - it should return 15 Jul 2003
(ignore the complication when the result will be February 31, etc.)
Thanks
|
|
|
|
|
If you have the two days in time_t format, then just subtract the two times and then divide by the number of seconds in a day.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Anton A. Loukine wrote:
How can I determine the number of days between 2 dates?
How can I determine a date that is exctly 6 months away from a specified date
Use a timespan class such as CTimeSpan or COleDateTimeSpan:
COleDateTime date1(2003, 1, 1, 0, 0, 0);<br />
COleDateTime date2(2003, 3, 24, 0, 0, 0);<br />
<br />
int nDays = (int)COleDateTimeSpan(date2 - date1).GetTotalDays();<br />
COleDateTime date2In6months = date2 + COleDateTimeSpan(6 * 30);
Anton A. Loukine wrote:
if Today is 15 Jan 2003 - it should return 15 Jul 2003
I don't know of an easy way to do this, however you may certainly do it manually by adding to the month and then to the year if there's overflow:
int nMonth = date2.GetMonth() + 6;<br />
COleDateTime date2In6months(date2.GetYear() + (nMonth / 12), nMonth % 12, date2.GetDay(), 0, 0, 0);
Regards,
Alvaro
All you need in this life is ignorance and confidence, and then success is sure. -- Mark Twain
|
|
|
|
|
Now suppose I wanted to complicate the matter and avoid using MFC or any other wrapper classes.
Thanks
|
|
|
|
|
Yes, these are wrapper classes. If you don't want to use them, I recommend you look at their source code to get some ideas for how to accomplish what you need.
Regards,
Alvaro
All you need in this life is ignorance and confidence, and then success is sure. -- Mark Twain
|
|
|
|
|
I have (hopefully) set up the menu for NOTIFYBYPOS.
In the cpp file, I want to add a message map entry for a menu item thats got no ID.
I have put in
afx_msg void OnMenuCommand( WPARAM wParam, LPARAM lParam);
in the h file
When the dynamic non-ID bearing menu items are clicked, I want to trap the WM_MENUCOMMAND issued.
I'm thinking
ON_COMMAND(<code>WHat_Goes_Here</code>, OnMenuCommand) ...
In the usual ON_COMMAND they have an ID_SOMETHING as the first parameter to this map statement...
Appreciate your help,
ns
|
|
|
|
|
I put in a dummy ID_DUMMY1 for all my dynamic menu items created on the fly and used that in the ON_COMMAND. But its not bringing in the right index - its a huge positive integer. BTW, if I name another actual physical menu item ID_DUMMY1 created before I even do the notifyposition stuff, it still responds to the OnMenuCommand!!!! SO something isnt right with my message map....I may be totally off the mark here. I am thinking if I make the submenu under the toplevel "mapdyn" NOTIFYBYPOS, every one under it will trigger the index handler. But maybe I cant make it NOTIFYBYPOS since its already created in the resorrce editor?
In my menu "mapdyn" I already have one existing physical submenu item since i wasnt able to get GetSUbMEnu(pos) without it being present.
CMenu* mmenu = ((CMainFrame*)AfxGetMainWnd())->GetMenu();
int pos = ((CMainFrame*)AfxGetMainWnd())->FindMenuItem(mmenu, "mapdyn");
if (pos == -1)
return;
CMenu* submenu = mmenu->GetSubMenu(pos);
HMENU m_hMenu = submenu->GetSafeHmenu();
MENUINFO mi;
mi.cbSize=sizeof(MENUINFO);
mi.dwStyle = MNS_NOTIFYBYPOS;
SetMenuInfo(m_hMenu, &mi);
submenu->AppendMenu(MF_STRING, ID_DUMMY1, "From M1");
submenu->AppendMenu(MF_STRING, ID_DUMMY1, "From M2");
submenu->AppendMenu(MF_STRING, ID_DUMMY1, "From M3");
void CBKView::OnMenuCommand(WPARAM wParam, LPARAM lParam)
{
CString a;
a.Format("index is %d", wParam);
AfxMessageBox(a);
}
Appreciate your help,
ns
|
|
|
|
|
I have implemented a Property Sheet with multiple property pages. I have set a few buttons on one of my pages and can't seem to get a handle to allow me to disable (grey) the button. I know I am doing something wrong and can't figure it out so please point me in the right direction. Sample code or correcting mine would help the most.
<br />
CWnd *pWnd = AfxGetMainWnd();<br />
CButton* pButton = (CButton*) pWnd->GetDlgItem(IDC_ENGINE_LIGHT_DELETE);<br />
pButton->EnableWindow(FALSE);<br />
Thanks!
John Hagen
|
|
|
|
|
This worked for me with list controls
from within your propertysheet class:
CMyPropertyPage m_myPage;
CButton* pButton = (CButton*) m_myPage.GetDlgItem(IDC_ENGINE_LIGHT_DELETE);
pButton->EnableWindow(FALSE);
|
|
|
|
|
That works for me, too, though I normally handle the button management local to the propertypage, so don't have the m_myPage indirection, e.g.
CButton* m_rbFile = (CButton*) GetDlgItem(IDC_BUTTON);
m_rbFile->EnableWindow(FALSE);
Debbie
|
|
|
|
|
Hi Debbie,
Thanks for the code. It worked perfectly. I appreciate youtaking the time to post help to my question.
John
|
|
|
|
|
Thanks for the sample code. It is what I needed to get over this minor hurdle. I appreciate your time and effort.
John
|
|
|
|
|
Hiya, I have a very old C Compiler( the usual NMAKE stuff!! ) that compiles very old dos based programs. The programs are very old but very good..so I like messing around with them and changing them..Sad I know but it helps me practice my programming...
Does anyone know a way of using Microsoft Visual C++ 6.0 to compile up such programs, instead of using the old C Compiler??
If anyone knew this it would be a great help to me..
Thanks,
grahamoj
|
|
|
|
|
depends how old they are, some dos staff might not be supported anymore. What is wrong with the old compiler? If all you want to do is to use VC, in VC 7 you can specify custom compiler (non MS), in VC 6 you can check "Always use custom build step"
|
|
|
|
|
Hiya using the old C Compiler is ok but abit crap because I would like to use 6.0 to be able to compile the old dos programs and my new stuff, instead of continually changing between the two ...
I know Visual 6.0 is a Windows based compiler, but surely it can do this.
Were is the "Always use custom build step" and what exactly I am checking it for??
thanks,
grahamoj.
|
|
|
|
|
1. The steps I mentioned are to use 3rd party compiler from VS 6 and 7. Project settings is the place to configure it.
2. If talking about 16-bit dos, it most probably would not compile with 32-bit MS compiler. If your code is 32-bits - just create a project and add your files there. There could be some dependencies missing (include directories, libraries etc.) but it is easy to configure in project settings.
I guess I do not understand what exactly is the problem with converting(adapting) the code.
|
|
|
|
|
Hi, can I get the height in point size (not logical size) from a font ?
LOGFONT lf;
GetFont()->GetObject(sizeof(lf),&lf);
return lf.lfHeight;
From MSDN:
lfHeight - Specifies the height, in logical units
Thx for help, Moak
|
|
|
|