日期:2014-05-18  浏览次数:21370 次

如何通过Marshal.GetFunctionPointerForDelegate获取函数指针?
工作中遇到这样一个问题,需要在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.大家帮忙看看,谢谢。


 

------解决方案--------------------
已经沉了。。。。。。。
------解决方案--------------------
兄弟我也问题和你类似啊?
有人知道帮我也看看那
http://topic.csdn.net/u/20110215/17/10b4584b-17ef-4e6d-90ae-2f3b1eb15174.html