【发布时间】: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