Monday 31 December 2007

theForger's Win32 API Programming Tutorial

WinProg

Welcome to theForger's Win32 API Tutorial

This tutorial attempts to get you started developing with the Win32 API as quickly and clearly as possible.

Download Full Example Code
The tutorial text does not include the full code, you will need to download this to compile the examples.

This tutorial is meant to be read as a whole

Please read it from beginning to end before asking questions... most of them will probably be answered. Each section builds on the sections before it. I have also added some solutions to common errors in Appendix A. If you ask me a question that is answered on this page, you will look very silly.

If you are viewing this locally or on another website, visit the #winprog website for the current official copy.

Sunday 23 December 2007

Updating the UI from a Secondary Thread

[Full article]In my January 2004 column I discussed the use of delegates to execute a method asynchronously. I showed you that it's relatively easy to call BeginInvoke on a delegate object from the code behind a Windows® Form in order to dispatch an asynchronous method call. You also saw how to set up a callback method that fires automatically when the asynchronous method call completes its execution. However, I stopped short of talking about how you should update the UI to tell the user that the work is complete.
Updating user interface elements from a secondary thread in Windows Forms is tricky because a secondary thread is not allowed to read or write property values directly from a form or any of its child controls. This restriction exists because form objects and control objects in Windows Forms are not thread-safe. The only thread that's allowed to directly access a property value of a form or one of its controls is the primary UI thread. You must learn how to update the user interface without breaking this rule.
The technique you're going to learn here involves writing code to switch control to the primary UI thread from the secondary thread where it's executing—a process known as marshaling. This will allow you to update the UI safely and reliably. Once you switch control from a secondary thread to the primary UI thread, you are free to change any property values of a form and its child controls.

Asynchronous method execution using delegates

[Full article]This month I'll discuss the use of delegates to execute a method in an asynchronous fashion. I'll assume that you already know the fundamentals of programming with delegates, but if not, you should read the December 2002 and January 2003 Basic Instincts columns.
There are a number of scenarios in which asynchronous execution can be a valuable design technique. For example, you should use asynchronous execution in a Windows® Forms application when you want to execute a long-running command without blocking the responsiveness of the user interface. As you will see, programming with delegates makes it relatively easy to run a command asynchronously on a secondary thread. That means you can build a Windows Forms application that executes long-running calls across the network without freezing the user interface.
Executing methods asynchronously can also serve as a useful technique for a server-side application. Imagine you are writing the code behind an ASP.NET page to service a client request. What should you do if your code needs to execute two or more time-consuming calls across a network? For example, imagine you are required to write an ASP.NET page that must run a query against a remote database and also must execute a SOAP method on a remote Web Service to complete its work. If you don't use asynchronous method execution, you can only make one call across the network at a time. This means you can't start the second network call until the first network call returns. Asynchronous method execution using delegates lets you execute two or more network calls at the same time. This can significantly reduce the time it takes to process a server-side ASP.NET request, increasing the responsiveness of your application from the user's perspective.

Wednesday 19 December 2007

C# docking panel suit

http://sourceforge.net/projects/dockpanelsuite/

Thursday 13 December 2007

Skills measured by Exam 70-431Course 2778ECourse 2779Course 2780Installing and Configuring SQL Server 2005

Install SQL Server 2005.

Verify prerequisites.

Upgrade from an earlier version of SQL Server.

Create an instance.

Configure SQL Server 2005 instances and databases.

Configure log files and data files.

Configure the SQL Server DatabaseMail subsystem for an instance.

Choose a recovery model for the database.

Configure SQL Server security.

Configure server security principals.

Configure database securables.

Configure encryption.

Configure linked servers by using SQL Server Management Studio (SSMS).

Identify the external data source.

Identify the characteristics of the data source.

Identify the security model of the data source.

Implementing High Availability and Disaster Recovery

Implement database mirroring.

Prepare databases for database mirroring.

Create endpoints.

Specify database partners.

Specify a witness server.

Configure an operating mode.

Implement log shipping.

Initialize a secondary database.

Configure log shipping options.

Configure a log shipping mode.

Configure monitoring.

Manage database snapshots.

Create a snapshot.

Revert a database from a snapshot.

Supporting Data Consumers

Retrieve data to support ad hoc and recurring queries.

Construct SQL queries to return data.

Format the results of SQL queries.

Identify collation details.

Manipulate relational data.

Insert, update, and delete data.

Handle exceptions and errors.

Manage transactions.

Manage XML data.

Identify the specific structure needed by a consumer.

Retrieve XML data.

Modify XML data.

Convert between XML data and relational data.

Create an XML index.

Load an XML schema.

Implement an HTTP endpoint.

Create an HTTP endpoint.

Secure an HTTP endpoint.

Implement Service Broker components.

