Wednesday, March 30, 2005

ReHash - A console-based hash calculator

http://www.codeproject.com/cpp/ReHash.asp ReHash is a free, open source console-based hash calculator. You can disable hash algorithms selectively per command-line if you don't need or like them, you can choose if you want to use recursive directory scanning or not.

Monday, March 28, 2005

Opening a command prompt for your project

Opening a command prompt for your project

Sometimes while working with a VS.Net project, you need to run a command line tool, either on the sources or output of the project. VS provides an easy way to add a menu item that will open a command prompt in the target directory of your application, or in the source folder.

In order to enable this, first go to the Tools menu, and choose External Tools. In the add dialog box, create a new item, and give it a name such as Source Shell. The command should be cmd.exe. For initial directory, you can pick one of:

  • $(ProjectDir) - source code for the current project
  • $(SolutionDir) - root directory of the current solution
  • $(TargetDir) - build location of the current project. This will adjust for different configurations, so it will open a shell in bin\Debug for debug builds, and bin\Release for release builds.

In my copy of VS I have a menu option for Source Shell, opening in $(ProjectDir), and one for Build Shell, opening in $(TargetDir). I also have a quick script that I run that sets up various environment variables, network drive maps, and drive substitutions, in order for me to have a useful dev command window. I get this script to run by adding

/k SetDevEnv.cmd

To the arugments line.

Wednesday, March 23, 2005

Tuesday, March 22, 2005

Indian Grocery Store in Spokane

Bollywood Video and Groceries 1812 East Sprague Avenue, Spokane, WA 99202 (509) 484-6365 Apparently it is close to Costco on Sprague Ave - so if you can look that up, you should be able to figure out the grocery store as well. Yellow Pages

Why does the debugger show me the wrong function? - identical COMDAT folding

Why does the debugger show me the wrong function?

Often you'll be minding your own business debugging some code, and you decide to step into one function and the debugger shows that you're in some other function. How did that happen?

class Class1
{
public:
 int *GetQ() { return q; }
private:
 int *p;
 int *q;
};
 
class Class2
{
public:
 virtual int GetValue() { return value; }
private:
 int value;
};

You then step through code that does something like this:

int Whatever(Class2 *p)
{
 return p->GetValue();
}

And when you step into the call to p->GetValue() you find yourself in Class1::GetQ. What happened?

What happened is that the Microsoft linker combined functions that are identical at the code generation level.

?GetQ@Class1@@QAEPAHXZ PROC NEAR    ; Class1::GetQ, COMDAT
  00000 8b 41 04         mov     eax, DWORD PTR [ecx+4]
  00003 c3               ret     0
?GetQ@Class1@@QAEPAHXZ ENDP         ; Class1::GetQ
 
?GetValue@Class2@@UAEHXZ PROC NEAR  ; Class2::GetValue, COMDAT
  00000 8b 41 04         mov     eax, DWORD PTR [ecx+4]
  00003 c3               ret     0
?GetValue@Class2@@UAEHXZ ENDP       ; Class2::GetValue

