Archive for November, 2009


The Issue:

I’m writing a site with one page that uses the session variable (User ID) to pick one user ID out of a comma separated list in the field Faculty. The default parameterized query designed in the SqlDataSource wizard only returns lines that contain an exact match:

The Issue:

I need to link to xmllite.lib library for one of my projects. I am seeing the following linker error:

1>XmlHandler.obj : error LNK2019: unresolved external symbol _CreateXmlReader@12 referenced in function “public: __thiscall XmlHandler::XmlHandler(class ATL::CStringT > >)” (??0XmlHandler@@QAE@V?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@@Z)

I tried adding the path to xmllite.lib in Tools->Options->VC++ Directories under libraryfiles but no luck.

I also tried to add explicitly thro’ code the following lines but still had no luck:
#pragma comment(lib, “C:Program FilesMicrosoft SDKsWindowsv6.0Libx64xmllite.lib”)

I tried to look at the exports in dumbin and it seems that the exported method is CreateXmlReader but at linking time it is trying to find _CreateXmlReader. Could this be the issue? If so, how to have my compiler not to add the additional “underscore” beside the method name. Or is this how compilers always do it?

Looking for any help or suggestions.

The Solution:

Add the path to your lib file in the “Tools->Options->VC++ Directories->Library files” like you did.

Then either use the pragma to link the lib in or add the lib file to your project via the project properties.
I don’t use pragma but the two approaches achieve the same thing.
Here’s how to do it via the property pages:

1) Right click the project
2) Select “Properties”
3) Navigate to “Configuration Properties->Linker->Input”
4) In additional dependecies add “xmllite.lib”

One last question though, are you building a 64-bit version? If not, you should use the xmllite.lib file found in
C:Program FilesMicrosoft SDKsWindowsv6.0Lib.

As Chinese word 地理 for example.

Issue:
Following line won’t work, 地理 will show as ?? in command line.
_tprintf(_T(“Locale 地理”));

Solution:
Call

.Net – X509Certificate2 vs X509Certificate

The x509Certificate was introduced in .NET v1.0/1.1 and was (comparatively) limited in its functionality. It can be used to get information about an existing certificate (valid dates, issuer, etc.). It had simple methods/operations (i.e. reading a cert from disk).

The x509Certificate2 is a superclass of the x509Certificate.

  • It represents an actual X509 certificate.
  • It was new in the .NET Framework v2.0.
  • This class gives you access to all the V2 and V3 properties (authority key identifier and key usage).
  • It supports loading a certificate from a certificate store.

C# Retrieving and Saving Data in Databases

There is all sorts of literature on this topic but people still keep asking the same questions. I’m creating this thread so I can send people here to look at some example code that I know will demonstrate all the principles they need. These principles can be extended or adjusted and applied to any data access situation. This code uses members of the System.Data.SqlClient namespace. If you’re not using SQL Server then it’s a simple matter of switching to the corresponding types of the appropriate namespace for your data source. For example, if you’re using an Access database then you’d use an OleDb.OleDbConnection rather than an SqlClient.SqlConnection.

Retrieving a single value. The ExecuteScalar method returns the value from the first column of the first row of the query’s result set:

