Spyros Panaoussis
Spyros Panaoussis

Reputation: 3

Windows Phone 7 C# error Attepting to call function failed

I am writing a test project "HelloPhone" in c# Windows Phone 7 and i am trying to use a C++ DLL/clr. Well at execution i get an unhandled exception error reporting that attempt to call the DLL function failed. I am not a C# programmer so here is my code:

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(); 





        }
    }
}

Could you please tell me what i do wrong?

Thnk you. Spyros

Upvotes: 0

Views: 645

Answers (3)

Phil Winkel
Phil Winkel

Reputation: 48

yea duder, this kinda stuff probably isn't supported on WP7 (as far as I know):

using System.Runtime.InteropServices;

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

It's running on a compact version of the .net framework.

Upvotes: 0

Jess
Jess

Reputation: 42948

You probably won't be too happy to hear this, but using p/invoke or a C++/CLR DLL is not supported in Windows Phone 7.

Upvotes: 2

bendewey
bendewey

Reputation: 40265

Are you trying to get the DeviceFirmwareVersion or DeviceHardwareVersion? Can you just use:

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

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

Upvotes: 0

Related Questions