1
기능, 바인딩, C++ 및 관리 코드의 결합 : 관리되는 C++ 프로젝트 내에서나는 따라서 전달되는 함수 객체 (AuthenticateNotifyFunc)를 기대하는 C++ 기능이
class lc_Authenticate
{
public:
typedef enum {
kAbort,
kContinue
} lc_AuthenticateStatus;
typedef std::tr1::function<lc_AuthenticateStatus (const string &msg)> AuthenticateNotifyFunc;
bool Authenticate(lc_AuthenticateParams ¶ms,
AuthenticateNotifyFunc notifyFunc);
}
을, 나는를 시도하고있다 따라서 위의 함수에 전달할 매개 변수를 정의 :
public ref class Form1 : public System::Windows::Forms::Form
{
public:
lc_Authenticate::lc_AuthenticateStatus UpdateStatus(const string &msg)
{
<<DO SOMETHING>>
return(lc_Authenticate::kContinue);
}
void test()
{
string appKey, appSecret;
appKey = GetString(this->appKeyTextBox->Text);
appSecret = GetString(this->appSecretTextBox->Text);
lc_Authenticate dbauth;
lc_AuthenticateParams params(appKey, appSecret);
// DOESN'T COMPILE won't let me take address of member function
// or know about _1
lc_Authenticate::AuthenticateNotifyFunc func =
std::tr1::bind(&Form1::UpdateStatus, this, _1);
dbauth.Authenticate(params, func);
}
};
그래서 나는 그것이 전달 기능이 있는지 여부를 상관하지 않는 방식으로 방법 ++는 C에 함수를 전달하는 일반적인 방법을 구현하기 위해 노력하고 정적 또는 멤버 함수. 그리고 관리 코드에서이를 어떻게 수행해야하는지 명확하지 않습니다.
이 작업은 ['Marshal :: GetFunctionPointerForDelegate'] (http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.getfunctionpointerfordelegate.aspx)를 사용하여 수행 할 수 있지만 끔찍한 못생긴. _ 왜 이걸하고 싶니? C++ 코드와 C++/CLI 코드를 명확히 구분하는 것은 좋은 일입니다. 그들을 단단히 묶어두면 고통 스러울 것입니다. – ildjarn
관련 : http://stackoverflow.com/questions/163757/how-to-use-boostbind-in-c-cli-to-bind-a-member-of-a-managed-class –