开发者

Using C# dll in Windows phone 7

开发者 https://www.devze.com 2023-01-27 13:50 出处:网络
I\'ve tried using C# dll in Windows phone 7 but it occurs error after start debugging as illustrated below.

I've tried using C# dll in Windows phone 7 but it occurs error after start debugging as illustrated below.


Troubleshooding tips: If the access level of a method in a class library has changed, recompile any assemblies that reference that library. Get generral help for this exception.


This is the code..

-----------------Windows Phone 7-----------------------------------------------

using System;
...
using System.Runtime.InteropServices;

namespace DllLoadTest
{
    public partial class MainPage : PhoneApplicationP开发者_StackOverflow社区age
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        [DllImport("MathLibrary.dll")]
        public static extern int AddInteger(int a, int b);

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("test " + AddInteger(3, 4));
        }
    }
}

------------------------C# MathLibrary.dll----------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MathLibrary
{
    public class Add
    {
        public static long AddInteger(long i, long j)
        {
            return i + j;
        }
    }
}

is there any problem? if not, using C# dll for WindowsPhone7 is impossible? The C# Dll loaded well in visualstudio2008 C#.


Why are you trying to use P/Invoke on a class library written in C#? Just add a reference to the DLL and use it directly:

using MathLibrary;
...

private void button1_Click(object sender, RoutedEventArgs e)
{
    MessageBox.Show("test " + Add.AddInteger(3, 4));
}

You can't use P/Invoke in Windows Phone 7, but you can use class libraries (built for Windows Phone 7).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号