dll中多线程使用回调函数

//dll头文件

#include <Windows.h>
#include <stdio.h>
#include <process.h>
#define MYLIBAPI extern "C" __declspec(dllexport);
typedef int (WINAPI *PFCALLBACK)(); 
MYLIBAPI void WINAPI TestCallBack(PFCALLBACK Func) ;
//dll源文件

#include "stdafx.h"
#include "CallbackDll.h"

PFCALLBACK gCallBack = NULL;
int WINAPI CBFunc(int Param1,int Param2);
ULONG WINAPI Thread1(LPVOID Param);

void WINAPI TestCallBack(PFCALLBACK Func) 
{ 
	if(Func == NULL)
		return; 
	gCallBack = Func; 
	DWORD ThreadID = 0; 
	HANDLE hThread = CreateThread(NULL, NULL, Thread1, LPVOID(0), NULL, &ThreadID); 
	return; 
} 

ULONG WINAPI Thread1(LPVOID Param) 
{ 
	int Step = 1;     
	(*gCallBack)();
	return 0; 
} 
//.cpp文件
#include "stdafx.h"
#include <Windows.h>
#include <stdio.h>
#include <process.h>
#include "../CallbackDll/CallbackDll.h"


int WINAPI CBFunc();
int _tmain(int argc, _TCHAR* argv[])
{
	TestCallBack(CBFunc);
	Sleep(100);
	return 0;
}
int WINAPI CBFunc() 
{ 
	printf(_T("ddddddddddddddddddddddd\n"));
	return 1;
}


阅读更多
个人分类: vc++ 个人笔记
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