Create services.

Create queues.

Create contracts.

Create conversations.

Create message types.

Send messages to a service.

Route a message to a service.

Receive messages from a service.

Import and export data from a file.

Set a database to the bulk-logged recovery model to avoid inflating the transaction log.

Run the bcp utility.

Perform a Bulk Insert task.

Import bulk XML data by using the OPENROWSET function.

Copy data from one table to another by using the SQL Server 2005 Integration Services (SSIS) Import and Export Wizard.

Manage replication.

Distinguish between replication types.

Configure a publisher, a distributor, and a subscriber.

Configure replication security.

Configure conflict resolution settings for merge replication.

Monitor replication.

Improve replication performance.

Plan for, stop, and restart recovery procedures.

Maintaining Databases

Implement and maintain SQL Server Agent jobs.

Set a job owner.

Create a job schedule.

Create job steps.

Configure job steps.

Disable a job.

Create a maintenance job.

Set up alerts.

Configure operators.

Modify a job.

Delete a job.

Manage a job.

Manage databases by using Transact-SQL.

Manage index fragmentation.

Manage statistics.

Shrink files.

Perform database integrity checks by using DBCC CHECKDB.

Back up a database.

Perform a full backup.

Perform a differential backup.

Perform a transaction log backup.

Initialize a media set by using the FORMAT option.

Append or overwrite an existing media set.

Create a backup device.

Back up filegroups.

Restore a database.

Identify which files are needed from the backup strategy.

Restore a database from a single file and from multiple files.

Choose an appropriate restore method.

Move a database between servers.

Choose an appropriate method for moving a database.

Monitoring and Troubleshooting SQL Server Performance

Gather performance and optimization data by using the SQL Server Profiler.

Start a new trace.

Save the trace logs.

Configure SQL Server Profiler trace properties.

Configure a System Monitor counter log.

Correlate a SQL Server Profiler trace with System Monitor log data.

Gather performance and optimization data by using the Database Engine Tuning Advisor.

Build a workload file by using the SQL Server Profiler.

Tune a workload file by using the Database Engine Tuning Advisor.

Save recommended indexes.

Monitor and resolve blocks and deadlocks.

Identify the cause of a block by using the sys.dm_exec_requests system view.

Terminate an errant process.

Configure SQL Server Profiler trace properties.

Identify transaction blocks.

Diagnose and resolve database server errors.

Connect to a non-responsive server by using the dedicated administrator connection (DAC).

Review SQL Server startup logs.

Review error messages in event logs.

Monitor SQL Server Agent job history.

Identify the cause of a failure.

Identify outcome details.

Find out when a job last ran.

Gather performance and optimization data by using DMVs.

Creating and Implementing Database Objects

Implement a table.

Specify column details.

Specify the filegroup.

Assign permissions to a role for tables.

Specify a partition scheme when creating a table.

Specify a transaction.

Implement a view.

Create an indexed view.

Create an updateable view.

Assign permissions to a role or schema for a view.

Implement triggers.

Create a trigger.

Create DDL triggers for responding to database structure changes.

Identify recursive triggers.

Identify nested triggers.

Identify transaction triggers.

Implement functions.

Create a function.

Identify deterministic versus nondeterministic functions.

Implement stored procedures.

Create a stored procedure.

Recompile a stored procedure.

Assign permissions to a role for a stored procedure.

Implement constraints.

Specify the scope of a constraint.

Create a new constraint.

Implement indexes.

Specify the filegroup.

Specify the index type.

Specify relational index options.

Specify columns.

Specify a partition scheme when creating an index.

Disable an index.

Create an online index by using an ONLINE argument.

Create user-defined types.

Create a Transact-SQL user-defined type.

Specify details of the data type.

Create a CLR user-defined type.

Implement a full-text search.

Create a catalog.

Create an index.

Specify a full-text population method.

Sunday 9 December 2007

Basic of GDI+ and Graphics in ASP.NET

Introduction
In this article, I will explain about GDI+ in .NET Framework. If you haven't heard about GDI+, then GDI+ is a set of classes in .NET framework that deal with graphics. You can use GDI+ to draw custom drawing on the screen. GDI provides a layer of abstraction, hiding the differences between different video cards. You simply need to call the Windows API function to do the specific task, and internally the GDI figures out how to get to the client's particular video card to do whatever that you want.Although GDI exposes a relatively high level API to developers, it is still an API that based on the old Windows API with C style functions. GDI+ sits as a layer between GDI and your application providing more intuitive and inheritance based object model. GDI+ is generally considered a Windows technology. However, some of the new GDI+ features make this technology an excellent choice for Web applications, enabling developers to generate images, graphs, diagrams, and much more.


http://www.worldofasp.net/aspnet/Tutorials/GDI/Basic_of_GDI+_and_Graphics_in_ASP.NET_119.aspx

