Monday, February 13, 2012

Reminder about your invitation from Heidi (Zhaoling) Y.

 
 
 
LinkedIn
 
This is a reminder that on February 1, Heidi (Zhaoling) Y. sent you an invitation to become part of their professional network at LinkedIn.
 
 
 
 
On February 1, Heidi (Zhaoling) Y. wrote:

> To: [houzhip.csdev@blogger.com]
> From: Heidi (Zhaoling) Y. [yaoz2004@gmail.com]
> Subject: Invitation to connect on LinkedIn

> I'd like to add you to my professional network on LinkedIn.
>
> - Heidi (Zhaoling)
 
 
 
 
 
You are receiving Reminder emails for pending invitations. Unsubscribe.
© 2012 LinkedIn Corporation. 2029 Stierlin Ct, Mountain View, CA 94043, USA.
 

Monday, February 6, 2012

Reminder about your invitation from Heidi (Zhaoling) Y.

 
 
 
LinkedIn
 
This is a reminder that on February 1, Heidi (Zhaoling) Y. sent you an invitation to become part of their professional network at LinkedIn.
 
 
 
 
On February 1, Heidi (Zhaoling) Y. wrote:

> To: [houzhip.csdev@blogger.com]
> From: Heidi (Zhaoling) Y. [yaoz2004@gmail.com]
> Subject: Invitation to connect on LinkedIn

> I'd like to add you to my professional network on LinkedIn.
>
> - Heidi (Zhaoling)
 
 
 
 
 
You are receiving Reminder emails for pending invitations. Unsubscribe.
© 2012 LinkedIn Corporation. 2029 Stierlin Ct, Mountain View, CA 94043, USA.
 

Wednesday, February 1, 2012

Invitation to connect on LinkedIn

 
LinkedIn
 
 
 
From Heidi (Zhaoling) Y.
 
Research Associate at University of Waterloo
Kitchener, Canada Area
 
 
 

I'd like to add you to my professional network on LinkedIn.

- Heidi (Zhaoling)

 
 
 
 
 
 
You are receiving Invitation to Connect emails. Unsubscribe
© 2012, LinkedIn Corporation. 2029 Stierlin Ct. Mountain View, CA 94043, USA
 

Wednesday, April 6, 2011

Different behavior of function atol in VC6, Visual Studio 2005 and Visual Studio 2010

Recently we have to upgrade a MFC project that can only compiled in VC6 to Visual Studio 2010. The project is pretty complex with 5 static library and dozens of dynamic linking libraries. After removing all the compiling errors caused by c++ language specification changes such as default function parameter is no long supported in function pointer ans so on, the program seems work now.

However, one test case always fails and we do not know why. It seems that it fails only at certain cases. After spending long time to investigate this crash (a memory crash is finally reported) we found out the reason.

In the code we have a function that needs to convert a string to DWORD, which is an unsigned long. The range of DWORD is  0 through 4294967295 Most times the conversion works fine as long as it is smaller than 2,147,483,647. The function we used to perform the conversion is atoi(), which converts a string to a signed integer. However, in VC6 the funciton returns a correct value  even if the string contains a integer that is bigger than the maximum signed integer. In Visual Studio 2005, the atoi function returns the maximum value of signed integer, which is 2,147,483,647, if the string contains a bigger value. In Visual Studio 2010 it returns an strange value. Therefore, our code will only work fine in VC6. As soon as it is updated to Visual Studio 2010, a dangerous bug will be introduced.

The solution of this bug is by replacing the atoi() function with _atoi64(), which will work in all of  the above situations. 

The project file ‘ ‘ has been renamed or is no longer in the VS 2010 solution file

I had a solution file with about 10 projects (some are libraries, some are dlls) that works very well. However, as soon as I change the name of the folder that contains the solution (including all projects) or move the whole solution from C: to D: drive, I will not be able to compile the solution. Instead, I will receive such an error: The project file ' ' has been renamed or is no longer in the solution.

After checking this problem carefully, I found that the main project (a MFC windows application) that references to other projects are using fixed project path. I think in other project types like C# windows form application all projects are using relative paths.

After removing all the project references, the solution compiles properly without any error message.

Thursday, December 23, 2010

Error on Entity Framework: Unable to update the EntitySet ... because it has a DefiningQuery and no element exists in the


I have this error with following simple code

 ObjectKeyakey = new ObjectKey();

        var aw = new entities2();

        ObjectQuery<ObjectKey> query2 =
            aw.LicenseKeys.Where("it.ActivationKey = @ln", new ObjectParameter("ln", strUserActivationKey));
        List<LicenseKey> keyList = new List<LicenseKey>();
        keyList = query2.ToList();

        ObjectKey selectedKey = keyList[0];
        selectedKey.ComputerName = "Test Change";
        int rowsAffected = aw.SaveChanges(true);


