Skip to content

Instantly share code, notes, and snippets.

@tsukkee
Created January 26, 2011 10:44
Show Gist options
  • Select an option

  • Save tsukkee/796545 to your computer and use it in GitHub Desktop.

Select an option

Save tsukkee/796545 to your computer and use it in GitHub Desktop.
A wrapper function for AfxBeginThread
// [Reference]
// Cのコールバック関数をC++のメンバ関数にバインディングする方法 - kazuhoのメモ置き場
// http://d.hatena.ne.jp/kazuhooku/20110126/1296031454
template <typename T, UINT (T::*THREAD_PROC)()>
UINT ToThreadCallback(LPVOID pParam)
{
return (static_cast<T *>(pParam)->*THREAD_PROC)();
}
// [Example]
class Klass {
public:
Klass() {
::AfxBeginThread(ToThreadCallback<Klass, &Klass::ThreadProc>, this);
}
protected:
UINT ThreadProc() {
// ...
return 0;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment