我正在尝试使用自定义 .NET ref 类来控制按钮系统。它由添加到父窗体的类内的一个 PictureBox 组成。当它检测到点击时,它需要调用构造函数中指定的函数,该函数是父类内部的方法。
例如:
//in the custom class file
public ref class CButton {
private: void (*callingproc)(void);
public:
CButton(void (*cproc)(void)) {
callingproc = cproc;
}
button_dowork() {
//do our code to detect if the click was in the right place and call our proc
callingproc();
}
};
//in the form.h
void cp(void) {
//do our form work
}
void Form_CreateCButton() {
CButton^ t = gcnew CButtom(cp);
}
当我按照说明进行操作时,上面会导致“使用 &ns::form::cp 创建指向成员的指针”的错误,然后是“指向成员的指针对托管类无效”。有任何想法吗?