|
#include <string>
class CAR
{
private:
std::string type;
public:
std::string GetType();
}
class BMW
{
public:
BMW() { type = "BMW"; }
}
and so on. you don't need to use std::string, obviously.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
HI
OK have somthing like this but how to call the individual info() method ??
Tim
|
|
|
|
|
Well, my way, there is no individual info method. However, in either case, you should find you're calling it in your original code. If not, perhaps you need to store a pointer instead of a class instance, perhaps it's being downcast by std::list at the moment ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
OK
THX alot
Will write my own list and iterator
That might be no problem then i just liked to know how to use list and iterator
CU
|
|
|
|
|
tbrake wrote: Will write my own list and iterator
No, please don't do that. What I was suggesting was that you should perhaps try storing a CAR * instead of a CAR in std::list.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
OK, I've done some testing:
this works:
#include <string>
#include <iostream>
#include <list>
class CAR
{
public:
virtual char * GetInfo() { return "BASE"; };
};
class BMW: public CAR
{
char * GetInfo() { return "BMW"; }
};
class Gemini :public CAR
{
char * GetInfo() { return "Gemini"; }
};
class Benz :public CAR
{
char * GetInfo() { return "Benz"; }
};
int _tmain(int argc, _TCHAR* argv[])
{
std::list<CAR*> cars;
cars.push_back(new BMW());
cars.push_back(new BMW());
cars.push_back(new Gemini());
cars.push_back(new Benz());
std::list<CAR*>::iterator it = cars.begin();
while(it != cars.end())
{
std::cout << (*it)->GetInfo() << std::endl;
++it;
}
int i;
std::cin >> i;
return 0;
}
but if you don't store pointers in the list, then it does indeed downcast to the base class.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hello all,
(My first post)
I am developing an application for WinCE 3.0 for a Pocket PC 2000 device in C++ using MFC / WinAPI.
In my application I use a Bluetooth CF card to communicate with a wireless printer. The drivers installed assign a COM port to the printer so I may
read / write to it using WinAPI calls for Files such as:
CreateFile( ... );<br />
ReadFile( ... );<br />
WriteFle( ... );
The wireless printer conserves battery by automatically turning off after a period of inactivity, so at times I must check to see if it is there before the user tries to print something.
The problem is that if I want to know anything about the file I must first get a handle with the CreateFile( ... ) function, which lags about 10-15 seconds before it times out if the printer is off, so usually the user is already trying to print something by the time I get back from that function call. Or if I make the user wait until I get back, they will get frustrated after so much time.
I tried using
CFile::GetStatus( ... )<br />
but it doesn't seem to work for COM ports, eg. I can call:
HANDLE hPrinter = CreateFile( _T("COM4:"),...);
and I get the handle but if I do this:
BOOL bIsPortAvailable = CFile::GetStatus( _T("COM4:"), ...);
I get FALSE back;
Is there a way to specify the timeout for the CreateFile( ... ) function or another way to check if that COM port is available?
Thanks Much,
T.J. Barbour
|
|
|
|
|
You could try polling the printer to see when it's off. That way when a user tried to print, the status would already be off unless it just turned off a few seconds before the user tried to print.
I think you might get more responses if this post were moved to the WinCE forum? I've noticed lots and lots of function calls give me major lag on WinCE when they don't on WinXP, so you're more likely to get someone who knows how to solve the problem over there.
Kelly Ryan
|
|
|
|
|
I'll look into that.
Polling is an option that I may persue, but we all know the disadvantages of polling : )
I appreciate the reply!
Thanks Much,
T.J. Barbour
|
|
|
|
|
Maybe you can get the printer driver manufacturer to support WM_DEVICECHANGE then you can actually be notified that the power has come or gone...
Marriage slows down your coding, a baby slows it down even more!
|
|
|
|
|
Hi,
I am working on an application that requires user to submit registration information to my company.
There are a couple options for me.
1) bring up an email & pre-type all registraion
information to the body but I am not sure
it's doable or not.
2) create a submit button and send the information
to our server but it requires some work in back end.
Is there any better way to do it? If not, is
that possible to pre-type the email?
Can someone give me some ideas/suggestions?
Thanks,
Kevin
|
|
|
|
|
Sure. You could use MAPISendMail (PSDK) to send mail from the application. You could easily provide the registration information in your desired format within the message object, and just show the user a read-only copy (out of niceness).
To the same end, there are also third-party add-ins that you can add to your app to handle mail sending.
Remember, though, that if you want to process these incoming registration messages automatically, some SMTP servers change the content of email messages. For example, my office e-mail scans for viruses and adds a line indicating the messages has been scanned for viruses at the bottom of the message.
--
I've killed again, haven't I?
|
|
|
|
|
Hi,
Thanks for your suggestion.
After reading http://www.codeproject.com/internet/cimapi.asp,
I am able to send email from my application.
However, it got a minor issue.
My email body is about 10 lines with about 200 characters.
I have "\r\n" to separate each line. The AfxMessageBox
displayed the text correctly, 10 separate lines.
But, the mail.Text ( ) concatenated my data to a
huge BIG string.
Do you know what caused the problem?
Thanks,
Kevin
|
|
|
|
|
I just tried the CIMapi and the mail I sent with "\r\n" as a line separator came across as individual lines as expected.
Have you checked the email message source to see if your CRLFs are coming through at all and just not getting displayed?
--
I've killed again, haven't I?
|
|
|
|
|
Hi,
I found the problem.
The problem was caused by my Thunderbird, Mozilla.
When I tested the same excutable on other
machine with Outlook Express. Everything
came out fine.
Thank for your help!
Kevin
|
|
|
|
|
Is there a reliable quick way to find the 4th Wednesday of every month using the "COleDateTime".
|
|
|
|
|
Just off the top of my head, assuming you want the 4th Wednesday of nMonth in nYear:
1. Create a COleDateTime for the 1st of nMonth in nYear at noon.
2. Use GetDayofWeek to find out what day it is.
3. Determine nOffset, how many days it is 'til the first Wednesday of nMonth.
4. Create a COleDateTimeSpan of (nOffset + 21) days.
5. Add this COleDateTimeSpan to the COleDateTime from step 1.
--
I've killed again, haven't I?
|
|
|
|
|
I am having some trouble on one machine, with an application written using CFtpConnection. I narrowed it down in a test program to a Cmd Prompt app that has the following code inside its tmain():
cerr << "Starting\n";
CInternetSession *pInetSession = new CInternetSession;
cerr << "Got session\n";
CFtpConnection *pFtpConn =
pInetSession->GetFtpConnection(servername);
cerr << "Got connection\n";
while (true);
On the control PC this program does what's expected -- prints the three lines and then hangs (if servername is a valid machine name) or prints two lines and exits with an "Abnormal termination" message (if servername is not valid). On the machine where I'm having trouble, regardless of servername the program will print two lines and then exit with no status message. Could WININET have some kind of corruption? Everything was working fine on this computer until this morning and I can't see what changed in the mean time. I can run ftp from the prompt and establish a connection fine. Any ideas? I am tearing my hair out here.
Thanks
|
|
|
|
|
Use endl instead of \n .
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
|
|
|
|
|
cerr flushes every time you write data to it. I acknowledge that it's better practice to use endl but that's not affecting this test program.
|
|
|
|
|
My bad. I glanced right over cerr and just assumed it was cout .
Have you tried catching CInternetException ?
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
|
|
|
|
|
So find out what went wrong.
try
{
cerr << "Starting\n";
CInternetSession *pInetSession = new CInternetSession;
cerr << "Got session\n";
CFtpConnection *pFtpConn =
pInetSession->GetFtpConnection(servername);
cerr << "Got connection\n";
while (true);
}
catch (CInternetException* e)
{
TCHAR err [1024];
e->GetErrorMessage(err, 1024);
cerr << "Big ol' uh-oh: " << err << endl;
e->Delete();
}
--
I've killed again, haven't I?
-- modified at 14:15 Thursday 5th January, 2006
|
|
|
|
|
It still exits with no message. I think rather than throwing a structured exception, WININET is calling exit(). I also added a handler for (...) and it did not execute either.
|
|
|
|
|
OK -- now I have uninstalled Dr. Watson on the machine in question and sure enough, when I run the test program, it gets to the GetFtpConnection call and then aborts with "The instruction at "0xaddress" referenced memory at "0xaddress"".
|
|
|
|
|
Hello Friends,
I'm developing an application, Where sound data has to be captured from a pci based "sound card" and the processed data has to again fed back to the sound card so that it can be listened by plugging-in a headphone.
I've used Microsoft Visual C++ 6.0 as a platform and DirectX commands for capturing the soundand processing it.This part(CApturing and processing) works well ,but i'm not able to stream the data back to the card.
Can anyone help me in this or refer to any directx programs which does this kind of an process.
Thank You In Advance
Rajeev
|
|
|
|