如何通过Marshal.GetFunctionPointerForDelegate获取函数指针?

cfans1314 2011-02-16 10:42:33
工作中遇到这样一个问题,需要在c#托管代码中,调用函数指针。我在类中添加了一个自定义方法makerClick和一个委托ClickDeleage。
public delegate bool ClickDeleage();//单击标注委托对象
public bool makerClick() //单击标准事件
{
string currPosdes = ""; //当前位置兴趣点描述
MLonLat currMakerLonlat = new MLonLat();
currMakerLonlat.fLon = float.Parse(currPosition.Longitude.ToString());
currMakerLonlat.fLat = float.Parse(currMakerLonlat.fLat.ToString());
MREGEOCODESEARCHOPTIONS Option = new MREGEOCODESEARCHOPTIONS();
MReGeocodeSearchResult result = this.mapCtrl1.HttpPoiToAddress(currMakerLonlat, Option);
if (result == null)
{
currPosdes = ""; //为获取到该位置附近的兴趣点信息。
}
if (result.lNumOfRoundPoi == 1)
{
currPosdes = result.pRoundPois[0].cName;
}
if (result.lNumOfRoundPoi > 1)
{
currPosdes = nearestFind(result.pRoundPois, FromGpsToLonlat(currPosition)).cName;
}

StringBuilder makerText = new StringBuilder();
makerText.Append("当前经度:" + currPosition.Longitude.ToString());
makerText.Append("当前纬度:" + currPosition.Latitude.ToString());
makerText.Append("当前位置信息:" + currPosdes);
notification1.Caption = "当前位置信息";
notification1.Visible = true;
notification1.Text = makerText.ToString();

return true;
}


通过上边的委托和函数来获取指针,以下是我获取函数指针的过程:
makerClickdelegate mydelegate=new makerClickdelegate(makerClick);
IntPtr functionPointer = Marshal.GetFunctionPointerForDelegate(mydelegate);

可这样确报了一个NotSupportedException的错误,目标平台是mobile5.大家帮忙看看,谢谢。


...全文
913 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
hefajiang 2011-12-31
  • 打赏
  • 举报
回复
兄弟,我也碰到了类似的问题,期待高人帮忙解决
cfans1314 2011-02-17
  • 打赏
  • 举报
回复
是吧。我看看你的。
cfans1314 2011-02-16
  • 打赏
  • 举报
回复
恩,是啊,大家帮忙看看啊。
子夜__ 2011-02-16
  • 打赏
  • 举报
回复
已经沉了。。。。。。。
cfans1314 2011-02-16
  • 打赏
  • 举报
回复
自己刷新下,要不就沉了。
wty198505 2011-02-16
  • 打赏
  • 举报
回复
兄弟我也问题和你类似啊?
有人知道帮我也看看那
http://topic.csdn.net/u/20110215/17/10b4584b-17ef-4e6d-90ae-2f3b1eb15174.html

110,577

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