How to determine if we are running on 64 or 32 bit?

In my work I need to be able to pick different files depending on if I run in 64 bit or 32 bit system. The first thing I did try was to use the size of IntPtr which is 4 for 32 bit and 8 for 64 bit. But since I was using the visual studio unit test framework it did not work that god. The unit test framework run in a 32 bit process but the application I’m testing is running in 64 bit, so decided to use P/Invoke to call GetNativeSystemInfo.

The structure that you get is according to

[StructLayout(LayoutKind.Sequential)]
private struct SystemInfoNative
{
    internal ushort ProcessorArchitecture;
    internal ushort Reserved;
    internal uint PageSize;
    internal IntPtr MinimumApplicationAddress;
    internal IntPtr MaximumApplicationAddress;
    internal IntPtr ActiveProcessorMask;
    internal uint NumberOfProcessors;
    internal uint ProcessorType;
    internal uint AllocationGranularity;
    internal ushort ProcessorLevel;
    internal ushort ProcessorRevision;
}

Out from this you can check the processor architecture.

And the complete source code
Read more

0.00 avg. rating (0% score) - 0 votes

.NET Framework 3.5 SP1 source code

Have you ever wondered how Microsoft does thing inside .NET? Now it’s possible to see the source code by configuring Microsoft reference source server inside visual studio. Just go to ‘Serversetup’ and setup you visual studio 2008 to use symbol files from Microsoft symbol server when you debugging. You can also download the symbol files and use them offline by follow this guide ‘Downloadsetup’.

The symbol files are available for this dll’s in .NET 3.5 SP1.
• mscorlib.dll
• Microsoft.Visualbasic.dll
• system.dll
• System.ComponentModel.DataAnnotations.dll
• system.data.dll
• system.drawing.dll
• System.Web.Abstractions.dll
• system.web.dll
• system.web.extensions.dll
• System.Web.Extensions.Design.dll
• System.Web.DynamicData.dll
• System.Web.DynamicData.Design.dll
• System.Web.Routing.dll
• system.windows.forms.dll
• system.xml.dll

0.00 avg. rating (0% score) - 0 votes

New hotkeys in Windows 7

In Windows 7 Microsoft have added some additional hotkey compared with Vista. This a small list of the new keys.

General

