lunedì, settembre 08, 2008

Metodo per avere avviare una singola istanza di un programma su Windows CE



Il codice che segue permette di avviare una singola istanza di un programma su windows CE

scritto in c# funziona correttamente su Compact Framework 2

La fonte è:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=726497&SiteID=1



using System;
using System.Collections.Generic;
using System.Windows.Forms;

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

namespace DevWEB
{
static class Program
{
[DllImport("coredll.dll", SetLastError = true)]
private static extern IntPtr CreateEvent(IntPtr lpEventAttributes, bool bManualReset, bool bInitialState, string lpName);

[DllImport("coredll.dll", SetLastError = true)]
private static extern bool CloseHandle(IntPtr hObject);

private const int ERROR_ALREADY_EXISTS = 183;
[DllImport("coredll.dll", SetLastError = true)]
private static extern IntPtr FindWindow(string className, string wndName);


[MTAThread]
static void Main()
{

string path = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
IntPtr handle = CreateEvent(IntPtr.Zero, false, false, path);
int error = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
if (handle != null && (error != ERROR_ALREADY_EXISTS))
{

Application.Run(new Memor.GUI.MainForm());
}
else
{
// Upon startup CF implementation of mscoree looks for a window with a class #NETCF_AGL_PARK
// and title set to the current process executable full path (\Program Files\MyApp\MyApp.exe).
// If found, the runtime presumes that the current application is already running. In this case
// it will be reactivated. To do this the abovementioned window is sent a message 0x8001,
// and then the new instance quits.

// The CF 2.0 is almost identical: This is only when you start the app multiple times before the Form has
// been appeared.
IntPtr hWnd = FindWindow("#NETCF_AGL_PARK_" + path, string.Empty);
if (hWnd != IntPtr.Zero)
{
Microsoft.WindowsCE.Forms.Message msg = Microsoft.WindowsCE.Forms.Message.Create(hWnd, (int)0x8001, (IntPtr)0, (IntPtr)0);
Microsoft.WindowsCE.Forms.MessageWindow.SendMessage(ref msg);
}
}
CloseHandle(handle);

}


}
}

mercoledì, settembre 03, 2008

Request Classic ASP Come Aggirare il limite 102.399 Bytes per modulo

Oggi mi sono reso conto che cercando di inviare una grande quantità di dati da un modulo ad esempio una textarea ad una pagina Classic ASP se si supera il limite di 102.399 bytes Si genera un eccezione nella riga in cui viene effettuato il recupero con l'istruzione Request.Form("NomeCampo") quindi per aggirare il problema ho scritto una classe che utilizza il sistema Request.BinaryRead  che potete scaricare seguendo il link di seguito:

Scarica qui

Per utilizzarlo mettetelo semplicemente in un file di inclusione (ad Esempio clsRequest.asp)

in modo che sia all'inizio della pagina in cui volete utilizzare la classe.

 

      Set MyRequest = New clsRequest

      MyRequest.Form("NomeCampo")                   'Solo POST

MyRequest.QueryString("NomeCampo")            'Solo GET

MyRequest("NomeCampo")                        'Sia GET Che POST (Con Precedenza di POST)= Se sono presenti due argomenti  POST e GET con nome uguale Quello GET Verrà Scartato

Nella classe già che ero a programmare ho incluso due routine una serve per evitare SQL Injection ed esegue un controllo tramite Regular Expression

l'altra esegue il metodo Server.HtmlEncode in modo da restituire stringhe che non possano essere soggette a Cross Site Scripting, Tuttavia se dovesse rendersi necessario disattivare una delle due o anche tutte e due queste funzionalità ho previsto delle variabili pubbliche a cui basta semplicemente assegnare un bvalore true dopo aver inizializzato la classe. di seguito riporto l'esempio:

      Set MyRequest = New clsRequest

MyRequest.DisableXSS = true                 'Disabilita la Funzione che inibisce il Cross Site Scripting

MyRequest.DisableSQLI = true                'Disabilita il Controllo su SQL Injection

MyRequest.Form("NomeCampo")                   'Solo POST

      MyRequest.QueryString("NomeCampo")            'Solo GET

 

 

Spero questa classe possa essere d'aiuto a qualcuno. Se avete qualche problema fatemi sapere.

 

Non mi ricordavo di avere un blog..

Erano anni che non scrivevo in questo blog... Non che qualcuno lo legga.. e così dal nulla ho deciso di metterci un tema nuovo.. Comunque...