函数指针的例子(C++) #include <stdio.h> #include <malloc.h> int func(int a,int b) { return printf("%d/n",a+b); } int main() { int (*FunctionPionter)(int a,int b); FunctionPionter = func; (*FunctionPionter)( (*FunctionPionter)(100,12),1); return 0; } 回调的经典例子(C#) using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace WindowsFormsApplication1 { public delegate bool CallBack(int hwnd, int lParam); public partial class Form3 : Form { public Form3() { InitializeComponent(); } [DllImport("user32")] public static extern int EnumWindows(CallBack x, int y); public static bool Report(int hwnd, int lParam) { Console.Write("Window handle is "); Console.WriteLine(hwnd); return true; } private void button1_Click(object sender, EventArgs e) { CallBack myCallBack = new CallBack(Report); EnumWindows(myCallBack, 5); } } } 回调的经典例子(C++) #include <stdio.h> #include <windows.h> BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM p) { printf("the handle is %d/n",hwnd); return true; } int main() { EnumWindows(EnumWindowsProc,0); return 0; } 多线程的例子 #include <stdio.h> #include <malloc.h> #include <string.h> #include <windows.h> DWORD WINAPI DaYin(__in LPVOID lpParameter) { for (int i=0;i<100;i++) { printf("%d/n",i); } return 0; } int main() { DWORD a; HANDLE h= CreateThread(NULL,NULL,DaYin,NULL,NULL,&a); printf("New ThreadID is %d/n",a); Sleep(10); printf("Main Thread is Over/n"); WaitForSingleObject(h,INFINITE); printf("second Thread is Over/n"); return 0; }