|
Please look in MSDN, CodeProject, google, ... ton of people did this already ...
Max.
|
|
|
|
|
what's the difference between a callback function and a function pointer? can anyone show me a short code snippet?
For example, here's a typedef and function pointer:
typedef void (*PostProcessFunc) (int&, ubt&);
void ProcessFunc(PostProcessFunc, int&, int&);
and is CALLBACK a keyword...?
For example:
HDDEDATA CALLBACK DdeCallback(uType, uFmt, hconv, hsz1,
hsz2, hdata, dwData1, dwData2)
I cant find CALLBACK statement/keyword from MSDN....
norm
|
|
|
|
|
CALLBACK is defined in many places, including windefs.h and wtypes.h.
for most people, i think it's probably defined as:
#define CALLBACK __stdcall
but, no there's no real difference between a what you use a function pointer for and what a callback function accomplishes. they both provide a way for one function to call another.
-c
“If it turns out that I’m actually the one who did it, then looking for the real killers would be a big old waste of time.”
-- OJ Simpson
|
|
|
|
|
Actually there is a difference. A function pointer can be used in an Object, a CALLBACK can't.
LPCTSTR Dutch = TEXT("Double Dutch ");
|
|
|
|
|
S van Leent wrote:
A function pointer can be used in an Object
care to expand on that ?
“If it turns out that I’m actually the one who did it, then looking for the real killers would be a big old waste of time.”
-- OJ Simpson
|
|
|
|
|
Ah, yes, I do care.
A function pointer could also point to a __thiscall function, meaning that it can be used as a non-static member of a class.
LPCTSTR Dutch = TEXT("Double Dutch ");
|
|
|
|
|
ah. true. (tho it looks like the original poster was asking about traditional windows CALLBACKs)
“If it turns out that I’m actually the one who did it, then looking for the real killers would be a big old waste of time.”
-- OJ Simpson
|
|
|
|
|
A CALLBACK or __stdcall, is a calling convention, just like _cdecl, __declspec, __fastcall and __thiscall. It is used to parse this to a function, who can use this to give data back.
A CALLBACK function cannot be used in an Object Oriented environment, so it is not recommended to use it in an OO-environment. Windows makes use of these functions so much, that it is an impossibility to name them all. The most common used CALLBACK (I think) is a Window Procedure, in the following form:
HRESULT CALLBACK WndProc(HWND, int, WPARAM, LPARAM);
LPCTSTR Dutch = TEXT("Double Dutch ");
|
|
|
|
|
BOOL CALLBACK EnumFontProc (LPLOGFONT lplf, LPTEXTMETRIC lptm, DWORD dwType, LPARAM lpData)
{
TRACE("Found a font named: %s\n", lplf->lfFaceName);
return TRUE;
}
EnumFonts (dc, 0,(FONTENUMPROC) EnumFontProc, (LPARAM)0);
-c
“If it turns out that I’m actually the one who did it, then looking for the real killers would be a big old waste of time.”
-- OJ Simpson
|
|
|
|
|
|
Thanks, norm,...I was wondering about the CALLBACKs too,...they seem like an anachronism. But, you see them used in virtually all windows code,...so, I assume that there must be an advantage to using this function. I'm wondering,...what exactly does the Visual C++ compiler do with them?
In Petzold's Programming Windows, the author states: The call-back function is a function in your program that is called from Windows. The best-known example of a CALLBACK function is the program's window procedure. You tell Windows the address of the windows procedure when registering the window class, and then Windows calls the function when sending messages to the program. Like a window procedure, a call-back function must be defined as CALLBACK because it is called by Windows from outside the code space of the program.
You know, I love geek-speak, but I'm not sure I understand it.
|
|
|
|
|
Nebulous Person wrote:
they seem like an anachronism
they're not an anachronism as much as they are a very powerful and advanced feature of C. yes they seem clumsy when compared to how you do similar things in C++, but Windows wasn't written in C++, it was written in C and Assembly.
in pure C++, you don't often need function pointers, since you can just pass an object and call members functions on that object; the object, in effect if not in reality, carries a function pointer for each of its member functions. but C has no "objects", so you have to pass the function pointers out in the open.
-c
“If it turns out that I’m actually the one who did it, then looking for the real killers would be a big old waste of time.”
-- OJ Simpson
|
|
|
|
|
Chris Losinger,
Ya know, I'm very new to C++ and Visual C++, but, I've found that reading the threads on this forum is probably the best source of information available to us 'code nitwits'. Thanks,...I appreciate the perspective. My brain is hemorhhaging intel.
|
|
|
|
|
You might want to check out all the recent C++ articles on creating delegates using STL, which are essentially a breed of C++-esque callback.
Though frowned upon in OOP, incidentally, you can use straight callback functions in C++. I've done it where a C program calls a DLL C function stub which is defined in a .cpp file, which in turn passes it onto an object instance, with a callback as a parameter. The C++ instance, after doing some work, later calls the callback. Pretty convoluted, but a project I worked on required it.
-- ian
"The greatest danger to humanity is humanity without an open mind." - Ian Mariano
http://www.ian-space.com/
|
|
|
|
|
How can I delete EOF in a file (in binary mode)?.
Thanks
|
|
|
|
|
you can't.
-c
“If it turns out that I’m actually the one who did it, then looking for the real killers would be a big old waste of time.”
-- OJ Simpson
|
|
|
|
|
I want to chek duplicate line in text file
Example:
If in "1.txt" has this data inside
50B82D3F9D3
2C051C76C7D
5804EBB2BB8
559AAC90CEE
DA64B9F10CC
B9A6A9866A9
AFF45E93F23
.
.
.
.
45788887454
B9A6A9866A9
This above text file has duplicate line
"B9A6A9866A9"
I want to write proram to check duplicate line.
Do you know how to do that? (Now I can use CStdioFile (ReadString, WriteString) and show Messagebox but not have idea to do that.)
Thank you for your answer.
|
|
|
|
|
is this for school ?
If you'd have to explain how to do this in your own words, without code, how would you anwser this, how would YOU solve the problem, once you know how to solve the problem, coding is easier. and it's from that point that I can/will help you !
Max.
|
|
|
|
|
two words: strcmp and fopen .
The rest is left as an exercise to the reader.
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
I would use ifstream to open the file, and then pass everything into a std::set, first checking if it is there. If it's there, I know that it is a duplicate, if all I want is to filter out duplicates, I am done. If I wanted to maintain order, I'd use a map and use the line number as the key.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
1) I have designed a primary Dialog Box, from which, on the selection of a menu command, i want to open another dialog box. In this case its just a File->Open command which should open a new modal dialog box to enter the filename/path. I added a new dialog by simply selecting one from insert->resource. I think i do need to define a new class for the dialog box, anyone agree? So once that has been done, how do i trigger the box from the main dialog? I was using something like
"CProgdlg::OnFileOpen{
CFildlg dlg;
dlg.DoModal();}"
but every time i compile or build it, it gives an error that the file (CFiledlg) is an undeclared identifier. Please Help.
2) Also, how does one make a set of multiple windows, like in installation file for programs, where a new dialog box is opened on pressing "next" and the earlier one is closed. The last box having "finish" instead of next, as always.
Cheers
Ayush
|
|
|
|
|
If CFildlg is a dialog you created you must #include "Fildlg.h" in this .cpp file. Otherwise if you meant to use MFC's CFileDialog then it is misspelled.
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
1) How about:
A) Looks like you misspelled "CFiledlg" in the 2nd line of code.
B) Did you #include the header file for your secondary dialog?
2) You want a wizard, and that's not in the scope of an explanation here.
------- signature starts
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
Please review the Legal Disclaimer in my bio.
------- signature ends
|
|
|
|
|
The code i gave was an example, so its not from the cpp file.
unfortunately, i forgot to include the header. Silly me, i think i must stop long hours of programming, its make me forget simple things.
Thanks a ton,
Ayush
|
|
|
|
|
Using Platform Builder 2.12 on Win2K:
I wrote a DLL which ciompiles and links fine, except that CEPB refuses to generate a LIB file. I've compaered this new DLL with other existing DLL's, and I can't find anything wrong with the setting (even the checkbox labelled "Do not create .LIB file" is NOT checked), and the compiler settings include a "/implib:My.DLL" command.
Anyone?
------- signature starts
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
Please review the Legal Disclaimer in my bio.
------- signature ends
|
|
|
|
|