The saveChanges function fails with the error say that I have a DefiningQuery and UpdateFunction mapped.

Following post provides a solution to it

  1. Right click on the edmx file, select Open with, XML editor
  2. Locate the entity in the edmx:StorageModels element
  3. Remove the DefiningQuery entirely
  4. Rename the store:Schema="dbo" to Schema="dbo" (otherwise, the code will generate an error saying the name is invalid)

The strange part is that in this database model I actually removed all views, and have confirmed that all table have primary keys set properly. Not sure why the DefiningQuery is still generated. 

Anyway, the problem has been solved by following the above 4 steps.

Wednesday, December 8, 2010

BinaryFormatter deserialization exception



The BinaryFormatter always includes version information in the serialized stream even if you set FormatterAssemblyStyle.Simple during serialization. If you try to deserialize the stream after rebuilding the assembly, this will fail, even if you set FormatterAssemblyStyle.Simple during deserialization (fails to load the old assembly version used when creating the serialized stream).

This is the post that talks about how to make different version of binding compatible when binary formatter is used by applying the concept of SerializationBinder


Monday, September 20, 2010

How to create an application without any dialog

Sometimes we want a simple application to detect the .Net framework installed on a computer before an application installation can continue. A simple console application can do the job. However, we do not want the black console window to be displayed during the installation.

The following solution may solve the problem

1. Create a simple Win32 project.
2. In the function
     _int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
...
}

The default value of nCmdShow is 1. Change it to 0. Application will not display any dialog. 

Comment out following line of code:



//// Main message loop:
//while (GetMessage(&msg, NULL, 0, 0))
//{
// if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
// {
// TranslateMessage(&msg);
// DispatchMessage(&msg);
// }
//}

//return (int) msg.wParam;

return 0;


After finish the code. Application will exit.

This article shows how to detect .Net framework installed on a computer with the source code.


The code can be downloaded from 


It works great.





Sunday, September 19, 2010

Decompress large gzip file

.Net GZipStream has a limitation of 4GB. It can not be used to compress/decompress files which are greater than 4gb. The following code overcomes the limitation.using dotnetzip library downloaded from http://dotnetzip.codeplex.com/ 

This code can unzip a Zip format file if the passed in file is right format. 

public static string Decompress( string strPath, string dstFile, bool bIsZipFile)
{

if ( bIsZipFile == true)
{
if ( File.Exists( dstFile ) )
{
File.Delete( dstFile );
}
if ( File.Exists( strPath ) == false )
{
return strPath;
}


string strFolder = Path.GetDirectoryName( strPath );
Ionic.Zip.ZipFile zipFile = new Ionic.Zip.ZipFile( strPath );
zipFile.ExtractAll( strFolder );
zipFile.Dispose();
return dstFile;
}


FileStream fsIn = null;
FileStream fsOut = null;
//GZipStream gzip = null;

        Ionic.Zlib.GZipStream gzip = null;

const int bufferSize = 4096;
byte[] buffer = new byte[ bufferSize ];
int count = 0;

        List<string> lstExtraFilesToBeMerged = new List<string>();

try
{
if ( File.Exists( strPath ) == false )
{
return strPath;
}

if ( File.Exists( dstFile ) )
{
File.Delete(dstFile);
}

fsIn = new FileStream( strPath, FileMode.Open, FileAccess.Read, FileShare.Read );
fsOut = new FileStream( dstFile, FileMode.Create, FileAccess.Write, FileShare.None );
if ( bIsGZip == true )
{
                //gzip = new Ionic.Zlib.GZipStream(fsIn, CompressionMode.Decompress, true);
                gzip = new Ionic.Zlib.GZipStream(fsIn, Ionic.Zlib.CompressionMode.Decompress, true);
                while (true)
{
                    //if (fsOut.Length > 100000)
                    //{
                    //    gzip.Close();
                    //    gzip = new GZipStream(fsIn, CompressionMode.Decompress, true);
                    //}
count = gzip.Read( buffer, 0, bufferSize );
if ( count != 0 )
{
fsOut.Write( buffer, 0, count );
}
if ( count != bufferSize )
{
// have reached the end
break;
}
}
}

}
catch ( Exception ex )
{
// handle or display the error
throw ( new Exception( "Decompress failed.", ex ) );
}
finally
{
if ( gzip != null )
{
gzip.Close();
gzip = null;
}
if ( fsOut != null )
{
fsOut.Close();
fsOut = null;

                if (lstExtraFilesToBeMerged.Count > 0)
                {
                    MergeFile(dstFile, lstExtraFilesToBeMerged);
                }
}
if ( fsIn != null )
{
fsIn.Close();
fsIn = null;
}
}

return dstFile;