【问题标题】:Windows Phone 7 C# error Attepting to call function failedWindows Phone 7 C# 错误尝试调用函数失败
【发布时间】:2011-04-26 20:19:34
【问题描述】:

我正在 c# Windows Phone 7 中编写一个测试项目“HelloPhone”,我正在尝试使用 一个 C++ DLL/clr。在执行时我得到一个未处理的异常错误报告,试图 调用 DLL 函数失败。我不是 C# 程序员,所以这是我的代码:

using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;
using Microsoft.Phone;
using DldesAPI;
using System.Runtime.InteropServices;

namespace DldesAPI
{
    public class DldesLib
    {

      [DllImport("DLDESLIB.dll", CharSet = CharSet.Auto)]
      public static extern int GetVersionNumber();

 //       [DllImport("DLDESLIB.dll")]
 //       public static extern int EncryptFirst(byte *pSrc,int SrcLen,byte *pDst,byte *pKey,int iKLen,long *wa,bool bRand);
    }
}

namespace HelloPhone
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        private void ClickMeButton_Click(object sender, RoutedEventArgs e)
        {


            int x = 0;
            string Msg;
            Msg=MessageTextBox.Text;

            x = 1;
            x = DldesLib.GetVersionNumber(); 





        }
    }
}

你能告诉我我做错了什么吗?

谢谢。 斯派罗斯

【问题讨论】:

  • 不是您问题的答案,但您应该知道,使用 InteropServices 会导致您的应用被市场拒绝。在今年晚些时候发布的“Mango”更新之后,您或许可以使用 InteropServices。

标签: c# windows-phone-7


【解决方案1】:

您可能不会很高兴听到这个消息,但在 Windows Phone 7 中是 using p/invoke or a C++/CLR DLL is not supported

【讨论】:

  • 谢谢安德鲁。我确实怀疑,但我寄予厚望,我错了
【解决方案2】:

是的,伙计,WP7 可能不支持这种东西(据我所知):

使用 System.Runtime.InteropServices;

[DllImport("DLDESLIB.dll", CharSet = CharSet.Auto)]

它在 .net 框架的紧凑版本上运行。

【讨论】:

  • 编译器没有问题 [DLLimport"DLDESLIB.dll")] 但在运行时代码无法访问定义为 DLL 函数的函数 DldesLib.GetVersionNumber()是问题所在。
【解决方案3】:

您是要获取DeviceFirmwareVersion 还是DeviceHardwareVersion?你能用吗:

DeviceExtendedProperties.GetValue("DeviceFirmwareVersion").ToString();

http://msdn.microsoft.com/en-us/library/ff941122(v=VS.92).aspx

【讨论】:

  • 不,我正在尝试连接一些从使用 /clr 选项编译的 DLL 导出的函数,但它是用 C++ 编写和编译的。如果我必须使用 C# 重写 DLL,我需要具有 C/C++“TStep”变量类型的等价物,并且我需要知道如何在运行时使用函数的地址加载这种变量跨度>
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多