1

我正在使用教程中的代码库来提供将非静态成员函数的函数点传递给需要静态函数指针的函数的功能,这可能有助于了解我在起诉什么,所以这里是链接http:/ /www.codeproject.com/KB/cpp/thunk32.aspx此代码使用 Boost 库,我已经下载并设置了或多或少的所有内容。

在 Thunk 库中,其中一个头文件有一段读取

#define BOOST_PP_ITERATION_PARAMS_1 (3,(0,THUNK32_MAX_ARGS,"Thunk32_template.h"))
??=include BOOST_PP_ITERATE()
#undef BOOST_PP_ITERATION_PARAMS_1

但这给了我大量的错误,我可以通过将其更改为来解决

#define BOOST_PP_ITERATION_PARAMS_1 (3,(0,THUNK32_MAX_ARGS,"Thunk32_template.h"))
#include BOOST_PP_ITERATE()
#undef BOOST_PP_ITERATION_PARAMS_1

下载的这段代码作为第二个项目包含在我的解决方案中,它能够愉快地编译和构建。但是我使用此代码的项目存在链接问题,为了避免人们询问,我收到这些错误消息

1>WebCamera.obj : error LNK2019: unresolved external symbol "protected: __thiscall indev::Thunk32Base::Thunk32Base(void)" (??0Thunk32Base@indev@@IAE@XZ) referenced in function "public: __thiscall indev::Thunk32<class WebCamera,void __cdecl(struct HWND__ *,struct videohdr_tag *)>::Thunk32<class WebCamera,void __cdecl(struct HWND__ *,struct videohdr_tag *)>(void)" (??0?$Thunk32@VWebCamera@@$$A6AXPAUHWND__@@PAUvideohdr_tag@@@Z@indev@@QAE@XZ)
1>WebCamera.obj : error LNK2019: unresolved external symbol "protected: __thiscall indev::Thunk32Base::~Thunk32Base(void)" (??1Thunk32Base@indev@@IAE@XZ) referenced in function "public: __thiscall indev::Thunk32<class WebCamera,void __cdecl(struct HWND__ *,struct videohdr_tag *)>::~Thunk32<class WebCamera,void __cdecl(struct HWND__ *,struct videohdr_tag *)>(void)" (??1?$Thunk32@VWebCamera@@$$A6AXPAUHWND__@@PAUvideohdr_tag@@@Z@indev@@QAE@XZ)
1>WebCamera.obj : error LNK2019: unresolved external symbol _capCreateCaptureWindowA@32 referenced in function "public: bool __thiscall WebCamera::Init(struct HWND__ *)" (?Init@WebCamera@@QAE_NPAUHWND__@@@Z)

我认为这是想说构造函数和析构函数没有声明,而且我的 WebCamera.Init() 也搞砸了。我已确保 Thunk32 项目导出的库包含在我的其他项目中,但我仍然收到这些错误。

我想知道我是否做出了??=include应该更改为的正确假设,#include如果有,我做错了什么或没有做错什么会导致这些链接器错误。或者,如果您可以为我提供一种能够将函数指针传递给非静态成员函数的不同方式,那就太棒了。

谢谢

4

4 回答 4

3

??= is a "trigraph" sequence for the # character. according to the standard, trigraphs are supposed to be handled as one of the first steps in processing (in phase 1 - before the preprocessor handles directives),so:

??=include "whatever"

Should be equivalent to:

#include "whatever"

so you should be able to use that form (I wonder why the trigraph was put there in the first place - some sort of evil joke perhaps?)

However, trigraphs cause problems and confusion (probably more than they help), so compilers seem to be moving towards warning about them and/or defaulting to not handling them. The compiler in VS 2010 has trigraph processing turned off by default - you have to use the /Zc:trigraphs option to turn it on.

See Purpose of Trigraph sequences in C++? for more details.

于 2010-10-13T17:59:34.820 回答
2

啊,艾纳尔,好人。这些天在做 Flash 和 Sharepoint 的东西,哎呀。挪威语,可能会解释三字母组。

Anyhoo,没什么复杂的,您只是忘记告诉链接器查看一些库。右键单击您的项目,Project Dependencies,勾选 Thunk 项目。这可以确保 Thunk32.lib 被查看并解析 ctor 和 dtor。

再次右键,属性,链接器,附加依赖项,添加“winmm.lib”。这解决了 capCreateCaptureWindow 符号。

于 2010-10-13T19:54:58.970 回答
0

Ok, so I have managed to solve this now.

Michael Burr nicley said that ??= is basically the same as typing # but in a way that people who dont have the hash symbol can type it, see Purpose of Trigraph sequences in C++?

Hans Passant then got the ball rolling for me buy letting me know that I had not fully linked in stuff. I needed to right click on my main project, select 'Project Dependencies' and select my other project that has the thunk32 code. I also needed to tell my main project to look at where the Thunk project is saving the lib, which turned out to be in a folder in my documents (explain that one!). I also needed to add the Thunk32d.lib (note the 'd' because I was/am in debug mode. Hans said that I needed winmm.lib but it turned out (when googling the function that was giving me the error that I needed Vfw32.lib instead.

Thanks guys! I hope that by giving the full answer like this it can help some one else who has a similar problem.

于 2010-10-14T14:24:20.230 回答
0

您是否在 indev::Thunk32Base 类中声明了一个构造函数和一个析构函数,但忘记在其 cpp 文件中定义?

于 2010-10-13T17:49:17.477 回答