|
You don't pass a function name as argument as another function but rather a pointer to a function:
First, you have to describe what is the 'type' of the function, for example:
typedef void (MyFunc*) (int,int);
This is a typedef that says that MyFunc is a type definition of a function returning nothing (the first void before (MyFunc*) ) and that takes two integer arguments (the argument list is specified after (MyFunc*) ).
Then, you can use MyFunc as a standard argument to a function:
void Do(MyFunc MyFuncThatWillBePassed)<br />
{<br />
}
This explain that the Do function will receive a pointer to a function of the type MyFunc as argument.
Inside your Do function, when you want to call your function, simply do that:
void Do(MyFunc MyFuncThatWillBePassed)<br />
{<br />
int a=0,b=0;<br />
MyFuncThatWillBePassed(a,b);<br />
}
Warning: you have to respect of course the type of the function and so you NEED to pass two integers (in our case) to your function otherwise you will have compile errors.
Hope this helps
|
|
|
|
|
it should be
typedef void (*MyFunc) (int,int);
|
|
|
|
|
Ooops... Sorry typo mistake
|
|
|
|
|
Hi
Thanx for all answers
by
KK
|
|
|
|
|
My Google skills are failing me this evening; does anyone have any examples or pointers for creating Sticky windows? Basically what I want is to create dialogs that stick to each other like Win Amp’s play list editor and its main dialog.
Any help is appreciated.
ZeePain! wrote: This seems like one of those programs that started small, grew incrementally, building internal pressure, and finally barfed all over its source code sneakers. Or something.
thedailywtf.com[^]
|
|
|
|
|
Tried a search on CP with "docking windows" ?
~RaGE();
|
|
|
|
|
Rage wrote: "docking windows"
Funny about a minute ago it dawned on me to change my search params. Low and behold there is all kinds of info. Gee
Thank you for the reply.
ZeePain! wrote: This seems like one of those programs that started small, grew incrementally, building internal pressure, and finally barfed all over its source code sneakers. Or something.
thedailywtf.com[^]
|
|
|
|
|
I have a .DBF file. Is it possible to do some database operation on this file using ODBC on some machine where SQL Server is not installed? If so can you show me a small code sample? (The application that i use is written in Visual C++ 6.0)
Thanks
Aljechin Alexander
|
|
|
|
|
ODBC is just an interface - it has no engine for SQL Server.
|
|
|
|
|
Google Web accelerator highlights prefetched links with a double-underline, but I dont see the web page being modified. I know this application is a BHO, so can someone tell me how can a BHO modify the look and feel of the web page?
PS: What is the difference between BHO and a add-on?
thanks!
|
|
|
|
|
A BHO can basically do whatever it wants :p
A BHO sits in the browser app, thats outside the page, and add-ons are embedded in the page. For that reason BHOs has a wider view of things.
|
|
|
|
|
I have a try/catch block that is throwing an exception. What are the different things I can find out about the exception? line number, exception type, etc?
thanks!
|
|
|
|
|
simply put - what u throw is what u get.
try/catch are not defined to give info like line numbers, only what was thrown.
to get more info u'll have to use SEH, but then u lose unwind semantics...
|
|
|
|
|
What I do is to buld a string containing the value of __LINE__ and pass this to a global ThrowError function which packages this into an object which throw can throw.
For example:
class CMyError : public CException {
public:
const char * Message;
};
and somewhere in the code:
static CString s;
s.Format("File %s, line %d\nOverflow in addition", THIS_FILE, __LINE__);
ThrowError(s);
where ThrowError puts its argument into Message in an instance of CMyError and throws the CMyError. So basically I can send any information I want to via a throw.
Shraddhan
|
|
|
|
|
1. Thanks for the suggestion, but I think that is not really what I want. If I know where to throw the error I know where the error is really happening. What I was looking for is line number for unexpected errors.
2. To __yb: I learnt that you can do all with C++ try/catch that you do with SEH through _set_se_translator. So if you can use SEH to get the instruction pointer that caused the error, you can obtain the same using C++ try/catch too.
3. For a suggestion to my own query, I can think of a _dirty_ way to obtain the line number in a try/catch or even with SEH. Before compiling the code write a script that will insert this statement after every line of code:
g_lineno = __LINE__;
and then in your exception filter, you can print this global variable g_lineno.
Now what I want to know from you guys is, whether this is going to be a performance hit if I implement it in production. I think _no_big_deal_ but what is your opinion?
thanks!
|
|
|
|
|
Brundiez wrote: Now what I want to know from you guys is, whether this is going to be a performance hit if I implement it in production. I think _no_big_deal_ but what is your opinion?
My understanding is that there are quite large overheads in doing a throw / catch. Also, what happens afterwards? Does the code keep running, or do you inform the user?
Either way, I reckon it is no big deal. Especially when you include the time taken to actually deal with the line number information. The cost of storing the line number in a global variable is nothing in comparison.
But I've just noticed that you say:
Brundiez wrote: Before compiling the code write a script that will insert this statement after every line of code
*Every* line of code? Do you *really* need to know so precisely?
Shraddhan
|
|
|
|
|
can anybody tell or give me some Visual C++ shortcut keys. I've been looking for shortkeys over the internet but I cant find one. Your help is greatly appreciated.
|
|
|
|
|
|
i write a activex and want to use it in word,and i want to capture the DocumentBeforePrint event so that i can prevent the word doc to be printed.what can i do?
|
|
|
|
|
My dialog program will start another dialog by pressing a button
Cxx dlg
dlg.DoModal();
In the Cxx dialog, I will create font by doing this
//Cxx.h
CFont m_font1;
//Cxx.cpp
//BOOL Cxx::OnInitDialog()
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT)); // Clear out structure.
lf.lfHeight = 25; // Request a 25-pixel-high font
lf.lfWeight = 700;
strcpy(lf.lfFaceName, "Arial"); // with face name "Arial".
m_font1.CreateFontIndirect(&lf); // Create the font.
The problem is that when I try to start the Cxx dialog second time.
The program will get error in creating the m_font1 again.
Please help!
|
|
|
|
|
|
Is it possible to destroy it.
Please help!
|
|
|
|
|
LaHaHa wrote: Is it possible to destroy it.
Yeah
m_font1.DeleteObject();
LaHaHa wrote: Please help!
My Pleasure
Jesus Loves <marquee direction="up" height="50" scrolldelay="1" step="1" scrollamount="1" style="background:#ffaaaa">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
Thank you very much!
I got it!
|
|
|
|
|
Hi
I want to ask you one think. How fancy GUIs for Windows applications such as MS Calculator plus, Norton system works, and other todays softwares having there own window, title bar, buttons, and other common controls, are created?
We Believe in Excellence
|
|
|
|