|
|
Cool! Given your requirements in your last post (about the type of software), that could
be a good solution.
Thanks for the link and update!
MArk
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
given a class heirarch where
A is the base class and B , C are derived classes .
Now I want to implement something like an object factory externally where I want to automatically create an object of the appropriate type . For this I define a struct with the definition ( pardon me for the pseudo code as part of the problem is with usage)
typedef struct
{
int code ;
reference_to_type_creator ;
}OBJ_TYPE ;
OBJ_TYPE objTable[] =
{ objA_code , < reference to create an object of type A > } ,
{ objB_code , < reference to create an object of type B > } ,
{ objC_code , < reference to create an object of type C > } ,
{ -1 , NULL } such that I can use this table in a function that processes random object entries
ProcessObject( int objCode )
{
for (int i=0;objTable[i].code!=-1;i++)
{
if( objCode == objTable[i].code)
{
A *a = objTable[i].reference_to_type_creator
a->Foo()
}
}
} I was unclear as to how this reference would be specified in the struct array above and its usage.
Help is appreciated
}
Engineering is the effort !
|
|
|
|
|
i'd just do it with a switch
ProcessObject( int objCode )
{
A* a = NULL;
switch (objCode)
{
case 0:
a = new whatever0;
break;
case 1:
a = new whatever1;
break;
etc..
}
a->Foo();
}
otherwise, maybe you could add static Create methods to your object types, and put refs to those in your array (off the top of my head):
class whatever0 : public A
{
static public whatever0 * Create()
{
return new whatever0();
}
...
};
class whatever1 : public A
{
static public whatever1 * Create()
{
return new whatever1();
}
...
};
...
OBJ_TYPE objTable[] =
{
{0, whatever0::Create},
{1, whatever1::Create},
};
... where OBJ_TYPE is a struct with an int and a function pointer that returns an A*
you'd need the static Create functions because you can't do function pointers to non-static member classes.
|
|
|
|
|
I'm building an App. I have a Doialog Box containing a Progress Bar to show the progress of the longer operations. If I switch between the App window and other open window, during such a long operation, the contents of my App window become corrupted, dispite the fact that the App works correct. Only the Progress Bar is shown when is updated with the SetPos() function.
How to prevent the window from loosing his "face" ?
In VC++6 please...
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
RomTibi wrote: I have a Doialog Box containing a Progress Bar to show the progress of the longer operations.
What article or tutorial / example did you follow to do that?
led mike
|
|
|
|
|
No such source. I tryed to use MSDN
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
RomTibi wrote: No such source.
That's garbage those samples have been around like forever on MSDN and are probably available during installation of Visual Studio.
RomTibi wrote: I tryed to use MSDN
You need to try harder[^].
led mike
|
|
|
|
|
...IT IS TO WORK ...
Thanks!
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
A small problem: following the link you provided I didn't find how to download the "Fire" example.
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Yes I see that now. It appears they have abandoned FIRE sample in later versions of MSDN documentation. If you go to the Documentation for CProgressBar for VS2005 version there is a link to a new sample of using the CProgressBar. Learn to use the MSDN documentation, doing so will save you much time.
led mike
|
|
|
|
|
I found it, thanks to you
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
You have two options:
1. Run your "longer operation" in a separate thread
2. Handle the messages for your dialog "manually" so Windows can re-draw your dialog and controls, see below
I sometimes use a macro that processes messages and place it in functions that usually take a long time to complete (in a for or while loop):
#define PUMP_MESSAGES {MSG Msg; while(::PeekMessage(&Msg,NULL,0,0,PM_REMOVE) != 0) {::TranslateMessage(&Msg); ::DispatchMessage(&Msg);}}
You don't want to call it too often, just about enough so your app remains responsive.
Example:
for (i = 0; i <= 999; i++)
{
PUMP_MESSAGES
...
...
}
|
|
|
|
|
Thanks!
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Hi,
I had the same problem last year, and decided to use a dedicated Progress Dialog. You can find a simple but verry effective SDK type implementation at <a href="<a href="http://www.geocities.com/krishnapg/UPDialog.html">www.geocities.com/krishnapg/UPDialog.html</a><ahref="http://www.geocities.com/krishnapg/UPDialog.html" target="_blank" title="New Window">^</a>]"></a>
Hope you find this Useful,
Regards,
Bram van Kampen
|
|
|
|
|
Thanks! I'll study the sources...
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
|
Thanks!:rose:
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
I know there is a name for taking an "extended word" and converting it to a "base word". An example extended word is "taking". The base word for "taking" is "take". Or "steaks" becomes "steak". I'm pretty sure I've seen the name for the particular algorithm that does that somewhere along the line. The only thing I can think of is Soundex/Metaphone and those are for phonetic purposes not reduction purposes.
modified on Thursday, February 28, 2008 5:07 PM
|
|
|
|
|
|
Thank you. Now I just have to find a "Word to Lexeme" English dictionary (or maybe "Word to Lemma to Lexeme" dictionaries or something similar).
|
|
|
|
|
I have a MFC serveur and a MFC client which work fine in most cases except 1 (the client and the serveur are in different Active Directory trees on the same network).
On the client I use :
m_pConnectionSocket = new CSocket();
if (m_pConnectionSocket && m_pConnectionSocket->Create())
{
if (m_pConnectionSocket->Connect(m_strLicenseServerName, TCP_PORT_3))
{
...
}
}
In the case it does not work Connect returns WSAEISCONN error which make no sense on my point of view.
Any idea ?
|
|
|
|
|
I have two static libs that I want to convert into one DLL. The libs contain class definitions and are statically linked into other DLLs.
We want to be able to use these classes with other DLLs without having th statically link the libs into them, since these classes can change often.
Any easy way to do this?
TIA
-C
|
|
|
|
|
If you have the source it should mostly be a matter of changing the project settings, in VS2005 or later anyway. In V6 you might need to create a new DLL project and manually pull in all the same files and setting the static lib project has.
If you don't have the source then reusing individual classes is out, you'd have to write a wrapper DLL that is itself statically linked to the original lib which kind of defeats the object as you'd get the whole lib in the DLL not just the classes you want.
Assuming you have the source, have you considered just including the source files directly in more than one project? We have a 'Shared' folder in parallel with the folders for our projects which contains source for common classes and headers that are used everywhere. Works fine as long a you only include things that you alwasy want to be the same everywhere they're used.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Its VS60.
I have all the source from the libs. They're class definitions that other classes are derived from. We regularly create new DLLs that statically link these libs. The problem is that if they change, we always have to recompile and version the DLL. We want to move all the class definitions into a DLL that our new DLLs can dynamically link.
So if the new DLL changes, the old ones can always dynamically link to the new changes.
Questions:
- How to convert from static to dynamic libraries?
- How to export the classes to be used by other DLLs? DO we only include the .lib file from the dynamic library into the new project?
- Any other issues?
I'm lost here.
|
|
|
|