|
You need to know what prototype it should be, then
you either declare it global or as a static class member.
returntype CallbackFn(params)
{
// Handle stuff in here.
}
Then you use 'CallbackFn' as param where te 3'rd party lib wants
a callback function.
/Magnus
|
|
|
|
|
Its (somewhere) in the MSDN, an example of a function in a class as a callback function for Multi-threading. First, create a separate function that is "static" (for thread use, UINT <funcname> (LPVOID)):
class MyClass
{
..
// Callback Function
static UINT MyCallBackFunc (LPVOID lpData);
// Actual Function
void MyFunction ();
..
}
UINT MyClass::MyCallBackFunc (LPVOID lpData)
{
MyClass *pMC = (MyClass *) lpData;
if (pMC)
pMC->MyFunction ();
}
// Use of the callback function - AfxBeginThread is a member of CWinThread
..
AfxBeginThread (0, MyCallBackFunc, this);
..
when assigning the callback function, use the MyCallBackFunc passing the instance of the class as the parameter.
this is just an example to give you an idea; better look for the actual code (I'm not 100% sure with this one. gud luck.
|
|
|
|
|
I edited the string in the string resource of my MDI project. In the fourth (tried the 5th place too) place I put \nCoin Project (*.coi), which according to my example should have opened the file/open dialog with a filter of *.coi. However it always says All File (*.*).
ANy suggestions? Is there a direct way by code we can do this?
Thanks in advance,
ns
|
|
|
|
|
I believe that, in C++, if a function may throw an exception, you should declare it like this:
<br />
int myfunc() throw (CMyException);<br />
The problem is that VC (even .NET) issues a warning that it disregards my declaration as the ANSI standard is not very specific when using functions that throw exceptions. In fact, I think the function may very well throw an exception of another type, not the one declared.
The question is:
Do you decorate your function declarations with an exception specification or don't bother since it does not matter. Why? Because it is good design? Also, if you do, do you use the throw (CMyException) both in the header and the implementation file?
Best regards,
Alexandru Savescu
|
|
|
|
|
The function my thow any other exception, but if it do so your aplication will be terminated because the 'unexpected' handler will be called witch by default call 'terminate'. To set your own handler you can call 'set_unexpected()'.
For a more deep perspectiv on exception you can see "Deep C++" in MSDN
Bye,
Orbital^
...the night is long ... but not long enought to do some real coding ...
|
|
|
|
|
Are you saying that if I do:
void f () throw (MyException)
{
throw OtherException();
}
void g()
{
try
{
f();
}
catch (MyException)
{
}
catch (OtherExcepion)
{
}
}
my application will be terminated. I doubt it!
Best regards,
Alexandru Savescu
|
|
|
|
|
In ANSI C++ the program will be terminated but as Visual C++ documentation say : "A function is declared using exception specification, which Visual C++ accepts but does not implement". If you want to write compatible code you should respect ANSI specification.
MS say : "Code with exception specifications that are ignored during compilation may need to be recompiled and linked to be reused in future versions supporting exception specifications."
Bye,
Orbital^
...the night is long ... but not long enought to do some real coding ...
|
|
|
|
|
Alexpro wrote:
The question is:
Do you decorate your function declarations with an exception specification or don't bother since it does not matter. Why? Because it is good design? Also, if you do, do you use the throw (CMyException) both in the header and the implementation file?
Exception specifications in C++ are broken. If you specify a function as having an exception specification (and if the compiler conforms to the standard) then any exception that the function throws that isn't in the specification causes the unexpected exception handler to be called which defaults to terminating the program.
This is considerably different to how they work in Java. Java has static checking of exception specifications which means that you can't write a function that calls another function yet doesn't either handle the exceptions specificed in the other functions exception specification or declare that exception in its own exception specification. It's a complex problem to make a C++ compiler do this static checking as it would most probably need sight of all source used for a start as there's probably not enough information in the resulting object files. There's then the issue of whether it's a good idea to have it do that checking...
In Java it's often a pain to have to modify lots of code when a library changes its exception spec. It wouldnt be so bad if the callers actually did stuff with the new exception, but often they don't, they just pass it on up the chain. Of course if each library caught every exception and translated the appropriate ones into their own more descriptive exceptions then that wouldnt be so bad, but you can find yourself upgrading a library and suddenly having to deal with 'blah.blah.sublibrary.we.now.use.exception' which, as I said, is a pain. If everyone did the right thing it would possibly be a good thing and add value, but people, being people, dont, and it isn't.
So, my view is that in Java it's a pain and isn't used properly and in C++ it's a liability and should be avoided at all costs unless you want your programs to just terminate randomly. To write robust code in C++ using exception specs you would need to wrap all access to any code that you didnt have sight of the source of in a try/catch block which translated all exceptions into something you knew. If one developer fails to do that in one library anywhere in your source tree then your program may just decide to exit. To be really sure you'd have to wrap ALL code in such a block. This isn't really such a bad thing, it may look nice to have that kind of rule on your coding standard, but IMHO it sucks Part of the nice thing about exceptions is that you dont need to fill each function in the call stack with error handling gunk which obscures the purpose of the real code. Most of the time you can let exceptions flow up through your code unobstructed. If you expect them, and can deal with them here, fine, you can do so. If you dont then as long as you deal with them at key places (COM interface boundaries, thread/process boundaries, etc) you can write robust code that handles even the most unexpected of exception in a graceful and recoverable (well you can try) manner.
In VC++ at present it's even worse than that as it doesn't enforce them, so they may as well just be a comment with interesting syntax and you really don't want to get me started on comments
Len Holgate
www.jetbyte.com
The right code, right now.
|
|
|
|
|
I have a subclassed static control that I want to display samples for a custom Font Dialog. Ofcouse when I set the LOGFONT lf.lfcharset to a character set, it wil not draw the text in that character set... I have searched MSDN with no "easily explained" luck. Can anyone help me, smaple code maybe? Thanks.
<><><><><><><><><><><><><><>
Matthew R. Miller
mattrmiller@computersmarts.net
www.computersmarts.net
|
|
|
|
|
The following code does not save a web page with .mht extension containing images but works fine otherwise .
UINT readfilethread ( LPVOID param )
{
data *d = ( data* ) param ;
char *buff = new char[1024] ;
CFile fp ;
fp.Open ( d -> target, CFile::modeCreate | CFile::modeReadWrite ) ;
int bytes ;
const char ch = '\0' ;
while ( bytes = d -> phttpfile -> Read ( buff, 1023 ) != 0 )
{
fp.Write ( buff, 1023 ) ;
for ( int i = 0 ; i < 1023 ; i++ )
buff[i] = 0 ;
}
fp.Close( ) ;
delete d ;
delete[ ] buff ;
return FALSE ;
}
Can any one suggest me a solution for the probelm for saving images as well ?
Samir Sood
|
|
|
|
|
Hi,
I would like to play with GDI+ but I don't have time to download the core SDK, I need just GDI+ files. what can I do. does anyone have these files where I can download it?
One more thing. How I can use GDI+ in MFC apps?
|
|
|
|
|
Williams wrote:
One more thing. How I can use GDI+ in MFC apps?
They co-exist fine. But you need to get the entire SDK, everyone who tries it with a portion ends up in trouble.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
|
|
|
|
|
Where can I find a DB2 CLI function C++ class wrapper?
thanks!
|
|
|
|
|
Just downloaded a Lib at
http://www.geocities.com/skuchin/otl/home.htm
that says to handle that. Don't know if it works...
|
|
|
|
|
Is here any CListCtrl Class Support Printing???
please help me
Renjith-CPian.
|
|
|
|
|
can you clarify your question further
is it like u have a list view & u need printing support for it
if it is the same & u need it in mfc i think i can help u
surbinsho
|
|
|
|
|
See my reply to your previous note.
/ravi
Let's put "civil" back into "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
ok i have a class which prints the listview (report view) in WYSIWYG format
i'll be posting it as an article soon or be mailing it to u
so plz keep on checking the message board
surbinsho
|
|
|
|
|
hi
check this link
http://www.codeguru.com/listview/lcprinting.shtml
surbinsho
|
|
|
|
|
I'm trying to catch an enter keypress from a single-line CEdit control in a dialog class. My solution is a hack which I presume won't with with non-CEdit controls. Can anyone suggest a cleaner way to do this?
My current solution is:
1. Derive control from CEdit
2. Set control style to multiline, want-return
3. Override OnChar:
// Grab that enter key
if (nChar == '\r') {
CWnd *pParent = GetParent();
if (pParent) {
::PostMessage (pParent->GetSafeHwnd(), WM_ENTERPRESS, 0, (LPARAM)GetDlgCtrlID());
}
}
else {
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
4. Parent dialog box watches for the WM_ENTERPRESS message with lParam equal to the control's ID.
Thanks.
|
|
|
|
|
|
Hi,
I have a developed large Project which consist of around 200 clases.
I want to reverse-Engineer this project.I developed the code in VS 6(VC++).
I used Visio but the only relation it showed was inheritence between classes.
I Dunno whether i used correct option.If any idea please express it.
I also used Visual Modeler with comes with VS 6 but there was no option for VC++ code.It gave option for VB only..
so any one has any idea how to reverse engineer so thst i can get full realtions between class
cheers,
Super
------------------------------------------
Too much of good is bad,mix some evil in it
|
|
|
|
|
|
Christopher Duncan wrote:
The only thing that comes to mind is Rational Rose, but it ain't cheap...
Well Cost is not the problem becos i have the necessary software.I just want to whether it is possible from Rational Rose and will it give full class realtionship?.
cheers,
Super
------------------------------------------
Too much of good is bad,mix some evil in it
|
|
|
|
|
super wrote:
will it give full class realtionship?
I don't have any personal experience with the product, but I've heard it's pretty full featured. That's why I included a link to their site, I'm sure they have a lot of information there about product functionality. Wish I knew more to tell you, but I hope this helps.
Chistopher Duncan
Author - The Career Programmer: Guerilla Tactics for an Imperfect World (Apress)
|
|
|
|