January 13, 2009

Changing version of .net framework dependency for setup and deployment project in visual studio 2008

Filed under: .net,vs.net Himanshu @ 3:50 pm

Its easy to do, but not obvious to locate, at least to me. It took a while for me to find, so I thought let’s log it, in case if I need it in future, or someone else might need it. I need to create setup that depends on .NET framework 2.0. instead of 3.5 which is default in VS.NET 2008.

After creating setup and deployment project, double click on dependency of .net framework in solution explorer:


Now, you should be able to see launch condition for .net framework in “Launch Conditions” tab. Until you double click for the first time, node do not appear in launch conditions. And that’s where I wasted some hours:

lauch condition

Select the node and see the property window, where you will find the answer of the question:


January 10, 2009

Knowing memory usage from Compact Framework application

For any handheld device application, memory usage is an important element to observer. .NET Compact framework have very less code that gives information about physical or virtual memory. But using native libraries – by doing pInvoke, one can retrieve memory usage statistics.

There can be more than one level of report that can be captured. Today, lets start with summary. GlobalMemoryStatus function in coredll can help identifying how much total physical memory available in the device and how much of it is free. Same way, how much of virtual memory available to process and how much of it is free.

Lets see how can we use GlobalMemoryStatus. We will have to define a class which will be passed to function and will be filled by GlobalMemoryStatus function. Layout of it is defined as structure by MS team, but its alright to use class here. By having it as class, we will be able to write default constructor unlike structure in C#.

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
    internal class MemoryStatus
        public uint dwLength;
        public uint dwMemoryLoad;
        public uint ullTotalPhys;
        public uint ullAvailPhys;
        public uint ullTotalPageFile;
        public uint ullAvailPageFile;
        public uint ullTotalVirtual;
        public uint ullAvailVirtual;
        public uint ullAvailExtendedVirtual;
        public MemoryStatus()
            this.dwLength = (uint)Marshal.SizeOf(typeof(MemoryStatus));

Now, lets define extern method for GlobalMemoryStatus

        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("coredll.dll", CharSet = CharSet.Auto, SetLastError = true, EntryPoint = "GlobalMemoryStatus")]
        static extern bool GlobalMemoryStatusWinCE([In, Out] MemoryStatus lpBuffer);

And here is how we can call the method

    MemoryStatus internalReport = new MemoryStatus();
    if (GlobalMemoryStatusWinCE(internalReport))

Powered by WordPress