Win+Up Maximize
Win+Down Restore / Minimize
Win+Left Snap to left
Win+Right Snap to right
Win+Shift+Left Jump to left monitor
Win+Shift+Right Jump to right monitor
Win+Home Minimize / Restore all other windows
Win+T Focus the first taskbar entry
Pressing again will cycle through them, you can can arrow around.
Win+Shift+T cycles backwards.
Win+Space Peek at the desktop
Win+G Bring gadgets to the top of the Z-order
Win+P External display options (mirror, extend desktop, etc)
Win+X Mobility Center (same as Vista, but still handy!)
Win+#
(# = a number key)
Launches a new instance of the application in the Nth slot on the taskbar.
Example: Win+1 launches first pinned app, Win+2 launches second, etc.
Win + +
Win + –
(plus or minus key)
Zoom in or out.

Read more

0.00 avg. rating (0% score) - 0 votes

Microsoft .NET Framework – Application Development Foundation

After 2 month of preparation and a weekend that disappeared I have passed my first MCTS exam. It has been an interesting trip with a lot of new knowledge and frustration when the sample questions don’t make sense (But I did pass the exam pass rate criteria with good marginal). I did use the “MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework 2.0 Foundation” book for my preparation and Measureup’s online test questions. The book also contain test question both in the book and one a CD. The questions in the book was really good and helpful both the question on the CD was according to me many times outside of the scope and had no connection to the content in the book or the real exam I did take. Measureup’s questions were the closest ones to the real exam and also the question that I did learn most from.
Read more

0.00 avg. rating (0% score) - 0 votes

Introducing WPF Application Quality Guide v.0.4

WPF Application Quality Guide v0.4 has been released today at the WindowsClient.NET with new topics and updates.

This release includes several new topics and updates:
1. Suggested Roadmap – updated to include new topics
2. Data-Driven Testing – a new article about the data-driven testing practice.
3. Globalization and Localization Testing – updated w/ more details including creating localizable UI layouts in WPF and approaches to localizing WPF applications.
4. Stability and Stress Testing – a new article about stress testing principles, best practices, and useful resources.
5. Accessibility Testing – a new article about accessibility considerations, best practices and key resources.
6. Tools / TestAPI – a brief intro about the newly released TestAPIs.

The full online version can be found here.

0.00 avg. rating (0% score) - 0 votes

Fun with UIAutomation and calc 2 (event handling)

Last week, I wrote about UIAutomation and calc. Now it’s time to revisit or little example program and replace the automatic start of calc and replace it a method that will wait for any calc to start and take control over that session. To abstract away the waiting code, I did create a new class called WindowOpenWaiter. Let’s take a look how we can use or new class. The full code to this blog can be found in the bottom.

The first thing we need to-do is to create a new instance of WindowOpenWaiter and give the title to the window that it should look for. Next thing is to call the wait methods with a timeout time in mille seconds so that we will not wait forever. The last thing we do is to get the element that the waiter has found for us and save it in some variable.

AutomationElement calc = null;
using (WindowOpenWaiter waiter = new WindowOpenWaiter("Calculator"))
{
    try
    {
        waiter.Wait(1000 * 10);
    }
    catch (TimeoutException e)
    {
        Console.WriteLine(e.Message);
        return;
    }
 
    calc = waiter.Element;
}

Read more

5.00 avg. rating (94% score) - 2 votes

Regular expression builder

I was doing some input verification of data to method when it did hit me that it would be nice if I could do it with regular expression since I was only check if the string data was in correct format. Since I’m not an expert in regular expression I needed some type of builder or verification tool. After some searching I found this free tool RegExr that has both an online version and desktop version. The thing that I did like most was the online version that was only a click away. The program doesn’t help you that much building the regular express but it helps a lot for verifying your expressions. It also has a bunch “code snippets” that you can use as building block.
Anyway this little program did save my day to tryout some different expression to find one that did fit my needs.

So I hope that you also will find it useful.
RegExr
RegExr desktop

0.00 avg. rating (0% score) - 0 votes

Fun with UIAutomation and calc

Last night I got a cool idea how to show some basic ideas of UIAutomation. I did decide to-do a UIAutomation example with calc as my test subject. The idea is to give a mathematical expression to the program, which will then use calc to solve the problem and show you the result. The main thing is to show how UIAutomation is working and not to calculate.

The first thing that we need is a method that can find an AutomationElement for us. An AutomationElement is anything that you can see on the screen as buttons and input fields. The method take a root AutomationElement that define where to start to search, a name and a class name for the object that we are looking for. We then create two property conditions based on the name and class name. These two conditions are then combined in an AndCondition. We also have OrCondition and NotCondition to use. The last thing we do is to search for the first AutomationElement that match the condition.

private static AutomationElement GetElement(AutomationElement root, string name, string className)
{
    PropertyCondition condName = new PropertyCondition(AutomationElement.NameProperty, name);
    PropertyCondition condClassName = new PropertyCondition(AutomationElement.ClassNameProperty, className);
    AndCondition cond = new AndCondition(condName, condClassName);
    return root.FindFirst(TreeScope.Descendants, cond);
}

Next method that we need is one that can return a invoke pattern. Invoke pattern is used for example to click on a button. This will be used to be able to click on the different buttons in calc

private static InvokePattern GetInvokePattern(AutomationElement element)
{
    return element.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
}

Read more

0.00 avg. rating (0% score) - 0 votes

.NET Cheat Sheets

When I was surfing around today I found this site that contain a bunch of different cheat sheets for .NET. The one that I find really useful was ‘Visual Studio 2005 Built-in Code Snippets‘. So simple have fun with this findings

0.00 avg. rating (0% score) - 0 votes

Easy usage of databases in PHP

When I started with development for PHP I did offend run into writing specific MySQL database code over and over in all my files. After suddenly running into something called Postegres SQL I quickly learned that this was not a good approach. I did also learn that it was really hard to debug database error with default error information, especially after the site was deployed for public usage.

So I decided to write the kill class that would solve all this small problems. The result was a simple database wrapper class container the most important functionality as:
– Connect
– Query
– Get next record in result (Perfect suited to be used with while loops)
– Get number of affected rows for SELECT, UPDATE, DELETE, INSERT
– Optimize table
– Clear result to free up memory
– Close connection
Get next record snippet

function next_record()
{
  $this->Record = mysql_fetch_array($this->Query_ID);
  $this->Errno = mysql_errno();
  $this->Error = mysql_error();
  $stat = is_array($this->Record);
  if (!$stat)
  {
    mysql_free_result($this->Query_ID);
    $this->Query_ID = 0;
  }
  else
  {
    $this->Row += 1;
  }
 
  return $this->Record;
}

I also added some error handling that enable verbose error on the page during development mode and verbose error message with mail after deployment. The error result contains information as:
– General error message
– Error number and error text from the SQL server
– HTTP referrer
– Requested URI
– GET data
– POST data
And since I did use my class a lot for system with user authentication I did add user ID and user name for current user getting the error.

I hope this code will help someone out there to not end up with my problem and reinvent the wheel again.

MySQL version:db_inc.zip
PostrgressSQL version:db_inc_pg.zip

Usage example of the class

$db = new DB();
$db->connect();
$db->query("SELECT * FROM Blog ORDER BY Date");
while($data = $db->next_record())
{
  $id = $data['ID']
  // Do more stuff
}
0.00 avg. rating (0% score) - 0 votes

« Previous PageNext Page »