【问题】
在C#中,想要把一个自定义的form变量:
downloadSongtasteMusic.frmDownloadSongtasteMusic
的指针,当做一个函数的参数,以此实现窗体指针变量的传递,结果出错:
Error 1 Cannot take the address of, get the size of, or declare a pointer to a managed type (‘downloadSongtasteMusic.frmDownloadSongtasteMusic’) D:\tmp\tmp_dev_root\downloadSongtasteMusic\downloadSongtasteMusic\downloadSongtasteMusic\completeHint.cs 22
【解决过程】
1.参考:
Cannot take the address of, get the size of, or declare a pointer to a managed type?
试试使用IntPtr,以及后来参考:
去添加unsafe,使用如下代码:
public partial class completeHint : Form { private string curFullFilename; private string curFolderPath; private IntPtr* curParentForm; public completeHint() { InitializeComponent(); } public unsafe void initParameter(IntPtr* parentForm, string fullFilename, string folderPath) //public void initParameter(string fullFilename, string folderPath) { curFullFilename = fullFilename; curFolderPath = folderPath; curParentForm = (frmDownloadSongtasteMusic *)parentForm; //Control curParent = this.Parent; //Form foundParentForm = curParent.FindForm(); //curParentForm = (frmDownloadSongtasteMusic)foundParentForm; //curParentForm.resetHintWindow(); }
但是结果还是出错,还是无法强制转换为所需要的frmDownloadSongtasteMusic变量。
【总结】
暂时放弃此条路。
换用其他方式,实现:
转载请注明:在路上 » 【未解决】Cannot take the address of, get the size of, or declare a pointer to a managed type xxx