Wednesday 5 December 2007

TrueCrypt: Free open-source disk encryption software for Windows Vista/XP/2000 and Linux

T r u e C r y p t
Free open-source disk encryption software for Windows Vista/XP/2000 and Linux
Main Features:
Creates a virtual encrypted disk within a file and mounts it as a real disk.


Encrypts an entire hard disk partition or a storage device such as USB flash drive.


Encryption is automatic, real-time (on-the-fly) and transparent.


Provides two levels of plausible deniability, in case an adversary forces you to reveal the password:

1) Hidden volume (steganography – more information may be found here).

2) No TrueCrypt volume can be identified (volumes cannot be distinguished from random data).


Encryption algorithms: AES-256, Serpent, and Twofish. Mode of operation: LRW.
Further information regarding features of the software may be found in the documentation.

http://www.truecrypt.org/

Open Source Web Design

www.oswd.org

Tuesday 4 December 2007

Firefox Add-ons: Split Browser

This splits the content area of the browser window as you like.
This splits the content area of the browser window as you like. It will help you in various cases. For example, to compare multiple webpages, to show a calendar always, and so on.There is some ways to split window.* Choose the "Split Browser to" menu in the context menu.* Choose the "Load in Split Browser" menu in the context menu on link.* Click popup-button on top/bottom/left/right edges of the content area.* Drop links, bookmarks, etc. to popup-button on top/bottom/left/right edges of the content area while dragging.

https://addons.mozilla.org/en-US/firefox/addon/4287

Sunday 2 December 2007

Use TEXTCOPY to restore and retrieve images from a SQL Server Table

Storing and Retrieving Images From a SQL Server Table
by Gregory A. Larsen

Most applications use images of some kind, like a .jpg or .gif file. One application might only have a few images, while another application could have thousands of images. The images might only be read or written a few times, or be used frequently by an application. When an application needs to store images, you need to determine how best to store and manage your images. This article will show you how to insert and extract images from a SQL Server database as well as discuss issues related to storing your images in SQL server.
Advantages and Disadvantages of Storing Images in SQL Server
Even Microsoft does not recommend storing images in SQL Server, because this causes performance and database disk space issues. An application that stores images in a SQL Server database will experience performance problems each time an image is stored or retrieved from SQL Server because of the way SQL Server needs to store or retrieve images.
SQL Server needs to convert an image that is larger than 8K into multiple chunks, and then store these chunks on separate SQL Server pages. When SQL Server retrieves a large image stored in a database, the image must be retrieved in chunks and converted back into an image. This process of breaking up an image into chunks and reassembling these chunks back into images is what causes performance problems. Also, storing images in a database will make the database considerably larger, so backing up and restoring the database will take longer.
Knowing how often your application is going to insert, update, and select an image from a database might help you to determine how greatly performance will be degraded if you store your images in a SQL Server database. If you are only inserting the image once, and retrieving it rarely, then the performance hit will be minimal for each usage of an image. On the other hand, if your application is serving up a single image frequently, then the performance drain on SQL Server could be significant. When the performance impact is significant, it is best to just save the image natively in a file system and store only a pointer (a URL or an actual file location ) to the file in SQL server.
There are advantages to storing images in a SQL Server database, however. One advantage is that it simplifies managing the images. If you want to move your database to a different database server, it is as easy as copying the database. Another advantage of storing the images in SQL Server is the extra layer of security around the images. By storing images in SQL Server, you can manage access to images using SQL Server logins and roles. This extra layer of security makes it harder for an individual to gain access to your application images.
Using TEXTCOPY to Store and Retrieve an Image from SQL Server
SQL Server provides a binary named “TEXTCOPY” to import and export an image to and from SQL Server. This “.exe” is stored in the “…\MSSQL\Binn” directory. The following is the syntax for using this executable:TEXTCOPY [/S [sqlserver] ] [/U [login] ] [/P [password] ]
[/D [database] ] [/T table] [/C column] [/W"where clause"]
[/F file] [{/I /O}] [/K chunksize] [/Z] [/?]
/S sqlserver The SQL Server to connect to. If 'sqlserver' is not
specified, the local SQL Server is used.
/U login The login to connect with. If 'login' is not specified,
a trusted connection will be used.
/P password The password for 'login'. If 'password' is not
specified, a NULL password will be used.
/D database The database that contains the table with the text or
image data. If 'database' is not specified, the default
database of 'login' is used.
/T table The table that contains the text or image value.
/C column The text or image column of 'table'.
/W "where clause" A complete where clause (including the WHERE keyword)
that specifies a single row of 'table'.
/F file The file name.
/I Copy text or image value into SQL Server from 'file'.
/O Copy text or image value out of SQL Server into 'file'.
/K chunksize Size of the data transfer buffer in bytes. Minimum
value is 1024 bytes, default value is 4096 bytes.
/Z Display debug information while running.
/? Display this usage information and exit.
You can call this executable without any parameters or a subset of parameters. When you execute the “exe,” if there are any required parameters missing, you will be prompted to enter the missing parameters. The following is an example of a command that will save an image to SQL Server, and then one that will export an image to a file system from SQL Server.
First, I first need to insert an image. The following is an image named “c:\temp\glacier.jpg” that I will be storing:
This image will be stored in a table named “Image.” The statement I used to create this Image table can be found in weblisting1. To insert the “glacier.jpg” picture into my SQL Server table, I use the following command at the DOS prompt:C:\Program Files\Microsoft SQL Server\MSSQL\Binn\TEXTCOPY.exe" /S(local)
/Umylogin /Pmysapassword /D TEST /T Image /C Picture /F "C:\temp\glacier.jpg"
/W"where Title='glacier'" /I
This example, when executed by the DOS command shell, copies the image “glacier.jpg” into a table “Image” into a database I created and named “TEST.” With this command, I can log on to my local SQL Server database using a SQL Server login named “mylogin.” Note that the TEXTCOPY executable does not support Windows authentication. The “/W” parameter identifies a “WHERE” clause that will identify the single record to be updated in the “Image” table. The “/W” parameter is required to start, with “where” followed by a criteria that will identify a single record. The TEXTCOPY .exe requires that a shell record be already stored in the “Image” table so that it can updated. This shell record is the record identified by the /W parameter. In this shell record, the image column “Picture” must have a non-null value. I used the following code to create the shell record prior to running the TEXTCOPY command above:insert into Image(Picture,Title) values(0x0,'Glacier')
If there is no shell record for TEXTCOPY to update, then you will get the following error:TEXTCOPY Version 1.0
DB-Library version 8.00.194
ERROR: Row retrieval failed.
If you have created the shell record, but the Picture column is NULL, the following error will be displayed:TEXTCOPY Version 1.0
DB-Library version 8.00.2039
ERROR: Text or image pointer and timestamp retrieval failed.
If you are storing images in SQL Server, you will probably also need to retrieve them. TEXTCOPY can be used to create a file from an image stored in SQL Server. An example follows of how to use TEXTCOPY to retrieve the glacier picture from SQL Server and save it to a file:"C:\Program Files\Microsoft SQL Server\MSSQL\Binn\TEXTCOPY.exe" /S(local)
/Umylogin /Pmysapassword /D TEST /T Image /C Picture /F
"C:\temp\glacier_out.jpg" /W"where Title='glacier'" /O
The only difference between this command and the one that saved the image into SQL Server is that the “/O” option was used, instead of the “/I” option. Note that if you try to create an output file and the image doesn’t exist, the process will successfully complete, but the file will be zero bytes in length.
As you can see, the TEXTCOPY executable allows you to copy a single image to or