CSharp Code:
  1. using (SqlConnection connection = new SqlConnection("connection string here"))
  2. {

Toward Better Design in Native C++

When you need to write a Windows service application in C++, does it end up looking something like this? If you don’t understand this code, don’t worry we’ll get to that in a minute.

SERVICE_STATUS_HANDLE handle = 0;

SERVICE_STATUS status = { SERVICE_WIN32_OWN_PROCESS,

This article discusses:

  • How XmlLite compares to other available XML parsers
  • The strengths and limitations of XmlLite
  • Reading and writing XML
  • XML security considerations
This article uses the following technologies:
XML, C++

Error:
Invalid

Tips for Using the Vista Command Shell

Command-line tips specific to Windows Vista are given.

For the most part, the features of the command line are the same in Vista as they are in Windows XP but there are some differences. (The Vista version is 6.0 whereas the XP version is 5.1.) Here are some tips that apply only to Vista.

Run as administrator in Vista

The Windows Vista operating system has a security feature called User Account Control that limits the privileges of users by default. Since the command line is usually involved with administrative tasks, you’ll often want to run as an administrator. This can be done each time by right-clicking the icon for the command prompt and choosing “Run as” from the context menu . A more convenient way is to set the command prompt to run with administrator privileges by default. Right-click the command prompt shortcut icon and choose “Properties” from the context menu. Click the “Advanced” button and put a check by “Run as administrator”. Click “OK”. Note that you will still get the UAC message when you open the command prompt.

Another way to run the command prompt as administrator is to enter “cmd” in Start Search and then use the keyboard combination Ctrl+Shift+ Enter.

“Open Command Window Here” in Vista

It is now easy to open a command prompt referenced to a folder of your choice in Vista. If the Shift key is held down while right-clicking a folder, the context menu will contain an entry, “Open Command Window Here”. Selecting this entry will open a command prompt with the chosen folder as the reference point for commands.

Open command window with administrator privileges anywhere

The “Run as administrator” option mentioned above always opens with \Windows\System 32\ as the working directory. To open a command console with administrator privileges in any directory of choice, you can add a command to the right-click context menu. The INF file to make the appropriate Registry edit can be downloaded here. It is from the PowerToy utility described at this link.

Send command output to the Windows clipboard with clip.exe

Vista comes with a command-line utility clip.exe that can be used to redirect or pipe the output of another command to the Windows clipboard. The command uses a “pipe” and has the form: somecommand | clipFor example, to send a directory listing to the clipboard, the command is: dir | clip

Place the contents of a text file into the Windows clipboard with clip.exe

The utility clip.exe can also be used to read a text file and place its contents in the Windows clipboard. The command has the form: clip < somefile.txt

The batch file command called "choice" is back in Vista

Oldtimers will remember that DOS had a command for batch files called "choice" that allowed for some limited user interaction. The command was then removed from 32-bit command shells because the "set /p" option gave equivalent or better functionality. However, "choice" is back in Vista in a new form. Enter "choice /?" in a Vista command prompt for details about its features.

Use the "choice" command to make a Vista batch file wait

One useful application of the "choice" command is to make a batch file pause for a specified period of time. The statement has the form: choice /T n /D y > nul The switch "/T n" specifies a wait period of n seconds. The switch "/D y" creates a default choice of "yes". To suppress the unwanted text output of the command, it is redirected to the null device (nul).

Use the "timeout" command to make a Vista batch file wait

Another new command in in Vista is "timeout". It will cause the command processor to wait for a specified number of seconds or until a key is pressed. The format is timeout /T n where n is the number of seconds to wait. To make the command ignore any key presses, the switch /nobreak can be added: timeout /T n /nobreak Because the command gives output listing the time remaining, it may be necessary to use a redirect to nul. timeout /T n > nul

Switch added to "Dir" to enable viewing Alternate Data Streams

NTFS files can have added information in "streams" or "forks". These added items are normally hidden from access by most Windows functions such as Explorer. In Vista a switch /R has been added to the "dir" command that allows alternate data streams to be listed.

Enable the built-in master administrator account on the log-in screen

Vista contains a master administrator account but it is not normally visible on the log-in screen. To enable it, open a command window with administrator privileges and use the command net user administrator /active:yes (Make sure that you assign a password to the account.) To remove the account from the log-in screen, use the command net user administrator /active:no

Reduce the space used by System Restore

System Restore can use up to 15% of a hard drive for its backup files (shadow storage). As hard drives get ever bigger, that becomes a lot of space. The command "vssadmin" can be used to administer settings for System Restore. To control the space allocation, open a command prompt with administrator privileges and enter vssadmin Resize ShadowStorage /For=C: /On=C: /Maxsize=[n] For [n] enter the desired size in MB or GB. The units must be stated: for example, "Maxsize=500MB" or "Maxsize=2GB". The example is for the C: drive. WARNING! This will delete all your old Restore Points!

Increase the file system memory cache

If you tend to open and close a lot of files, you may be able to increase performance by creating a larger value for a special cache setting with the file system utility command fsutil behavior set memoryusage 2According to Microsoft, this increases something called the "paged pool" memory. Do not use if you are already consuming large amounts of system memory with other activities. If performance after the change is unsatisfactory, undo it with the commandfsutil behavior set memoryusage 1These commands require administrator privileges. The commands change a Registry setting and take effect after a reboot.

Use "takeown" to access certain files

Vista protects many system files for security reasons and even an administrator is not allowed to access them. If you are denied access to a file while in an administrator account, you can use the command line tool "takeown.exe" to reassign ownership. You will need to run the command from a command prompt with administrator privileges. The syntax is takeown /f some_file [/a] [/r]The specified filename can contain wildcards. You can also specify a folder. The optional switch "/a" transfers ownership to the administrators group. If omitted, the default is to transfer ownership to the present user account. The switch "/r" recurses subdirectories. Although this command assigns ownership, it does not give control rights. Thus if you wish to modify a system file (often not a good idea) you will probably have also to apply the "icacls" command discussed next.

Obtain control rights to a file with "icacls"

(Icacls.exe supersedes the "cacls" command of Windows XP. The older command is still available, however.) This command has a rather complex set of options. They can be displayed by entering "icacls /?" in a command prompt. One example is the command to grant full access rights to an account named user:icacls file_name /grant user:F

Clean up Vista SP1 files

When you install Vista service pack 1, a facility for uninstalling it is also created. If you have SP1 installed for a while and are satisfied that you will keep it, you can remove the uninstall files and free up almost a GB of disk space. To remove the backup files, use the command VSP1CLN.EXE (I have used caps to make the difference between "one" and "ell" clear but case doesn't matter.) Administrator privileges are required. After running this command, you will be unable to uninstall Vista SP1 so be sure you really want to keep it.

Using drag and drop- not

The useful capability to drag commands and drop them into a command prompt that was present in past versions of Windows does not work in Vista. (However, it has been restored in Windows 7.)

Tips for Using the Windows Command Prompt

Here’s an assortment of tips and tricks for using the Windows command shell.
There are certain little tricks that books on the command prompt don’t always tell you. Or, if they do, the description is buried away in a paragraph somewhere. Experienced users of the command line know all about these. However, average users may not and I am going to mention a few useful tips for them. As far as I know the tips work in both Windows XP and Vista except where noted. They may or may not work for older editions of Windows. Tips for Vista only are given on another page.

How to make a blank line in a batch file

Sometimes you would like a blank line or two in the output from a batch file. It isn’t immediately clear how to do this. Simply entering “echo” doesn’t work because that will output the status of command echoing. The trick is to enter echo.Note that “echo” is followed by a period with no space in between.

Force the “echo” command not to parse arguments

The preceding tip is a special case of a more general method for using the “echo” command. Although the command is used to display text or messages, it can also take certain arguments such as “on” or “off”. If you write echo off you will not get a display of the string “off” but will actually be configuring the “echo” command itself. To display the string “off”, you would use echo. off In other words, placing a period at the end of “echo” forces the command to simply display whatever follows without checking to see if the string is one of the special cases.

Check if a file exists

A special variant of the “If” statement can be used to find out if a file is already present. The statement is if exist somefile somecommand The statement can also test for non-existence of a file with if not exist somefile somecommand

The useful device “nul”

The invisible null device called “nul” has a number of uses. (It’s also sometimes called the “bit bucket” or the “black hole”.) Anything sent to it disappears. It can be used in statements when you do not want output to be dIsplayed. For example the command somecommand > nul will carry out some command but send whatever is the normal output into oblivion. Sometimes in a batch file you do not want any possible error messages to be displayed. This is done by using somecommand 2> nul Another use for nul is to apply a command, which normally works only on files, to a directory instead. For example, it’s useful sometimes to check if a directory already exists. The statement if exist something somecommand will check for the existence of a file but doesn’t work for a directory. However all directories contain the null device so you can use this statement if exist somedirectory\nul to check if a directory already exists.

Stopping a runaway command

Sometimes you start a command only to find that it is going on and on, spewing out screen after screen of output. Most of the time you can terminate a command by simultaneously pressing the two keys “Ctrl” and “c”.

Pausing a scrolling screen

If you have a command with a lot of output,, you can pause the scrolling so that you can read what’s on the screen. Use the keyboard combination “Ctrl+s”. To resume scrolling, repeat Ctrl+s

Use drag and drop

Having to type the fully qualified path of a file every time it’s needed in a command can be tedious and subject to error. Many people are unaware that a file can be dragged from a folder or Windows Explorer view and dropped on an open command window. It saves a lot of typing. (Doesn’t work in Vista)

Go up one level above the working directory

Any Unix user knows this one but it’s often new to Windows users. To go up to the directory that is one level above the working directory, enter cd .. You can repeat this to go up more levels. It’s a little off the subject of the command shell but in the Start-Run line just entering the two periods “..” will also take you up one level from the default working directory (the working directory is normally
%USERPROFILE%)

How to change the working directory to a folder on a different drive

If you want to change the working directory for a command window to a folder on a different drive, the command “cd” doesn’t work. You have to first enter the drive letter and colon and then enter “cd” and the folder path. However, you can use the switch /d to change the current working directory drive as shown below: cd /d E:\testYou can also make the change with one command entry if you use “pushd” instead of “cd”: pushd E:\test

Watch out for spaces in file and folder names

The command shell does not recognize spaces in path names. Any path name with spaces must be enclosed in quotation marks. This problem often crops up in scripts where certain environment variables or input arguments are used. For safety, variables that involve file or folder names should be enclosed in quotes.

Special treatment of variables in “For” statements in batch files

“For” statements are very useful, providing powerful iterative methods. They have the peculiarity, however, of requiring double percent signs for iteration variables in batch files. in other words the syntax in a batch file is:for %%variable In set Do statementIf a “For” loop is run directly from the command line, only a single percent sign is used. The syntax is then: for %variable In set Do statement

Case-sensitive variables in “For” statements

In contrast to Unix systems, Windows is usually not case-sensitive, However, iteration variables in “For” statements are case-dependent. So %A is a different variable from %a.

Pin a command-line shortcut to the Start menu

If you use the command prompt frequently, make it easily accessible. Open Start-All Programs-Accessories and right-click the entry “Command Prompt”. Select “Pin to Start menu” from the context menu. Or go to \WINDOWS\system32 and right-click the command shell file cmd.exe and select “Pin to Start menu” from the context menu.

Create a shortcut to a command

If there is a command that you use frequently, you can create a shortcut. The trick is to use the switch /k so that the command prompt stays open. The entry for the shortcut should be cmd /k somecommand.exeIf the command also needs switches, those can added as well. (The general details of making a shortcut are at this page.)

Open Windows Explorer from the command line

To open the current command-line directory in a Windows Explorer window use the command start .To open the directory above the current command-line directory in a Windows Explorer window use the commandstart ..(Windows XP only) To open My Computer in a Windows Explorer window use the commandstart ...

Using the command “Start”

The tip given above is an example of how the “Start” command can be used to invoke an action or a system folder or an URL. For example, simply entering “cookies” in the Run line will open the system folder Internet Cookies in Windows XP (but not in Vista). However, in the command shell, you would need to enter start cookies In Vista, the command has to be modified with the Shell command and would be start shell:cookies Similarly, you can open a program like Microsoft Word with the commandstart winwordYou can also open a Web page in Internet Explorer with a command of the typestart http://somesite.com

Save typing with file-name and folder-name completion (Tab completion)

A very useful feature that can save a lot of typing is the name or path completion function. This feature uses the Tab key to complete file and folder names that you begin typing. For example, type “a” (no quotes) into a command line and then press the Tab key. Windows will complete your typing with the name of an existing file or folder beginning with “a”, starting in alphabetic order. Press Tab again and the next possible file or folder will be displayed. In this way, you can cycle through all files and folders existing in your current path that begin with a particular character or group of characters. The keyboard pair Shift + Tab will take you backwards in the list. The tab completion function can be used in more than one place in a command.

Enable QuickEdit mode for the command window

Being able to cut and paste to and from the command window is very handy but it is not enabled by default. I use this feature frequently and I suggest that you enable it for all command windows. The details of how to enable QuickEdit are given on another page. Once QuickEdit is enabled, the contents of the clipboard can be entered into a command prompt by right-clicking in the command window.

Display the Command History

The default setting for the configuration of a command window includes the capability for storing up to 50 previously entered commands. The command history can be displayed by entering the “F7″ key.

Use the “sleep” command in Windows XP batch files

Sometimes it is desirable to have a batch file wait a certain amount of time before it carries out the next command. If you download the free Windows 2003 Server tools (described on another page), one of the available tools is sleep.exe, which provides a way to make batch files wait a specified interval. For an interval of n seconds the command is: sleep n

Copy text from the console window

Way back in the days of DOS, it was not uncommon to enter text directly from the command window into a file with the “copy” command. That is less common in Windows but the capability is still there. Output from the command window or console is denoted by CON. (It is not case-sensitve.) To copy text from the command window to a file “sometext.txt”, the sequence of statements would be copy con sometext.txt
First line of your desired text
some more text...
^Z
The last line indicates the keyboard combination of the Control key and “z” followed by pressing the Enter key. This command terminates the sequence and sends the text to the desired file, which it creates. This particular example places the file in the working directory but other paths can be used.

Tips for the Vista command shell

Windows XP and Vista share many of the same features in the command line. However, as to be expected, there are some differences. Tips that are relevant to Vista only are given on the next page.

Powered by WordPress | Theme: Motion by 85ideas.