|
thanks for your reply. But I want to know the event by which I come to know whether file gets attached or not so i can move further for processing.
Any kind of idea will be helpful.
SNI
|
|
|
|
|
Yeah, it's a bit different than just launching outlook with a parameter when you use COM.
Here's some VBA that will start Outlook, create and send an e-mail.
Dim o As Object 'will be an Outlook.Application
Dim msg As Object 'will be a MailItem
Set o = CreateObject("Outlook.Application")
Set msg = o.CreateItem(0)
msg.Subject = "this is my subject"
msg.attachments.Add "path to the attachment"
msg.body = "my message"
msg.Recipients.Add "an e-mail address"
msg.send
You can replicate that relatively easily using the #import approach to interfacing with Outlook.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
C++ code for the VBA I posted - note that it's pretty much a direct translation...
#import "progid:Outlook.Application" auto_search
int main(int, char**)
{
try
{
CoInitializeEx(0, COINIT_APARTMENTTHREADED);
Outlook::_ApplicationPtr ol(__uuidof(Outlook::Application));
Outlook::_MailItemPtr msg(ol->CreateItem(Outlook::olMailItem));
msg->Subject = "this is my subject";
msg->Attachments->Add("path to the attachment");
msg->Body = "my message";
msg->Recipients->Add("an e-mail address");
msg->Send();
}
catch (_com_error& e)
{
std::cerr << (char*)e.Description() << std::endl;
}
return 0;
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Here is the code snippet.
class Super
{
public:
Super(){}
virtual void someMethod() {cout<<"in Super class"<<endl;}
};
class Sub : public Super
{
public:
Sub();
virtual void someMethod(){cout<<"in Sub class"<<endl;}
};
Sub mySub;
Super& ref =mySub;
ref.someMethod();
I don't really understand how the compiler works when it comes to the statement ref.someMethod(); . I guess the compiler first find someMethod() method in the Sub class. If doesn't find, then enter base class---Super class to find it.
above explanation is correct?
------------
If altering someMethod() in Sub class like this:
virtual void someMethod(int i){cout<<"in Sub class"<<endl;}<br />
what happens when the compiler runs ref.someMethod(); statement?
Obviously the output is "in Super class".
------------
If the someMethod() in Sub class is
virtual void someMethod(int i = 1){cout<<"in Sub class"<<endl} <br />
when the compiler runs ref.someMethod(); statement,what is the output?
In VS 2005,the output is "in Super class". I feel it is hard to understand,I believe the right result is "in Sub class".
Anyone could give me some idea,thanks in advance.
sharion
|
|
|
|
|
This feature is called run-time linking.
Based on the current type of the object the function call is resolved. So in first case the output is printed as "in Sub class" ie when function signatures in super and sub are same
When the function signatures are different, and the call is with a int parameter, it would look for a match which is defined in super and function is only available from the base part. So it calls the base class function
So obviously the compiler would say, I can not see it and I dont know what to call for and calls the base class exact match function for the remaining two cases.
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
modified on Thursday, April 16, 2009 1:34 AM
|
|
|
|
|
Hi,
sharion wrote: If doesn't find, then enter base class---Super class to find it.
above explanation is correct?
- Here you are littlebit right, but virtual keyword doing magic here,
sharion wrote: when the compiler runs ref.someMethod();
Basically there is two type of binding
1. Run-time binding (or late binding)
- if same function define in parent class with same signature and it virtual, then compiler ignore it for run-time, and run time function will be called using VPTR and VPTABLE.
2. Compile-time binding (or erly binding)
- if above is not a case then compiler resolve binding at compile time only.
Parag Patel
Sr. Software Eng, Varaha Systems
|
|
|
|
|
sharion wrote: If the someMethod() in Sub class is
virtual void someMethod(int i = 1){cout<<"in Sub class"<<endl}
when the compiler runs ref.someMethod(); statement,what is the output?
In VS 2005,the output is "in Super class". I feel it is hard to understand,I believe the right result is "in Sub class".
No, the compiler is correct. In this case, there are two possible functions matching ref.someMethod() . The C++ Standard defines rules by which the compiler can decide which is the best match. These rules specify that a function with no parameters is a better match than a function with a parameter which has a default value. The fact that one of the methods is implemented in the derived class and one in the base class has no impact.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I have a problem of number formatting
I made a function to convert from number to string.
and I used "stringstream" class for converting.
like this
string strText;
stringstream ssBuf;
ssBuf<<55555;
ssBuf>>strText;
I expect "55555" as result. but the result is "55,555".
How do I remove thousand seperator "," in string?
Thanks.
cozyu
modified on Wednesday, April 15, 2009 10:25 PM
|
|
|
|
|
Your locale[^] is getting in the way.
You need to tell the stringstream to use a locale without number punctuation. The simplest way to do that is to just use the std::locale::classic() locale like this:
std::string strText;
std::stringstream ssBuf;
ssBuf.imbue(std::locale::classic());
ssBuf<<55555;
ssBuf>>strText;
However, this loses any other locale-specific properties, so you might just want to use the number punctuation bit of the classic locale, like this:
std::string strText;
std::stringstream ssBuf;
std::locale l;
l = l.combine<std::numpunct<char> >(std::locale::classic());
ssBuf.imbue(l);
ssBuf<<55555;
ssBuf>>strText;
The combine method call copies your global locale and replaces the copy's number punctuation facet with the classic locale's number punctuation facet.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Great reply, got my 5
Don't you consider writing an article for CP ? I think you could bring really valuable things
|
|
|
|
|
Cedric Moonen wrote: Great reply, got my 5
Cheers
Cedric Moonen wrote: Don't you consider writing an article for CP ?
There are a few things I've got that I've thought about writing up. Trouble is, I'm lazy It's a good attribute for a developer, as it means you're more likely to use someone else's code than write your own, but not so great for article writing!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote: Your locale[^] is getting in the way.
Mine is set to use commas, yet I see 55555 when using the OP's code snippet.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Yeah, so did I, but as locales are the only thing that affect stream output like that, it seems likely that locales were the issue. Anyway - I suspect your default C++ locale (which isn't necessarily the same as what your regional settings say!) is set to "C", a.k.a the 'classic' locale, like mine.
No, I don't know what sets the default C++ locale...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thank you for your help
I'm always feel insufficiency about <locale> library.
Could you share your knowledge about the 'locale'.
It's always big problem of me.
I think the article about 'locale' is very valuable thing.
Thanks!
|
|
|
|
|
I have a C/C++ program (yes, a mix of both) that acquires data from a hardware device and displays it in real time. I want to add some processing on the data as soon as I read it, but I want to make sure it doesn't slow down the data acquisition too much. Is there a utility that will measure how long a function takes or how often it is called?
I already use the Red Gate ANTS profiler for my .NET apps, but it doesn't work with native code. Also, any profilers I've tried tend to slow down the application quite a bit. Is there a way I can measure the execution time without affecting it too?
Or would it be best to use the clock() function from time.h to measure this?
Thanks,
Dybs
|
|
|
|
|
Hi,
I would not use external tools for this. They tend to be rather complex for the task at hand. Instead add a little piece of code.
Have a look at multimedia timers[^]; make sure you first determine their accuracy, it can be worse than 1 msec (up to 16 msec is common).
If that is not good enough, google for code that relies on the RDTSC assembly instruction.
|
|
|
|
|
To add to Luc's answer - I've always used the high-resolution performance counter[^] to time my code. I've got a class that encapsulates the whole process in an RAII fashion - something like:
class CTimer
{
public:
CTimer(std::string const& what) : what_(what) { QueryPerformanceFrequency((LARGE_INTEGER*)&freq_); begin_ = Now(); }
~CTimer() { end_ = Now(); ShowTime(end_ - begin_); }
private:
__int64 Now()
{
__int64 now;
QueryPerformanceCounter((LARGE_INTEGER*)&now);
return the time you calculated;
}
void ShowTime(__int64 deltaTime) { std::cout << "Doing " << what_ << << std::endl; }
__int64 begin_, end_;
__int64 freq_;
const std::string what_;
};
{
CTimer t("some message");
}
I've left out the involved bits (calculating time from QueryPerformanceCounter result and displaying the time nicely) as I don't have access to the code I wrote right at the moment.
Certainly don't use clock() - it's a milli-second timer.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks for the answers. The reason I mentioned clock() is precisely because it's a millisecond timer. I'm not certain exactly how fast the data acquisition is now, but I don't think it's any faster than once a millisecond. When I add my processing code, I'd like to get as accurate as I can on how much it affects the timing, if at all.
I was looking at the link from Luc and saw the reference to QueryPerformanceCounter . I've seen other references to it on CP, but haven't needed to use it yet. Looks like it should do what I need.
Thanks again for the suggestions,
Dybs
|
|
|
|
|
|
I am working with some C++ code (not my code, of course) that has a bunch of huge functions, which I would like to refactor. Does anyone know of a utility that will scan C++ source files and report the number of lines in each function?
Jim Scott
|
|
|
|
|
I think this one[^] will do that
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Tried CCCC on a MFC program and it choked on all the special defines (macros) one is using when dealing with the win32 API.
|
|
|
|
|
You could well be right - I used it on embedded system code, and we didn't have much 'macro magic'.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks. This is a nice tool, and it gives a lot more information than I expected.
|
|
|
|
|
Here is list of SLOC metric tools:
LOC Metrics - Alternative Tools[^]
Source Monitor[^] seems to provide what you need, as it can provide a quick overview of all methods and how many statements they have. Just create a baseline and right-click the baseline and choose "Display Method Metrics...."
Also I would recommend to use Doxygen to see call hierarchies and class diagrams.
|
|
|
|