views:

71

answers:

4

I am using a library of code from a tutorial for providing functionality for passing function points of non-static member functions to a function that expects a static function pointer, probably helps to know what I am suing, so here is the link http://www.codeproject.com/KB/cpp/thunk32.aspx This code uses the Boost library, which I have downloaded and set-up more or less everything from.

In the Thunk library, one of the header files has a section that reads

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

but this gives me epic amounts of errors, which I can solve by changing it to

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

This code that is downloaded is included in my solution as a second project, which is able to compile and build happily. But my project that is using this code has issues linking, to save people asking, I get these error messages

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)

I think this is trying to say that the constructor and destructor are not declared and that my WebCamera.Init()is messed up as well. I have made sure that the library that the Thunk32 project exports is included in my other project, but still I get these errors.

I would like to know if I have made the correct assumption that ??=include should have been changed to #include and if I have, what have I done wrong or failed to do that results in these linker errors. Or if you can provide me with a different way of being able to pass a function pointer to a non-static member function that would be awesome.

Thanks

A: 

Do you have a constructor and a destructor declared in the indev::Thunk32Base class that you forgot to define in its cpp file?

Michael Goldshteyn
yer, indev::Thunk32Base has both structors, they are already part of the code from the article. I am not getting any compile errors, just the link errors I mentioned
thecoshman
you wouldn't get compile time errors for missing function definitions. You would only get link time errors such as the ones in your original question, so please make sure that the functions aren't just declared, but are also **defined**!
Michael Goldshteyn
Yes they are defined
thecoshman
+3  A: 

??= 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.

Michael Burr
So... should that change not matter (Actually being beneficial as it lets the compile work properly) From what you said, I shouldn't bother trying to enable trigraphs as its not going to make a difference.
thecoshman
@thecoshman: I think you're right.
Michael Burr
+2  A: 

Ah, Einar, good man. Doing flash and Sharepoint stuff these days, ouch. Norwegian, might explain the trigraphs.

Anyhoo, nothing complicated, you just forgot to tell the linker to look at some libraries. Right-click your project, Project Dependencies, tick the Thunk project. That makes sure that Thunk32.lib gets looked at and resolves the ctor and dtor.

Right-click again, Properties, Linker, Additional dependencies, add "winmm.lib". That resolves the capCreateCaptureWindow symbol.

Hans Passant
As delightfully happy your answer, sadly it did not fix my issues the same linker errors are coming up... I may have juggled the output folder for Thunk, but I also married up the folder as input for my other project lib include folder things... any hoops, sleep must be had. I look forward too more help, thank you so much for the help dude
thecoshman
ok, so Imanaged to fix two of my link errors. I did as you said, with no diferance, then noticed that Thunk32 was building a debug version, so I added Thunk32d.lib to additional dependencies . Now I just need to sort my third link error from my question.
thecoshman
A: 

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.

thecoshman