|
Hi,
I have a function which returns a HRESULT. Not quite sure how they work, i know there is loads of constants and stuff for them. But I want to define a constant return value of my own. How do i go about this?
Cheers
Rich
|
|
|
|
|
An HRESULT is the only return permitted by COM, excepting a sleight of hand that I believe does not occur under C++, but VB and other languages for people easily confused. It is a complex structure, but in the first instance you can check using two macros, SUCCEDED() and FAILED, as in
HRESULT hr = pISomeINterface->SomeMethod();
if (FAILED(hr))
{
AfxMessageBox("You've stuffed it again !!!!");
return false;
}
Where did the function come from, and why do you want to change the return value ?
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
A completely useless anwser! It has nothing to do with the question asked.
|
|
|
|
|
This may be true, to the illiterate or truly stupid.
I'm still at a loss as to why we have pussies here who refuse to put their names to their posts, but I guess if you're going to insult people that would give you a reason to run and hide....
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
Your wit is to much for me, I leave in shame and disgrace.
|
|
|
|
|
If you want to make your own HRESULT you can use the MAKE_HRESULT macro.
Before you go playing with making your own you need to read some documentation on HRESULTS.
|
|
|
|
|
"Winerror.h" has the answers that you are looking for!
use MAKE_HRESULT macro. You may want to check if you
cannot convert your error by a predefined error type by
using the HRESULT_FROM_WIN32 macro.
Good luck!
|
|
|
|
|
Cheers, things are clearer now. I only want to flag to the user of my DCOM routine that the operation couldn't go ahead. So i just set the severity to information, to flag this. I kinda expected there would be a range where we could define our own. Doesn't look that simple though.
Thanks
Rich;)
|
|
|
|
|
How can I add hours ahead to a given date?
e.g., if the date time is now 16-July-2001 17:00:00 PM,
the expected date time is 16-July-2001 23:00:00 PM. (6 hours ahead)
The default DATE Arithmetic operators (-/+) in Visual C++ only apply to DAY.
How can I do so for HOUR?
STDMETHODIMP CMyLibrary::MyGetDate(DATE *MyGetDate)
{
SYSTEMTIME dDate;
GetLocalTime(&dDate);
DATE dTemp;
if (SystemTimeToVariantTime(&dDate, &dTemp) == 0 )
return Error("Conversion Error - MyGetDate");
/* This add one more DAY to a current date */
dTemp = dTemp + 1;
/* How can I add hours to a given date */
*MyGetDate = dTemp;
return S_OK;
}
|
|
|
|
|
if you want to add 2 hours you can use
dTemp += (1 / 24) * 2;
or for 5 hours
dTemp += (1 / 24) * 5;
Disclaimer: I have just written it, not tried to compile and run it, but it should work...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Thanks for your help, I have tried to test it,
but it still add DAYS instead of HOURS.
It seems the DATE + operator adds day with round-up figure:
dTemp = dTemp + 1.5 --> adds one day
dTemp = dTemp + 0.5 --> adds NONE
|
|
|
|
|
Strange, the DATE is an 8-byte floating-point number...
Maybe someone else knows something, I don't...
(Have never really used DATE...)
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Just add a CTimespan variable:
CTime x;
CTimeSpan hour(0,1,0,0);
x += hour;
LP
|
|
|
|
|
Take a look at _AfxOleDateFromTm and _AfxTmFromOleDate in 'olevar.cpp'(located in the MFC source directory). These should help you out adding an hour to a DATE variable.
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
Hi,
I've tried to define a friend class for the first time in my life, but it didn't work out the way I wanted it to...
There's a class of some sort and I defined another class (a dialog) as friend of that class, let's say:
class SomeOldClass()
{
friend class dlg_ShowPrivates;
public:
private:
CList m_list;
}
class dlg_ShowPrivates()
{
void SetClass(SomeOldClass * pClass)
{m_pClass = pClass};
void DoSomethingWithList()
{
m_pClass->m_list.blablabla; // Do something with the class
}
protected:
SomeOldClass * m_pClass;
}
The only error I get is on the line where I try to access m_list from m_pClass. I get the old;
cannot access private member declared in class SomeOldClass
But how come? The dialog is a friend, so should be able to access the privates of SomeOldClass, right?
Structured programming vs. chaotic mind boggling
|
|
|
|
|
OK, I've found the cause of this problem.
Apparantly the friend-class definition is valid JUST for the section in front of which you define it!
So this definition:
class SomeOldClass()
{
friend class dlg_ShowPrivates;
public:
private:
CList m_list;
}
defines dlg_ShowPrivates as a friend of the next section in the definition which is a PUBLIC section (which makes it a pretty stupid line of code).
For the desired effect you should define it as follows:
class SomeOldClass()
{
public:
friend class dlg_ShowPrivates;
private:
CList m_list;
}
Structured programming vs. chaotic mind boggling
|
|
|
|
|
Your explanation of the problem is wrong.
Friendship grant access to every section of the
class, regardless of where the "friend" line is
laid down.
You better recheck your code to see if you've made
any other change than that
|
|
|
|
|
I've compiled your code (with some syntactic
errors cleared out) and it works fine.
Are you sure the piece of code you're trying to put
to work resembles what you've posted?
|
|
|
|
|
aparently it doesn't, because the example works with you...
here's a stripped out version of the REAL class that wanted te have a friend..
class Class_Profile : public Class_Object
{
// PUTTING THE FRIEND DECLARATION HERE IT DIDN'T WORK
public:
Class_Profile(Class_Main * pMain);
~Class_Profile();
/* interface */
public:
// lots of functions here
/* end of interface */
/* methods */
protected:
// lots of methods
private:
// more methods
/* attributes */
protected:
// a couple of members
// PUTTING THE FRIEND DECLARATION HERE IT WORKED
private:
// lots of members, one of which the one I wanted to acces:
Class_Aggregation<class_display> m_Display;
};
Structured programming vs. chaotic mind boggling
|
|
|
|
|
well ,it definitely beats me. I see no reason why
the code will work locating the friend declaration
in a different line.
It'd help if you could post two real (ie, compilable)
projects showing both behaviors.
good luck joaquín
|
|
|
|
|
Hmmm, I tried to make a sample project which didn't work (in the way I described), but I couldn't do it, because it just works...
Ridiculously enough I then tried to restore my own code in the original project, so that it would produce the error again, but now it just works! I'm absolutely sure I'm doing everything in the same way I did it before, but I just can't get it to not-work anymore...
I must have seem a weird anomaly here, but thankt for the remarks! I was making wrong assumptions there, which was wrong. I'm glad it works now the way it should!
Structured programming vs. chaotic mind boggling
|
|
|
|
|
irreproducible error --> no error!
cheers
|
|
|
|
|
Hi
I have created a CListCtrl with the additional options as Hot
Track Selection & OneClick activate.
I have set the Hover time to 1 Second.
Now, When I try to point to any item ( Hover around 1
second ) then, I create a CRichEditCtrl on the fly on some
condition with some data on to it.
Now, whenever I change to focus to any other item and the
required condition is not satisfied , it waits 1 second to
destroy the earlier editbox .
I would like to remove the display of this editbox as soon as i
move the mouse to some other item.
Which Event should I call implement to do this??
Also, when i move to anyother item it immediately changes
to blue color. Pl. let me know which event gets fired here ?
Thanx in advance
regards
Sankar
|
|
|
|
|
You could subclass CRichEditCtrl, an make it destroy its self when it the mouse moves way from it. Better yet you could create a single CMyOwnRichEditCtrl and have it hidden to begin with, then just show it at the proper time... it could then just hide its self when its no longer needed.
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
I have developed an MFC application under Win 98 which handles the WM_CTLCOLOR message quite a lot to alter the color of the text etc.. This works fine on Windows 98 but when I ran it on Windows 2000 the WM_CTLCOLOR message wasn't being handled (or maybe it wasn't being sent?) and so all the colour has disappeared from my application!
Please could anybody tell me why this is happening.
David Osborn
|
|
|
|