Saturday 1 December 2007

.Net programming standards and name conventions

.Net programming standards and name conventions

Guidelines – a hidden feature for the Visual Studio Editor

Update 12/2/2004: Uploaded an image from Visual Studio 2005 Beta. Note the image below shows guidelines at column numbers 5 and 30, but the regkey value is RBG(255,0,0), 4, 29. The Guideline column numbers are 0-based in the registry.



Update 11/29/2004: I've corrected the two (embarrassing) typos below. I must have had thanksgiving dinner on the brain at the time. 1. The reg key is [HKEY_CURRENT_USER]\Software\Microsoft\VisualStudio\8.0\Text Editor (note the space between Text and Editor). 2. It's RGB, not RBG. The example had a typo, but it is now corrected.

Guidelines are visible column indicators for the VS Editor. During the last test pass, I came across a test case named “Guidelines” which got my immediate attention. I never heard of this before, so I made sure to spend extra time testing this cool, but hidden little feature during the Beta test pass. I didn’t find any issues with it, so I feel it is safe to share. Let me know if you run into any issues with it.



Warning! To enable guidelines, you’ll need to modify your registry settings. Follow the instructions below at your own risk.



Enabling Guidelines



First, shut down Visual Studio 2005 if already started.



Under

[HKEY_CURRENT_USER]\Software\Microsoft\VisualStudio\8.0\Text Editor

Create a string value called

Guides



Set Guides to the following

RGB(x,y,z) n1,...,n13

Where x,y,z are the RGB values and n is the column number. You can have at most 13 guidelines.



For example,

Guides = RGB(128,0,0) 5, 80

will place a Red guideline at column numbers 5 and 80.



And now launch VS and open a text file.



Disabling Guidelines



An obvious no-brainer, just delete the Guides keys you created above. Restart VS, and no more guidelines.