venerdì 19 dicembre 2008

iPhoneUI on msdn

Now you can find my iPhoneUI (codeproject article) on the msdn.
here[^], take a look.

iPhoneUI on codeplex

Many thanks to dkackman that add my iPhone UI to codeplex.
He put a modified version up on codeplex and begins a fascinating trip into it.
You can find it directly here: http://www.codeplex.com/iPhoneUI/[^] take a look.

lunedì 15 dicembre 2008

OfficeServ Unico is out

OfficeServ Unico is one of my last work on mobile.
TELCEN (my company) prepared for Samsung a commercial software that turns smartphone into a single terminal capable of handling all types of communications, GSM-UMTS-HSDPA and VoIP.

I'll add the direct link to Samsung, where you can see the product, here[^].

sabato 13 dicembre 2008

martedì 9 dicembre 2008

String & P/Invoke with C#

Sometime I hear about c# problem with the P/Invoke and string.
Here I add a very simple usage of it, it describe C++ CString and c# String.

1. SetWindowText
First I begin with a sample really simple. How to set a string of a dialog. I invoke the SetWindowTextW.
You can define this for mobile app
[DllImport ("coredll.dll", EntryPoint="SetWindowTextW")]
private static extern void SetWindowText(IntPtr hWnd, string lpString);
You can define this for desktop app
[DllImport("user32.dll"), EntryPoint="SetWindowTextW")]
private static extern bool SetWindowText(IntPtr hWnd, string lpString);

Call the function with this code snippet
public bool SetText(IntPtr hWnd, String text)
{
System.text.StringBuilder NewWindowText = new System.text.StringBuilder(text);
return (SetWindowText(hWnd, NewWindowText) != 0);
}
GetWindowText
The second example is one that creates more problems. The fault probably is derived from the fact that many people use the String for these conversions instead of the StringBuild. To do this I need two P/Invoke the first for retrieve the lenght the second to retrieve the text.

You can define this for mobile app
[DllImport("coredll.dll", CharSet = CharSet.Auto, SetLastError = true), EntryPoint="GetWindowTextW")]
static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
[DllImport("coredll.dll", SetLastError = true, EntryPoint="GetWindowTextLength")]
static extern int GetWindowTextLength(IntPtr hWnd);

You can define this for desktop app
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true), EntryPoint="GetWindowTextW")]
static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll", SetLastError = true, EntryPoint="GetWindowTextLength")]
static extern int GetWindowTextLength(IntPtr hWnd);
Call the function with this code snippet
public string GetText(IntPtr hWnd)
{
int length = GetWindowTextLength(hWnd);
StringBuilder TheWindowText = new StringBuilder(length + 1);
GetWindowText(hWnd, TheWindowText, TheWindowText.Capacity);
return TheWindowText.ToString();
}
If anybody knows any more graceful solution, I'd like to know it.
I hope my suggestions are useful to someone.

martedì 2 dicembre 2008

Simple event logging

With this class your application can write in the event log.
The class use the
System.Diagnostics to write the message into the Event log.

using System.Diagnostics;

public class Logging

{

static string Source = "My Application";

public static void WriteEventLog(string Message, System.Diagnostics.EventLogEntryType EntryType)

{

try

{

if (!EventLog.SourceExists(Source))

{

EventLog.CreateEventSource(Source, "Application");

}

EventLog.WriteEntry(Source, Message, EntryType);

}

catch(Exception ex)

{

System.Diagnostics.Debug.WriteLine(ex.Message);

}

}

}


Usage:

Logging.WriteEventLog(System.Diagnostics.EventLogEntryType.Information,"Message Error");