|
Hi..
In c++ how can i create a new object of a class depending on the contents of the string. Suppose a function is there which takes input argument as a string which is nothing but a class name and that function will return me a new object of that class. something like...
char strClassName[] = "CTest";
CTest* pTest = new ??
now what will be replaced with ?? and i want to use that strClassName string.
class CTest is an example i can replace that with any class name. Whatever the class name appears in the strClassName that class's object should get created. Something like RUNTIME_CLASS macro in MFC. in this macro it uses ## to parsing token. Same thing i want to achieve not using MFC. how can i do that.
Thanks
Ravi
|
|
|
|
|
Its a simple use of logic i guess..
Class Class1 : public CBase
{
public:
void WhoAmI() //virtual fucntion in base class.
{
printf("i am class1");
};
};
Class Class2 : public CBase
{
void WhoAmI() //virtual fucntion in base class.
{
printf("i am class2");
};
};
char szClassName[] = "Class1";
void main()
{
CBase *pClass;
if(!strcmp(szClassName,"Class1"))
{
pClass = new Class1;
}
else
....
pClass->WhoAmI();
...
}
The World is getting smaller and so are the people.
|
|
|
|
|
It requires more thought that that. The RUNTIME_CLASS macro in MFC uses the runtime information gathered by MFC to create new objects.
In plain C++, the most effective approach would be to analyse the string the user has posted, and create a new object based on this info. For an example:
void* ptrObject = NULL;<DIV>
if ( _stricmp(strClassname, "CTest") == 0 )
{
ptrObject = reinterpret_cast<CTest*>(ptrObject);<DIV>
ptrObject = new CText(...);
}
<DIV>
... Use the object ...
<DIV>
delete ptrObject;
This code piece will analyze the input and create a new object based on the input. The void-pointer is used because we want the pointer to be global for the function, but we do not know it's type until we analyze the string. Be especially careful that you initialize the pointer to NULL before doing the cast conversion. Otherwise your compiler might throw you a warning.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
hi,
I'm a VietNamese student, now i'm doing a project with the ower-draw
control and I want to create a dialog that like your RGN Generator.
Would you please tell me how to create A RGN Generator text with the
burning fire around it and a button with the text circling it.
Thanks
|
|
|
|
|
Hello Guys,
Is it advisable to design a new control derived from CWnd like CButtons in stuff?
Can any one give me or direct me to a sample that has done it so that i can understand the complexity involved.
Thanx in advance.
Yo!
|
|
|
|
|
Search for CRulerWnd/ CRulerWindow in codeproject,which allows to create/use custom control Ruler(Scale)
Warm Regards,
KKR
|
|
|
|
|
Thanx Mate,
Regards,
Prakash.;)
The World is getting smaller and so are the people.
|
|
|
|
|
How can I crack an encryped *.zip file or an encrypted Word document? as we have known, decryption needs its algorithm and its key, but we don't know the encryption algorithm of it, I want to try the key one by one by using a hacker dictionary,
how can I do it? I want someone will help me~
I am a Chinese boy
|
|
|
|
|
Prolly wrong place to ask that question...
The word of the day is legs, let's go back to my house and spread the word
|
|
|
|
|
Hahaha man you are so sick...Password are put so that ppl like you dont read them.
|
|
|
|
|
don't put your nose into stinking things!
Don't try it, just do it!
|
|
|
|
|
ive used GetDIBits to get the bitmaps images RGB data into a
byte array
so effectively i can modify the rgb values of the image by just modifying the bits in the byet array buffer.
i tried creating a function
SetPixelColor(LPBYTE imgBuf,int column,int row,DWORD dwColor)
{
}
that is supposed to set the dwColor for pixel at row and column specified
however im having problems in mapping the row and column to the 1D LPBYTE buffer
please advice??
or is there any other alternative APIs
|
|
|
|
|
How can i change the text in the status bar for an SDI document >
|
|
|
|
|
try it !
probably
AfxGetApp()->m_hMainWnd->GetDescendWindow(yourstatusbarID);
Hello World!
|
|
|
|
|
I would like to write a proxy compatible with windows 98/XP.
I have looked at the articles here on CP and the two relevent articles don't apply to my particular problem I don't think.
For instance, the firewall example here on CP uses features specific to XP (I think). I want to write a firewall, but need it to work in win 98 also. Does anyone know of articles which might explain the different approaches used in writting a http proxy? basically I just want to capture HTML before being sent to browser, preferably both IE and Netscape. I have already considered using IWebBrowser2 to accomplish what I want to do also.
Edit Actually I really need to capture HTTP and HTML...so maybe IWebBrowser2 wouldn't work at all
Thanks
The word of the day is legs, let's go back to my house and spread the word
|
|
|
|
|
|
Coolness
Thanks
The word of the day is legs, let's go back to my house and spread the word
|
|
|
|
|
I want to design a windows program that can communicate using the serial port. I bought C#.net standard not knowing it did not have serial communcations framework and the work around is using MSComm.ocx from Visual Studio 6 which i do not have. Does C++.net standard have serial port communications framework? Or would buying Visual Studio.net solve my issue?
Thanks,
karl
|
|
|
|
|
For serial communication over COM port you have to use API functions like
CreateFile, WriteFile, ReadFile etc.
or alternatively you can use an OCX component, like MSComm.ocx.
Both ways can be achieved from C#, too.
Bunburry
|
|
|
|
|
Does any one know a fairly easy way to set the focus to a given edit control in a dialog box? Thx,
Ralf.
ralf.riedel@usm.edu
|
|
|
|
|
GetDlgItem(IDC_MYCONTROL)->SetFocus() ???
The word of the day is legs, let's go back to my house and spread the word
|
|
|
|
|
That's it. Thanks.
ralf.riedel@usm.edu
|
|
|
|
|
I also do myEdit.SetSel (0, -1); before setting focus to an edit control after displaying a validation error message. This prepares the control for overwriting.
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
I need to send data out in two short ints in a message. The source data is in floating representation, range -180.00 to +180.00. This needs to be converted into a scaled 32 bit 2's Complement integer value
So what I need to do is normalise the data;
i.e. float f = 99.9;
f = f/180; // 0.555
Now I need to extract the bits that reprsent the .555 and convert them to a 32 bit bit 2's Complement integer
I was planning to use the union as follows:
union
{
int intValue;
unsigned short buff[2];
}convert;
So once I have converted the float to int I can assign the buff[]
e.g. convert.intValue = floatToInt(f/180);
So now I can load the message using convert.buff[0] and convert.buff[1]
Note I need to check the conversion, so I am planning to do the following:
float f_out = (float) ((buf[0] << 16 | buf[1])*180);
Question how to I convert the float to int?
grahamfff
|
|
|
|
|
int i = int ((f/180.0f)*float(MAX_INT));
I don't remember exactly what MAX_INT is called. But it is in limits.h.
float f = float (i) / float (MAX_INT) * 180.0f;
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|