My first Xbox 360 program (game?)

November 1st, 2008

Downloaded Microsoft XNA Game Studio 3.0 this weekend, could not resist to try it out.

With Visual Studio 2008, It can create games for Windows, Zune, and XBox 360.  Not interested to create Windows games, don’t have a Zune(yet), the only option left is to test it on my XBox 360.

To deploy your game onto XBox 360, you need a Creators Club Premium Membership.  Without this membership, you would not be able to connect your XBox 360 to your computer through XBox live.

Took out my credit card and $100 later, I am now a Creators Club Premium Member!


 

Set up XBox 360 with XNA Game Studio

  • Logged onto XBox Live from my XBox 360, went to Games Market Place, downloaded XNA Game Studio Connect.
  • Launched XNA Game Studio Connect, it spitted out a 25-character key for the first time.
  • On my PC, started  XNA Game Studio Device Center, entered the key, and the PC and XBox made the connection.

 

My first Game

If you used Visual Studio before, nothing is new here:

  • File => New Project, picked XBox 360 games
  • Seconds later, a game template was created
  • Pressed F5, VS deployed the game onto XBox, and my first “game” was running.

It was just a blue screen, not even a “Hello World” on it, but it was every exciting: this might change the landscape for XBox 360 game creation.  For a $100, .NET programmers can create games/applications for XBox 360 and Zune, it’s no longer a privilege for big game studios.

Posted in .NET, XBox, XNA Game Studio | No Comments »

IE8 First impression

August 28th, 2008

 

Now IE8 Beta2 is out, I decided to give it a try.

First impression:  it’s much faster than compare to IE7. 

I am using it with Google reader, other than some layout issues with the action footer for each item, everything seemed fine.

Update:  Turned on the compatibility view, everything worked fine. 

Posted in Other | No Comments »

WURFL and SSDS, part I

June 28th, 2008

A friend of mine asked me for some help on mobile device detection.  He introduced me to WURFL, a giant database contains mobile devices information in xml format, in a single file.

First thought came to mind was:  how do I store this thing in a database?  I Googled around, found a couple of .NET libraries working against WURFL, but they all directly working against the xml.  Queries are done against memory objects.

To store this thing in SQL 2005, would need to define a schema, too much work.

I just got access to the SSDS beta, what a perfect match:

  • No need to define any schema.
  • WURFL would be an Authority.
  • Devices would be the container.
  • Each device would be an Entity in the Devices container.
    • device_Id will be the entityId
    • device.Properties will hold the user_agent, fallback_id, and all the capabilities.

Within 30 minutes, I whipped up a console application, parsed the 8MB xml, and stored all the 5755 devices into SSDS.

Next, I will write a web service to query the data.

Posted in .NET, Mobile, SOA, SSDS | No Comments »

More on Home Server and Virtual Machines

June 11th, 2008

A couple of points on running Virtual Server 2005 R2 on Home Server:

  • Always apply Virtual Server 2005 R2 SP1 first
  • Install the server hosting software on C drive.  C is the OS partition for Home Server, mine is 20GB in size.
  • Install the VM hard drive files in a share like \\YourHomeServer\VM, not D drive, otherwise, you might get into file corruption issues.
  • If you are running none-Windows guest operating systems, and the guest OS won’t boot up, try turn off the “Enable hardware-assisted virtualization if available” option.

While trying to install UBuntu on Virtual Server 2005, at one point, I gave up, decided to try VMWare Virtual Servers 2.0.  VMWare did not like the \\YourHomeServer\VM path notation for virtual hard drives, it kept complaining the size was too small to create the hard drive.  On Home server, other than C, you could not use any local hard drive letters, so I had to go back to Virtua Server 2005 R2.

Posted in Other | No Comments »

Home Server, Virtual Server and Linux

June 8th, 2008

I am running my home server on an AMD dual-core 4200 box with 4GB of RAM.  It mainly served as a file server, thought I could utilize it a bit more.  Running virtual machines is the natural choice.

I wanted to be able to run the VMS without login the home server, so it seems I need the Virtual servers:  Microsoft Virtual Server 2005 R2 or VMWare virtual server.  They both are free.

Since Home Server is essentially Windows Business Server 2003 stand edition, so I decided to try Microsoft Virtual Server 2005 R2 first.

Within an hour, I have Virtual Server 2005 R2 installed and an instance of Windows Server 2008 Trial up and running.  That’s promising, but I did not want to run a trial version of Windows 2008.  How about Linux?

First, tried to install Fedora, but could not get anything going past the boot screen.  I gave up after several tries.  Decided to go with UBuntu.  Downloaded the desktop, and went a little bi further, but after the initial screen, everything went black.  After Googling a bit, found that was a color depth issue, following the instructions on the net and forty minutes later, I reached the final reboot screen.  

