Sunday, May 17, 2009

Converting CString to double in MFC

You can use the following snippet to convert CString to double in MFC:

#include "stdlib.h"

double func(CString pValue)
{
wchar_t* stopString;
double num = wcstod(pValue, &stopString);
return num;
}

Tuesday, April 07, 2009

View Native DLL Dependencies

If you develop a native DLL using Visual Studio 2005 SP1, you may need to know the dependencies of this DLL in order to ship it with your application, you can use the Visual Studio utility: depends.exe

image 

  1. Run Visual Studio Command Prompt
  2. type depends.exe and press enter.
  3. Click file->open to choose your DLL.
  4. View the dependencies in the left side tree view.

Sunday, October 07, 2007

Office SharePoint Server Development - What's Needed?

To begin playing with SharePoint Development you will need:

- Windows Server 2003.
- Install Windows SharePoint Services 3.0 (WSS) or Microsoft Office SharePoint Server (MOSS)
- Visual Studio 2005
- .NET Framework 3.0
- Microsoft® Visual Studio® 2005 Extensions for Windows Workflow Foundation
- Windows SharePoint Services 3.0 Tools: Visual Studio 2005 Extensions
- SharePoint Server 2007 SDK: Software Development Kit

Wednesday, February 15, 2006

C# Invalid Cross Thread Operation

In .NET Framework 2.0 with default settings you can not change a Windows Control Property from an external thread, and if you try to do that you will get the following Exception
"Invalid Cross-Thread Operation"

to avoid this exception you can disable the checking for invalid Cross-Thread Operation by setting this static Property to false:
Control.CheckForIllegalCrossThreadCalls = false;

This settings is not recommended it is done only to avoid the exception appearing while debugging, it may cause serious problems if you disabled it (its done mainly to warn you while you debug your application).

To See other techniques to avoid this problem, see:
http://weblogs.asp.net/justin_rogers/archive/2004/10/08/240077.aspx
http://blogs.wwwcoder.com/amachin/archive/2004/12/15/1146.aspx

Tuesday, February 07, 2006

Invalid character value for cast specification

If you catch this error and you are trying to use a DateTime Value with SQL Server then check that your date in this range:

1/1/1753 to 31/12/9999

it will probably fix the problem

Friday, October 21, 2005

PDF Files

I found a fantastic class library project to edit and create PDF files its name is "IText_Sharp" which is an import for the original project "IText" from Java to C#, Check it out if you need to edit or create PDF files.
www.sourceforge.net/projects/itextsharp/

Sunday, October 09, 2005

Coding Style

coding style is an important factor in producing an efficient code that can be reused or modified eaisly.

I will review here basic hints in coding styles:
  1. naming variables: best way to name a variable is to choose first an abreviation for it based on its type like "str" for "String" and "num" for "Numebers", then add a descriptive name for the variable ex: if you are declaring a variable for the Monthly Income its name may be like "numMonthlyIncome", take care that to make the variable readable Start every descriptve word in it with a capital letter and the varaiable abbreviation must be in small letters.

  2. naming Functions: try to name Functions so that describe their operation and target and avoid ambigous names, and concentrate on choosing a name that describes the output not the input since the input will be described in the parameteres declaration in the function ex: int GetAverageIncome(string strEmployeeName).

  3. Return Codes: it is a coding style where all the functions in the code always returns an integer value describing the status of the result or any other related message like errors that may occure or confirmation messages or you can combine between the return value of a function and its return codes like in the example of the previous function declaration, we know that an average value of an income must be always a postive value so we can return negative values describing error messages like -1 for "That employee does not exist in the database" and so on.