Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

What's New in Visual Studio 2008 and the .NET Compact Framework 3.5 : Page 3

The release of Visual Studio 2008 also updates the .NET Compact Framework, with new tools, APIs, LINQ support and WCF features. Find out how these can help make your job easier.


advertisement
New APIs
In .NET Compact Framework 3.5, you can now programmatically retrieve the platform information (PocketPC or Smartphone) using the Platform property:

'---need to import Microsoft.WindowsCE.Forms.dll--- Dim instance As Microsoft.WindowsCE.Forms.WinCEPlatform instance = Microsoft.WindowsCE.Forms.SystemSettings.Platform() MsgBox(instance.ToString)

You can also check the version number of the OS used in the device using the OSVersion property from the OperatingSystem class, like this:

Dim OS As OperatingSystem OS = Environment.OSVersion MsgBox(OS.ToString)

If you need to play a sound file, .NET CF 3.5 includes the new SoundPlayer class, which allows you to play a .wav file:


Dim soundplayer As New Media.SoundPlayer With soundplayer .SoundLocation = "\Windows\Alarm1.wav" .Play() End With

In addition, you can also play standard system sounds, like this:

Media.SystemSounds.Asterisk.Play() Media.SystemSounds.Beep.Play() Media.SystemSounds.Exclamation.Play() Media.SystemSounds.Hand.Play() Media.SystemSounds.Question.Play()

Compression
The compression classes available in the desktop version of the .NET Framework is now finally available in .NET CF 3.5. The compression algorithms supported are GZip and Deflat. The following shows how you can use the new classes to perform compression and decompression.

First, ensure that you import the required namespaces:

Imports System.IO Imports System.IO.Compression

The Compress() function shown in Listing 3, allows you to compress a byte() array and returns the compressed data in another byte array.

Because you do not know the actual size of the decompressed data, you have to progressively increase the size of the data array used to store the decompressed data. The dataBlock parameter suggests the number of bytes to copy at a time. A good rule of thumb is to use the size of the compressed data as the block size, such as:

'---data is the array containing the compressed data--- dc_data = ExtractBytesFromStream(zipStream, data.Length):

The actual act of extracting the bytes from a stream object is accomplished by the helper ExtractBytesFromStream() function (Listing 4).

To test the functions defined above, use the following statements:

Dim str As String = "Hello world" Dim compressed_data As Byte() '---compress the data--- compressed_data = _ Compress(System.Text.ASCIIEncoding.ASCII.GetBytes(str)) '---decompress the data--- Dim decompressed_data As Byte() decompressed_data = Decompress(compressed_data) '---print out the decompressed data--- MsgBox(System.Text.ASCIIEncoding.ASCII.GetString( _ decompressed_data, 0, decompressed_data.Length))



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date