After clicking the button, the VM rebooted, but hang shortly after the boot screen.  Remember the old DOS days, if you had a piece of incompatible device driver, your machine would not even start.

Again, back to Google, but this time nothing came up.  Someone suggested going into to recovery mode at the grub screen.  That’s did not help, but it did prove one thing: indeed it hang while detecting some kind of device.

After hours of trying, I was at a point of giving up, then I noticed the “Enable hardware-assisted virtualization if available” check box.  I unchecked it, and powered on the VM.  Boom, everything worked!

Posted in Other | No Comments »

Boot Camp 2.1 installed, finally

May 18th, 2008

I have been trying to install Boot Camp 2.1 ever since it has been released.  But every time, I got the following error message:

"The installer encountered errors before boot camp could be configured"

I have XP running under BC 2.0, tried everything I  could find on the Web:

  • Set locale to English
  • Manually unpacking the .msi into .msp, then run msiexec /upgrade *.msp
  • Uninstalled the BC 2.0 upgrade, and did a full install from the Mac OS X dvd

None of the above helped.  I sort of gave up on it until I got the XP SP3 update notice.

Spent another hour or so trying out different things, still the same error message, seems going no where, then I noticed I have two Live Mesh video adapters installed.  As the last resort, I uninstalled the two video adapters and restarted the BC 2.1 upgrade for the Nth time.  Wala, it worked!!  Everything went smoothly, after the reboot, I have BC 2.1.  Windows XP Sp3 is next to be installed!

Lessons learned:

Uninstall any Video Adapters that is not installed by Boot Camp 2.0.  You should have only either an ATI or Nvidia adapter under the Video Adapters in Device Manager.

Posted in Mesh, Other | No Comments »

Live Mesh Client Installation

April 27th, 2008

Microsoft launched a tech preview version of its Mesh application last week.

I was trying to add my Vista machine to the Mesh by installing the client app, but keep getting a message, some thing like "This application can be installed on 32-bit US version of Windows XP and Vista".

I could not figure out what went wrong for the past 3 days, almost tried everything I could think of, even wanted to uninstall Vista SP1 .  Finally, 10 minutes ago, I tried to set my location to US, and all things worked!

Thought this might be helpful for other people.

Posted in Mesh | No Comments »

MeasureString for wrapped multi-line text height in .NET Compact Framework

April 7th, 2008

In .NET Compact Framework, Graphics.MeasureString only measures the required width and height for a single line string.  What happens if the text is wrapped?

Several years ago, I used this piece of code to measure a wrapped string height.  Not pretty, but works.  A couple of days ago, I found this code, which utilizes the DrawText API, I think is better, but I did not like the idea of taking a control as input.  Combine these two, I have this code:

static public Size MeasureStringEx(Graphics gr, string text, Font font, Rectangle rect)
{
    RECT bounds = new RECT();
    bounds.left = rect.Left;
    bounds.right = rect.Right;
    bounds.bottom = rect.Bottom;
    bounds.right = rect.Right;

    IntPtr hFont = font.ToHfont();
    IntPtr hdc = gr.GetHdc();
    IntPtr originalObject = CoreDll.SelectObject(hdc, hFont);
    int flags = CoreDll.DT_CALCRECT | CoreDll.DT_WORDBREAK;
    CoreDll.DrawText(hdc, text, text.Length, ref bounds, flags);
    CoreDll.SelectObject(hdc, originalObject);
    gr.ReleaseHdc(hdc);
    return new Size(bounds.right - bounds.left, bounds.bottom - bounds.top);
}

and the CoreDll API imports:

Public struct RECT
{
    public int left;
    public int top;
    public int right;
    public int bottom;
}

[DllImport("coredll")]
public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);

[DllImport("coredll.dll")] public static extern int DrawText(IntPtr hdc, string lpStr, int nCount, ref RECT lpRect, int wFormat);
public static int DT_CALCRECT = 0x00000400;
public static int DT_WORDBREAK = 0x00000010;

Posted in .NETCF, Mobile | No Comments »

Windows Mobile 6.1

April 2nd, 2008

It has been announced here, and emulator images can be downloaded from here.

 

Posted in Mobile | No Comments »

Screen Capture in .NET Compact Framework

March 31st, 2008

Five years ago, if you wanted to do a screen capture on Windows Mobile devices with .NET Compact Framework, you would look at Screen Capture, I did not count the lines, but looked quiet long.  Five years later, I wanted to do the same thing, and my code looked like this:

