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
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.
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.
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
Related
overflow, im having trouble trying to add a ui framework , for exmple metro framework, to my c# form.
I know that i have to include the reference and include it with
using MetroFramework.Forms;
but im not sure what else to do here and when ever i try and google it, i just get websites that try and sell me a framework package.
Here is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MetroFramework.Forms;
namespace FrameworkTest
{
public partial class Form1
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
I know this may be a silly question but any help would be much appreciated.
Thanks to Crowcoder I found out that I was supposed to add
MetroForm after Form1 like:
public partial class Form1 : MetroForm {
//Code goes here
}
I got bug in my app and can not solve it.
Bug is - I can not use camera more than three times.
Code, that demonstrates it is here:
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using PhoneApp1.Resources;
using System.Windows.Media;
using Microsoft.Devices;
namespace PhoneApp1
{
public partial class MainPage : PhoneApplicationPage
{
PhotoCamera aCamera = new PhotoCamera(CameraType.Primary);
// Constructor
public MainPage()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
var cam = new camera_VM();
}
}
class camera_VM
{
public camera_VM()
{
VideoBrush __cameraView = new VideoBrush();
PhotoCamera aCamera = new PhotoCamera(CameraType.Primary);
__cameraView.SetSource(aCamera);
}
}
}
On third launch - it throws error:
{System.NotSupportedException: Specified method is not supported.
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.VideoBrush_SetExternalVideoPortSource(VideoBrush vb, String sPortName)
at Microsoft.Devices.Camera
Have no idea - what does it mean.
My guess that having Videobrush in code - bad idea, but have I another option? I got Grid in DataTemplate, that binds to VideoBrush object.
If I must properly dispose camera unit - can anyone tell me, how to do it right?
P.S. Code is just example, that fires an error.
I've a WPF program which it's MainWindows.xaml.cs has many functions and events. I want to make it more readable so I moved some of the functions and events in a separate class named "partialClassMainWindow.cs". I moved all button events to it. now when I click on a button it must go to button_Click function in partialClassMainWindow but a new funciton is created in MainWindows.xaml.cs.
how can I prevent it?
for example consider this simple program:
MainWindow.xaml.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication3
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
//moved to partialClassMainWindow:
//private void button1_Click(object sender, RoutedEventArgs e)
//{
//}
}
}
partialClassMainWindow.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
namespace WpfApplication3
{
public partial class MainWindow:Window
{
public void button1_Click(object sender, RoutedEventArgs e)
{
textBox1.Text = "Hello World";
}
}
}
Don't think that you can avoid it. It looks like Visual studio just checks the code behind file and not any other files with more partial code. But the other guys are right MVVM is the way to go and normally you have little or none code behind. Only typical view stuff you would handle there, all the business logic goes into the viewmodel.
http://msdn.microsoft.com/en-us/magazine/dd419663.aspx
Is a good place to start reading about MVVM.
I have got the error :
Error 24 Type 'X.volSays' already defines a member called 'volSays' with the same parameter types
The code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
namespace X
{
public partial class volSays : PhoneApplicationPage
{
public volSays()
{
InitializeComponent();
}
}
}
How do I fix this error ?
I have a simple window application I am starting and I was given another file I would like to bring into the new project. How do I bring them both together to work as one file?
New Project
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
Other
using System;
using System.Text;
using System.IO;
using System.Net;
namespace CaptchaClient
{
public static class SampleUse
{
public static void SampleSolve()
{
}
}
public class CaptchaSolver
{
}
public enum ResponseState
{
}
}
This screenshots shows the how yo do he procedure
Right click on your project in the Solution Explorer and click Add Existing Item. Then browse to the other class file. Once imported, you might want to change its namespace to the one you are using in your project.