c++callback回调实例
靜態(tài)庫(kù)文件:
Func.h:
#ifndef _Func_H
#define _Func_H
#endif
#include "stdafx.h"
#include<iostream>
using namespace std;
typedef int(*pFunc)(int parameter1, int parameter2);
void MyCallBack(string content,pFunc function);
?int Add(int parameter1, int parameterb);
Func.c:
#include "stdafx.h"
#include "Func.h"
?int Add(int a, int b)
{
?int sum = a + b;
?return sum;
}
?void MyCallBack(string content, pFunc function)
?{
? int re = (int)function;
? printf("content=%d", re);
?}
控制臺(tái)調(diào)用程序:
// Test.cpp : 定義控制臺(tái)應(yīng)用程序的入口點(diǎn)。
//
#include ".\\Func.h"
#include "stdafx.h"
#include <iostream>
#ifndef _Func_H
#include ".\\Func.h"
#endif
int fs(int a, int b)
{
?return a - b;
}
//
//#import "..\debug\MyCom.dll" no_namespace
#pragma comment(lib,"./MyLib.lib")
int _tmain(int argc, _TCHAR* argv[])
{
?int sum = Add(2, 4);
?printf("sum=%d", sum);
?MyCallBack("this is my callback", (pFunc)fs(7,2));
?//CoInitialize(NULL);
?//CLSID clsid;
?//CLSIDFromProgID(OLESTR("myCom.GetRes"), &clsid);
?//CComPtr<IGetRes> pGetRes;//智能指針?
?//pGetRes.CoCreateInstance(clsid);
?//pGetRes->Hello();
?//pGetRes.Release();//
?//CoUninitialize();
?return 0;
}
總結(jié)
以上是生活随笔為你收集整理的c++callback回调实例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: STL中map和string, vect
- 下一篇: Aspose.Cells.dll操作ex