public static Bitmap ScreenCapture(IntPtr hWnd, Rectangle rect)
{
    IntPtr hBitmap; 
    IntPtr hDC = CoreDll.GetDC(hWnd); 
    IntPtr hMemDC = CoreDll.CreateCompatibleDC(hDC);

    hBitmap = CoreDll.CreateCompatibleBitmap(hDC, rect.Width, rect.Height);

    if (hBitmap != IntPtr.Zero)
    {
        IntPtr hOld = (IntPtr)CoreDll.SelectObject(hMemDC, hBitmap);
        CoreDll.BitBlt(hMemDC, 0, 0, rect.Width, rect.Height, hDC, 0, 0, CoreDll.SRCCOPY);

        CoreDll.SelectObject(hMemDC, hOld);

        CoreDll.DeleteDC(hMemDC);
        CoreDll.ReleaseDC(hWnd, hDC);
        Bitmap bmp = System.Drawing.Image.FromHbitmap(hBitmap);
        CoreDll.DeleteObject(hBitmap);


        return bmp;
    }

    return null;
}

 

The CoreDll imports:

[DllImport("Coredll.dll", EntryPoint = "GetDC")]
public static extern IntPtr GetDC(IntPtr hWnd);
[DllImportAttribute("coredll.dll", EntryPoint = "GetWindowDC")]
internal static extern IntPtr GetWindowDC(IntPtr hWnd);
[DllImport("Coredll.dll")]
public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
[DllImport("coredll.dll")]
public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight);
[DllImport("coredll.dll")]
public static extern IntPtr CreateDIBSection(IntPtr hdc, IntPtr hdr, uint colors, ref IntPtr pBits, IntPtr hFile, uint offset);
[DllImport("coredll")]
public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
[DllImport("coredll")]
public static extern int DeleteDC(IntPtr hdc);
[System.Runtime.InteropServices.DllImportAttribute("coredll.dll", EntryPoint = "ReleaseDC")]
internal static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport("coredll")]
public static extern IntPtr DeleteObject(IntPtr hObject);

Posted in .NETCF, Mobile | No Comments »

How do you explain MSFT’s Mobile Platforms to end users

March 27th, 2008

Let’s say you developed a MSFT Windows mobile software, in the WM5 world, you probably named your product as "XYZ for Windows Mobile 5 Pocket PC edition" and "XYZ for Windows Mobile 5 Smart Phone edition".

These names are fine for people working with WM systems, but for end users, the word "Smart Phone" might create a lot of confusions.  The problem is more and more Pocket PC devices have phone functions, are they Pocket PCs or Smart Phones?  A lot of users might choose the wrong software for the wrong devices.

I use the following simple method to explain this to the end users, it seems working well:

Looking for the "Start" menu on your device, if it's in the top left corner, choose the Pocket PC software; if it's in the lower left corner, use the Smart Phone software.


Pocket PC

Smart Phone

Posted in Mobile | No Comments »

How to programmatically close a message box in .NET Compact Framework

March 24th, 2008

On Windows Mobile devices, there is a Time out setting for the Home or Today screen.  When this time out value is reached, WM will hide whatever program is running and display the Home/Today screen.

This causes a problem for one of my project.  In my project, if the MessageBox.Show(…) function is called and the home/today screen kicks in before the user closes the message box, my program is hidden, and the user has no way to get back in, except turn the device off then on again.

The reason is obvious, modal dialog boxes, like message boxes, block the UI thread until they are closed.  But how do you close a message box while it’s hidden?  After some googling plus try and error, I came up with the following solution:

 

const int WM_DESTROY = 0x02;

 

