我怎样才能投或升压转换绑定到C函数指针? [英] How can I cast or convert boost bind to C function pointer?

查看:95
本文介绍了我怎样才能投或升压转换绑定到C函数指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有这样的:

void func(WCHAR* pythonStatement) {
  // Do something with pythonStatement
}

和我需要将其转换为void函数(无效)是这样的:

And I need to convert it to void function(void) like this:

bind(func, TEXT("console.write('test')"))

现在我已经结构体是这样的:

Now I have struct like this:

typedef void (__cdecl * PFUNCPLUGINCMD)();

struct FuncItem {
PFUNCPLUGINCMD pFunc;
    // ...
};

如何设置我的结构的pFunc到绑定(FUNC,东西)?绑定回报lambda_functor不是一个函数指针,所以我怎么能施放此仿函数为一个函数指针?

How can I set the pFunc of my struct to bind(func, "something")? Bind returns lambda_functor not a function pointer, so how can I cast this functor to function pointer?

感谢。

最终使用<一个href=\"https://github.com/Ciantic/NppyPluginDll/blob/939cc865e90e9e15578d44228b6fdf69cf3b39f4/NppyPluginDll.cpp#L101\">the包装解决方案(GitHub上)

Ended up using the wrapping "solution" (GitHub)

推荐答案

我认为你不能,除非你得到的lamba_functor全局变量。

I think that you can't, unless you make the resulting lamba_functor a global variable.

在这种情况下,你可以声明调用它的函数:

In that case, you could declare a function that invokes it:

void uglyWorkaround() {
    globalLambdaFunctor();
}

和设置 pFunc uglyWorkaround()

修改结果
就在旁注:如果你是静态文本结合函数调用,您可以完全省略绑定()呼叫,只写:

void wrapper() {
    func(TEXT("console.write('test')"));
}

和设置 pFunc 包装()

这篇关于我怎样才能投或升压转换绑定到C函数指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