69,371
社区成员
发帖
与我相关
我的任务
分享
void func_1(void)
{
printf("func_1");
}
void func_2(void)
{
printf("func_2");
}
void func_3void)
{
printf("func_3");
}
typedef void (*fun)(void);
map<string, fun> func_map;
map<string, fun> create_func_map()
{
#define insert_func_entry(map, func) map.insert(pair<string, fun>(string(#func), func))
insert_func_entry(func_map, func_1);
insert_func_entry(func_map, func_2);
insert_func_entry(func_map, func_3);
// ...
return map;
}
void call_by_string(const string& fun_name)
{
map<string, fun>::iterator find_result= func_map.find(fun_name);
if (find_result != func_map.end())
((*find_result).second)();
}
int _tmain(int argc, _TCHAR* argv[])
{
call_by_string(string(argv[1]));
system("PAUSE");
return 0;
}
#include <Windows.h>
#include <process.h>
extern "C" {
__declspec(dllexport) void func_1(void)
{
printf("func_1");
}
__declspec(dllexport) void func_2(void)
{
printf("func_2");
}
};
int _tmain(int argc, _TCHAR* argv[])
{
typedef void (*fun)(void);
fun pfun = NULL;
pfun = (fun)GetProcAddress(NULL, argv[1]);
if (pfun)
{
pfun();
}
else
{
printf("no such function!\n");
}
system("PAUSE");
return 0;
}