[DllImport("coredll.dll", EntryPoint = "FindWindow")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

 

[DllImport("coredll.dll", EntryPoint="SendMessage")]
private static extern uint SendMessage(IntPtr hWnd, uint msg, uint wParam, uint lParam);

 

public static void KillWindow(string className, string title)
{
    IntPtr handle = FindWindow(className, title);
    SendMessage(handle, WM_DESTROY, 0, 0);
}

public static void CloseMessageBox(string title)
{
    IntPtr handle = FindWindow("Dialog", title);
    SendMessage(handle, WM_DESTROY, 0, 0);
}

Posted in .NET, Mobile | No Comments »

WCF and Silverlight on IIS setup

March 20th, 2008

Both involve MIME type setup on IIS.

1. WCF:  If your WCF does not work on your production IIS server, most likely the .svc MIME type is not registered, I used the following command line to fix it:

c:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ServiceModelReg -i

2. Silverlight, you need to register the .xap MIME type, for IIS 7, simply using the following command line:

C:\windows\system32\inetsrv\appcmd set config /section:staticContent /+[fileExtension='.xap',mimeType='application\x-silverlight-app']

For both cases, the "C:\Windows\" directory path depends on where your OS is installed.

Posted in ASP.NET, SOA, Silverlight | No Comments »

Sliverlight Applications and Web Services

March 14th, 2008

I am trying to write my first Silverlight application.  I need to do data binding, I already have a set of business objects written in an existing project.  Naturally, I want to reference that project and reuse the business objects.  But VS 2008 won’t allow me to reference the project, says I can only reference Silverlight projects.  Fine, how about reference the .dll then?  Same thing, VS 2008 complaints the .dll is not built with Silverlight.  Why?

It clicked in 10 minutes later while trying different things:  a Silverlight application is a client side application, it should never directly using business objects, which sit on the server side.  The server side objects and operations should be exposed as services, which then can be consumed by Silverlight applications.

Posted in ASP.NET, SOA, Silverlight | No Comments »

How to determine if a table exists in SQL Server Compact (SSC) Edition

March 10th, 2008

In one of my managed code project, I need to determine if a table exists in SSC.  This is pretty easy to do in regular SQL Server with T-SQL:

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[MyTable]') AND type in (N'U'))

SELECT 'Table exists.'

ELSE SELECT 'Table does not exist.'

However, this does not work in SQL Server Compact Edition.  First of all, SSC does not have sys.objects, second, SSC does not support conditional T-SQL.

After googling a bit, I found the first problem can be solved by using INFORMATION_SCHEMA.TABLES, how about the second problem?  I just could not find any conditional T-SQL reference in SSC.

I ended writing a c# function like this:

public static bool DoesTableExist(string tableName, SqlCeConnection ssceconn)
{
    string exsitTSql = @"SELECT COUNT(TABLE_NAME) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='" + tableName + "'";
    int cnt = (int) ExecuteScalar(exsitTSql, ssceconn);
    return (cnt == 1);
}

Posted in Mobile, SQL | No Comments »

SSDS MIX08 Session Summary

March 8th, 2008

Watched Nigel Eillis’ MIX08 presentation today: http://sessions.visitmix.com/?selectedSearch=BT05.  Here is a short summary on what I have learned about SSDS.

  • SSDS is a layer of WS been put on top of MSFT’s 18k+ SQL servers.
  • Taking Invitation only Beta application now, public Beta within 6 month, go live in Q1, 09.
  • SSDS supports REST and SOAP services now, will support more later.
  • There are three concepts you need to know:
    • Authority
    • Container
    • Entity
  • Authority contains Containers, and Container contains Entities.
  • No schema is needed for Containers and Entities.
  • Entities have two kinds of properties:
    • Fixed properties.  There are three so far:  ID, Kind, Version.  They are referenced as SomeEntity.ID, SomeEntity.Kind, SomeEntity.Version.
    • Flex properties.  Can be any number if them.  Referenced as SomeEntity["SomeProperty"].  Same property name on different entities needs not to be the same type.  E.g. “DatePublished” on EntityA can be a datetime, but on EntityB could be a string.
  •  Queries are in LINQ like syntax.
  • Product Page: http://www.microsoft.com/sql/dataservices/default.mspx.
  • Team Blog: http://blogs.msdn.com/ssds

Posted in SQL | No Comments »

MIX08 Sessions online

March 7th, 2008

If you don’t get to go to MIX, this years sessions are available here.   Lots of good stuff and good too see they built the whole thing with Silverlight.  So far, there are more than 60 sessions available, will take days if you go through them all.

Posted in .NET, ASP.NET, Silverlight | No Comments »

ASP.NET MVC Preview 2

March 5th, 2008

Another beta release from MSFT:  ASP.NET MVC Preview 2.

I mainly using MonoRail for my MVC stuff, have not looked at ASP.NET MVC yet, I only know ASP.NET MVC will support NVelocity view engine, which is the engine I use.

Posted in .NET, ASP.NET | No Comments »

Microsoft SQL Server Data Services

March 5th, 2008

I just got access to Amazon SimpleDB last Friday, yet get a chance to look at it.  Today, Microsoft announced Microsoft SQL Server Data Services (MSSDS).

“The service is designed for developers building Web-based applications that need a scalable, easily programmable and highly available utility-based data store.”

You can pre-register for the beta here.

I am anxious to take a look at this, since I already know a lot about MS SQL Server, I might use this a lot more than Amazon SimpleDB.

Posted in SOA, SQL | No Comments »

Silverlight 2.0 Controls Source

March 5th, 2008

I like source code, I like to read them, tweak them, and break them.

Here is the source code package for Silverlight 2.0 controls.

http://download.microsoft.com/download/6/5/e/65e6d2b0-8f7e-4e08-ae62-31f03d664f73/Silverlight2Beta1Controls.exe

Posted in Silverlight | No Comments »