Running on PPC or on the PC?

  • Thread starter Thread starter Ofer B.
  • Start date Start date
O

Ofer B.

I'm writing a program that will run on PPC and PC.
I'm using sql ce so I have to know when the program is running on the PC and
when on the PPC.

How can I know that at run time?

Ofer
 
Your application can determine the OS it is running on at runtime using:-
System.Environment.OSVersion.Platform

This will return PlatformID.WinCE on Pocket PC or PlatformID.Win32NT on
Windows XP or similar - see the online documentation for all other possible
values.

Peter
 
Thanks Peter,

I use the Enviroment Class, but I can't declare a variable like SqlCeEngine.
if I declare it before the IF statment. It can't run on the PC. If I
declare it in the IF statment (like the code beneath) I can't use it out
side the IF statment.
do you have any idea?
can I do it with pre compiletion statment?
String os = System.Environment.OSVersion.Platform.ToString();

if(os == "WinCE")

{

SqlCeEngine eng = new SqlCeEngine();

}

else //WinNT

{

// use *.mdb database

}


Ofer
 
Any function that uses class which is not available on current platform,
will fail, once invoked, regardless of whether you actually execute the
lines that reference this class. Because of this the following won't work:

void test()
{
if(os == "WinCE")
{
SqlCeEngine eng = new SqlCeEngine()
...
}
else
{
// use mdb db
}
}

but this will:

void UseSqlCe()
{
SqlCeEngine eng = new SqlCeEngine()
...
}

void UseMDB()
{
....
}

void test()
{
if(os == "WinCE")
{
UseSqlCe();
}
else
{
UseMDB();
}
}

The problem is that you will end up with enormous amount of code. I have
written a class "SQLGenericClient", that uses SqlCe on WinCE and SQLClient
on the desktop. It offers SQLGEnericCommand, SQLGenericDataAdapter,
SQLGenericTransaction etc. While doing this I've hit a number of snags and
cannot say that I have reached production quality... The demo works though
:)
 
Back
Top