You will see a dialog box just like the following when you try to open a .sln file if you using Visual Studio and TFS:
2/02/2010
One or more projects in the solution could not be loaded
6/03/2009
How to re-add database objects into EDMX
8/17/2008
How to reference WPF types in XAML
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:custom="clr-namespace:WpfApplication1"
Title="Window1">
...
</Window>
2. If the WPF types had been defined outside your WPF application, you can append "assembly" clause to "clr-namespace:xxx" and spearate "clr-namespace" and "assembly" clauses by semicolon:
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:custom2="clr-namespace:WpfCustomControlLibrary1;assembly=WpfCustomControlLibrary1"
Title="Window1">
...
</Window>
3. The <?Mapping XmlNamespace="http://your-domain/your-type" ClrNamespace="your-wfp-app-namespace" ?> does not work again that Ian Griffiths and Chris Sells introduced it in [Programming Windows Presentation Foundation ].
5/03/2008
How to partition a USB Flash Drive
Goals:
Partitioning a USB flash drive into 2 partitions. One used to general storage task and it will be supported on both the Windows and Linux; And another partition will be only supported on Linux, then you can use this partition to install a USB-bootable Linux.
Requirements:
1. A runnable Linux operating system. At here, I used Ubuntu 8.04.
2. fdisk: a partition table manipulator for Linux that existing on general Linux system.
2. A USB flash drive.
Step1. Find the USB flash drive device.
sudo fdisk -l
On my machine, I had the following output like this:
Disk /dev/sdb: 523 MB, 523091968 bytes
17 heads, 59 sectors/track, 1018 cylinders
Units = cylinders of 1003 * 512 = 513536 bytes
Disk identifier: 0x6f20736b
So, I assume you had same the device with my which is the /dev/sdb.
Step2. Create the one partition for general storage.
sudo fdisk /dev/sdb
2.1 Use "d" command to delete all existing paritions. First, use "p" command to print the partition table, get the partition number, then repeatedly use "d" command to delete if you have more than one existing partitions. My partition table look like the following output from "p" command:
Device Boot Start End Blocks Id System
/dev/sdb1 1 718 360047+ 6 FAT16
/dev/sdb2 * 719 1018 150450 83 Linux
Then use "d" command to delete:
Command (m for help): d
Partition number (1-4): 2
Command (m for help): d
2.2 Use "n" command to create the partition.
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1018, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1018, default 1018): 509
After above commands had been done, I got a new partition:
Device Boot Start End Blocks Id System
/dev/sdb1 1 509 255234 83 Linux
2.3 Use "t" command to change the partition's system id.
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): b
Finally, the partition has been done, but at here this partition is not compatible with Windows yet.
Device Boot Start End Blocks Id System
/dev/sdb1 1 509 255234 b W95 FAT32
Step3. Create a bootable Linux partition.
Reference Step-2 to create a Linux partition, but use "a" command instead of "t" command that introduced in Step2-3. The "a" command used to toggle partition is bootable.
Command (m for help): a
Partition number (1-4): 2
The final output like this:
Device Boot Start End Blocks Id System
/dev/sdb1 1 509 255234 b W95 FAT32
/dev/sdb2 * 510 1018 255263+ 83 Linux
Step4. Make the general storage partition is compatible with the Windows.
Command (m for help): c
DOS Compatibility flag is not set
Command (m for help): c
DOS Compatibility flag is set
Step5. Commit all work that you had done.
Command (m for help): w
If you do something wrong, you can rollback all your work via "q" command.
Step6. Format the Linux partition to ext3.
This step is optional if you like ext3 file system.
sudo mke2fs -j /dev/sdb2
3/02/2008
An easy way to add Chinese language support for Ubuntu 7.10 English local
1. Add Chinese language support:
sudo apt-get install language-pack-zh language-support-zh language-pack-gnome-zh
2. Install Arphic fonts:
sudo apt-get install ttf-arphic-uming ttf-arphic-ukai ttf-arphic-gbsn00lp ttf-arphic-gkai00mp ttf-arphic-bsmi00lp ttf-arphic-bkai00mp
3. Make a file named local.fonts in /etc/fonts/
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<!-- /etc/fonts.conf file to configure system font access -->
<fontconfig>
<!-- Enable sub-pixel rendering
<match target="font">
<test qual="all" name="rgba">
<const>unknown</const>
</test>
<edit name="rgba" mode="assign"><const>rgb</const></edit>
</match>
-->
<alias>
<family>serif</family>
<prefer>
<family>Bitstream Vera Serif</family>
<family>AR PL ZenKai Uni</family>
<family>AR PL ShanHeiSun Uni</family>
<family>AR PL SungtiL</family>
<family>AR PL KaitiM GB</family>
<family>AR PL Mingti2L Big5</family>
</prefer>
</alias>
<alias>
<family>sans-serif</family>
<prefer>
<family>Bitstream Vera Sans</family>
<family>AR PL ZenKai Uni</family>
<family>AR PL ShanHeiSun Uni</family>
<family>AR PL SungtiL</family>
<family>AR PL KaitiM GB</family>
<family>AR PL Mingti2L Big5</family>
</prefer>
</alias>
<alias>
<family>monospace</family>
<prefer>
<family>Bitstream Vera Sans Mono</family>
<family>AR PL ZenKai Uni</family>
<family>AR PL ShanHeiSun Uni</family>
<family>AR PL SungtiL</family>
<family>AR PL KaitiM GB</family>
<family>AR PL Mingti2L Big5</family>
</prefer>
</alias>
</fontconfig>
4. Restart computer.
2/15/2008
Remove crashed SQL Server 2005 Express installation
If u cannot uninstall the instance of SQL Server 2000 Express installation by general methods, u can try the following steps:
1. Backup all ur data.
2. Stop and then delete all SQL Server services.
sc delete mssqlserver
sc delete mssql$sqlexpress
sc delete mssqlserveradhelper
sc delete sqlbrowser
sc delete sqlwriter
2/08/2008
How to disable Windows Live OneCare?
1. Disable Windows Live OneCare, run as administrator to run the following commands:
sc config msfwhlpr start= disabled
sc config msfwdrv start= disabled
sc config msfwsvc start= disabled
sc config mpfilter start= disabled
sc config onecaremp start= disabled
sc config winss start= disabled
then restart the computer.
2. Enable Windows Live OneCare, run as administrator to run the following commands:
sc config msfwhlpr start= system
sc config msfwdrv start= auto
sc config msfwsvc start= auto
sc config mpfilter start= auto
sc config onecaremp start= auto
sc config winss start= auto
then restart the computer.
1/26/2008
Remove list item from Vista Programs and Features
After uninstalled VS2005, I try to uninstall Microsoft Silverlight 1.0
SDK Visual Studio 2005 Template via Vista Programs and Features. But,
the uninstalling process indicates me that requires VS2005 has been
installed. It's simple to remove the associated files with Microsoft
Silverlight 1.0 SDK Visual Studio 2005 Template, but how to remove the
list from Vista Programs and Features and Windows Registry.
There are two ways to resolve this:
1.Utilize the Windows Install Clean Up utility.
But be care for, the Windows Install Clean Up utility does not remove
the files of any programs that are installed by Windows Installer.
2.Remove the Windows Registry items by hand.
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AFD5020D-65CE-4C4D-B6D8-6AAC29A4A95C}]
12/26/2007
VS2005 and VS2008 .sln file icon incorrect
I had installed VS2005 and VS2008 on Vista Business, both work fine. But today, I found .sln file icon losted and cannot open it with double-click. So I associate .sln with Visual Studio Version Selector, it works again, but the file icon is incorret.
I spent all the afternoon to make a ton of mistakes, the final solution is: associate .sln with <osroot>\Program Files\Common Files\microsoft shared\MSEnv\VSLauncher.exe.
The headache had been resolved, but I cannot find the reality. The conclusion is more bigger and more danger.
12/25/2007
Pseudorandom number generation enhanced in VS2005
1. Define the _CRT_RAND_S macro before the #include <stdlib.h> .
2. Does not need call srand function to generate the seed.
3. rans_s now has returned value which is type of errno_t, zero if successful.
4. Use this formula: dst_num = (unsigned int)((double)rand_num / (double)UINT_MAX * rand_max + rand_min) to specify the range[rand_min, rand_max] .
12/16/2007
A small example of compute Fibonacci's formula statically in C++
How to implement a algorithm computing Fibonacci's formula statically in C++? If it can be done then the more efficient code will be produced. OK, look the a small example below.
template<unsigned int N>
struct Fibonacci {
template<>
struct Fibonacci<1> {
template<>
struct Fibonacci<2> {
int main(int argc, char *argv[]) {
unsigned int v9 = Fibonacci<9>::value;
return (0);
12/11/2007
A sealed class in C++
I want a 'sealed' class in native C++ just like 'sealed' in C++/CLI and C# or 'final' in Java. I googled it then got following solution.
template<typename T>
class DeriveLock {
private:
~DeriveLock() {}
friend T;
class SealedClass : virtual public DeriveLock<SealedClass> {
};
You can found above sample code at Bjarne Stroustrup's article.
10/31/2007
LNK2028, LNK2019 without extern "C"
I wrote a Win32 dll in VS2005 and a CLR-Console client, the CLR-Console client is the caller of Win32 dll. In the Win32 dll, using /TC compiler option to build it and using /clr option to build the CLR-Console client. The all things is fine, such as 'dllexport/dllimport', 'Additional Include Deirectories' and 'Additional Dependencies'. But I got LNK2028 unresolved token and LNK2019 unresolved external symbol, the reason is I forgot using the extern "C" to include all dllexport functions.
10/23/2007
Reversing string in C
There is a example for reversing string in the Section 3.5 of K&R's 'The C Programming Language' . The example code look like this:
void reverse(char s[]) {
int i, j;
for (i = 0, j = strlen(s) - 1; i < j; ++i, --j) {
But the above code can be improved. There is 'Pointer Version':
void reverse(char *s) {
char c;
while (*s++)
while (l < s) {
*l++ = *s;
*s-- = c;
The *strrev* in C standard library implements the same functionality, but generally implements in assembly code.
10/20/2007
Item not found: Could not find this item! on Vista
When u try to remove a directory under the Vista GUI, u'll get 'Item not found: Could not find this item'. Or, u'll get 'The system cannot find the file specified' under the Vista command prompt.
Try the following:
1. Open the command prompt.
2. Execute *dir /x* to display 8.3 file name
3. Execute *rd filename* the filename 8.3 format that u got it in step 2.
10/18/2007
The #end joke
I found a joke when I publish my blog through the gmail. Wrote a blog which includes a piece of C/C++ code. Within that, the *# e n d i f* C/C++ directive had been used. So after send my blog, I got truncated blog content, Ha.
Because, u can use the *# e n d* flag in ur gmail in order to indicate blogger to truncate the content after *# e n d* flag. It's a joke.
Organize IA-32 machine code in C++ class
#include <iostream>
#pragma pack(push, 1)
class MachineCode {
public:
#pragma pack(pop, 1)
typedef void (__stdcall *ProcCall)(void);
class Adapter {
public:
thunk_.proc_ = (unsigned long)proc - ((unsigned long)pthis + sizeof(thunk_));
::FlushInstructionCache(::GetCurrentProcess(), pthis, sizeof(thunk_));
return (true);
ProcCall GetProcCaller(void) {
static void DefProcCall(void) {
Then, I use the following code to call X::DefProcCall function:
Adapter x;
x.Init (&Adapter::DefProcCall, &x);
ProcCall call = x.GetProcCaller();
call();
The all magic is at 'reinterpret_cast<ProcCall>(
The jmp_ data member of MachineCode class stores 0xE9 that is 'jmp' instruction in IA-32. And the proc_ data member stores relative address since the ending address of the thunk_ which in Adapter class. So whole MachineCode class generate such IA-32 code 'jmp address'.
10/16/2007
[] Operator in IA-32 assembly code
[] bracket operator means get the content of the memory location, u can treat [location] as addressing expression.
The following C code:
int i;
i = 0x1234;
can be translate to assembly code which looks like this:
mov dword ptr [i], 1234h
the dword ptr means the content of variable i occupied 4 bytes. It is required because of IA-32 is byte addressable. And above mov instruction does not know how much storage requires for storing immediate number 1234h.
10/15/2007
Cannot install Microsoft Server 2003 SP2!
*update.inf*
1. net stop cryptsvc
2. ren %systemroot%\system32\catroot2 old-catroot2
3. net start cryptsvc
10/14/2007
Manipulate bits in C
1. Definition:
const int FIRST = 1 << 0;
const int SECOND = 1 << 1;
const int THIRD = 1 << 2;
Why defines the bit flag like this? Oh, just for clarity.
2. Setting bit flag:
int flags = 0;
flags |= FIRST;
flags |= SECOND;
flags |= THIRD;
if (flags & FIRST) {
printf("FIRST bit has been set.\n");
} else if (flags & SECOND) {
printf("SECOND bit has been set.\n");
}
...
3. Clearing bit flag:
flags &= ~FIRST;
flags &= ~SECOND;
...