Observe that at the object code level, the two functions are identical. (Note that whether two functions are identical at the object code level is highly dependent on which version of what compiler you're using, and with which optimization flags. Identical code generation for different functions occurs with very high frequency when you use templates.) Therefore, the linker says, "Well, what's the point of having two identical functions? I'll just keep one copy and use it to stand for both Class1::GetQ and Class2::GetValue."

0:000> u Class1::GetQ
010010d6 8b4104           mov     eax,[ecx+0x4]
010010d9 c3               ret
0:000> u Class2::GetValue
010010d6 8b4104           mov     eax,[ecx+0x4]
010010d9 c3               ret

Notice that the two functions were merged: The addresses are identical. That one fragment of code merely goes by two names. Therefore, when the debugger sees that you've jumped to 0x010010d6, it doesn't know which of the names it should use, so it just picks on.

That's why it looks like you jumped to the wrong function.

To disable what is called "identical COMDAT folding", you can pass the /OPT:NOICF flag to the linker.

Sunday, March 20, 2005

Gurudwara (Sikh temple) in Spokane, Wa

Visited the Sikh temple of Spokane. Its most probably the only sikh temple between Seattle and Minneapolis. The giani at the gurudwara, was an especially nice person. The address of the gurudwara is Sikh Temple of Spokane 1420 North Barker Road Spokane, WA 99016 Phone: 509-892-9377 directions when driving from Montana. (take exit 293. At the end of the exit, turn right onto Barker road. The gurudwara is on the right side of the road, opposite Conco gas station). The gurudwara has paat every sunday at 11:00am, followed by laangar. About 45 Sikh families live in the area around spokane. While visiting the gurudwara I recommend a visit to Spokane valley mall. Exit 292 (I think). Also visit the Post-Falls outlet center. I believe it was exit no. 2 (into the Post-Falls event center) in Idaho. (The mall is on the right side of i-90, while travelling from Montana - The outlet center is on the left side of I-90) .

Indian restaurant in Spokane, Washington

Top of India, on East Sprague. They have a pretty good buffet, served even on weekends. (The buffet was $7.00). The naans and chicken tikka masala were especially good. This restaurant was previously called Delhi palace and is now under new management. visit it at : 11114 East Sprague Avenue, Spokane Valley, WA 99206 map (from Montana, take exit 291. At the end of the exit, take a left onto Pine st. Drive down pine st and take a right onto East Sprague. Top of india is on the left side)

Thursday, March 17, 2005

DirectX and .Net - Tutorials

http://www.sunlightd.com/Windows/DirectX.NET/ http://users.pandora.be/riemer/index.html

Monday, March 14, 2005

Generating a Random Password - C#

public static string GenerateRandomPassword(int PasswordLength) { string _allowedChars = "abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789!@$?"; Byte[] randomBytes = new Byte[PasswordLength]; char[] chars = new char[PasswordLength]; int allowedCharCount = _allowedChars.Length; Random randomObj = new Random(); for(int i = 0;i < PasswordLength; i++) { randomObj.NextBytes(randomBytes); chars[i] = _allowedChars[(int)randomBytes[i] % allowedCharCount]; } return new string(chars); }

Thursday, March 10, 2005

String to Enumeration Value C#

Here is code, that will take a string value and return the corresponding enumeration value. //t - type of the enumeration static object StringToEnum( Type t, string Value ) { foreach ( FieldInfo fi in t.GetFields() ) if ( fi.Name == Value ) return fi.GetValue( null ); // We use null because enumeration values are static throw new Exception( string.Format("Can't convert {0} to {1}", Value, t.ToString()) ); }

Monday, March 07, 2005

Using MemoryStream .NET

//writing to Memory stream byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText); MemoryStream memoryStream = new MemoryStream(); memoryStream.Write(plainTextBytes, 0, plainTextBytes.Length); memoryStream.FlushFinalBlock(); //getting the bytes from memory stream and converting them to a string byte[] memoryTextBytes = memoryStream.ToArray(); string originalText = Convert.ToBase64String(memoryTextBytes ); //reading from memoryStream byte[] memoryTextBytes2 = new byte[memoryStream.Length]; memoryStream.Seek(0,SeekOrigin.Begin); int readByteCount = memoryStream.Read(memoryTextBytes2 , 0, memoryTextBytes2 .Length); memoryStream.Close(); string plainText = Encoding.UTF8.GetString(plainTextBytes, 0, readByteCount); -------------------------------------------------------------------------------------- using MemoryStream to BinarySerialize into memory -------------------------------------------------------------------------------------- MemoryStream t = new MemoryStream(); BinaryFormatter myFormatter = new BinaryFormatter(); myFormatter.Serialize(t, someObject); //serialize some object byte[] plainTextBytes = new byte[t.Length]; t.Seek(0,SeekOrigin.Begin); int readByteCount = t.Read(plainTextBytes, 0, plainTextBytes.Length); t.Close(); //plainText contains the serialized string string plainText = Encoding.UTF8.GetString(plainTextBytes, 0, readByteCount); ///deserialization byte[] stringAsBytes = Encoding.UTF8.GetBytes(plainText); t = new MemoryStream(stringAsBytes); object newO = myFormatter.Deserialize(t) ;

Friday, March 04, 2005

Free e-books for programmers

Free APress books for download. I really like COM and .NET Interoperability A P R E S S . C O M | Books for Professionals, by Professionals ...

Wednesday, March 02, 2005

.NET Debugger Visualizations - Hashtable

http://msdn.microsoft.com/msdnmag/issues/04/08/NETMatters/default.aspx An article from MSDN mag (Aug 2004), which shows how to create a hashtable visualizer, than can be used during debugging. Very useful.

Dr. GUI .NET #4 - System.Object and Garbage Collection

Dr. GUI .NET Summary: Dr. GUI describes System.Object, the base class of all other .NET Framework types, and shows how to use its methods in any .NET Framework type. The good doctor also. (nn printed pages)

Snippet Compiler

A great tool to compile snippets of C# code Snippet Compiler

New TLAs

CCE

Compute Cluster Edition

HPC

High Performance Computing

ISV

Independent Software Vendor

RTM

Release To Manufacturing

SKU

Stock Keeping Unit

x64

AMD 64-bit and Intel EM64T