Saturday, December 29, 2007

ref vs out parameter

ref
Before passing ref parameter the sender class must instantiate the ref argument, so ref requires additional bandwidth to send the object both ways.
ref allows the called methods to modify the object to which the reference refers because the reference itself is being passed by reference.
out
An out argument is created by the called method and it is returned to the caller.

Power toy for .NETCF 3.5

Microsoft has released the Power Toy for .NETCF 3.5, it includes few important features that were available with .NET but missing from .NETCF like

· Remote Performance Monitor and GC Heap Viewer

· NETCF CLR Profiler

· App Configuration Tool (NetCFcfg.exe)

For additional details please refer http://blogs.msdn.com/netcfteam/archive/2007/09/12/power-toys-for-net-compact-framework-3-5-ctp-released.aspx

Monday, July 9, 2007

How to run an "exe" from a running program

To run/invoke an exe from the running program use
System.Diagnostics.Process.Start method with input parameter as exe name with full path and any input parameter to the exe if applicatble or just "".

e.g. System.Diagnostics.Process.Start("\test.exe","")

Monday, June 18, 2007

What’s new for .NETCF developers in Orcas ...

Orcas coming with the following new features for the Mobile developers
  • Unit testing for devices like VSTS have for Desktop and Web applications
  • Device Security Manager : to make sure that application will run on the devices with different level of security
  • Device Emulator 2.0: It is 40% faster than older one, it have battery simulation to simulate the different battery levels.
  • Device Emulator 3.0: Comes with XML config file and support for scripting e.g. VB Script helps in better testing using test scripts
  • .NETCF 3.5

Friday, June 15, 2007

What’s New for developers in Windows Mobile 6

The features provided by WM6

  • WM6 devices will have .NETCF 2.0 with SP 2 and SQL Server Compact Edition 2005 preinstalled in ROM
  • Compatible with WM5 applications
  • Support for AJAX
  • 2 New native API’s
    • Sound API : Can Play MID,WMA,WAV and MP3 file formats
    • WISP (Windows Ink Service Platform) Lite: for ink reorganization, it will help to develop character reorganization type applications.
  • New WM 6.0 SDK
  • Security Tools: These tools will help to sign the application and make the applications to run on Smart Phones and PPC. These 2 devices have different level of security settings so the application that can run on PPC (which have 1 tier security) not necessarily can run on Smartphone (which have 2 tier Security). It provides 2 tools
    • Security Configuration Manager
    • CabSign Tool

Apart from this the SDK tools available with WM6

  • Fake GPS: This will allow you to send the Fake GPS values to your device so that it would be easy to implement and test the GPS functionality in the application even if the device don’t have GPS feature.
  • Fake Server: This tool will simulate the Web services so that the application can work in disconnected mode and still can access the features of the web service
  • Cellular Emulator: Using this user can send and receive SMS/ voice calls from the emulator.
  • Hopper: This is tool that will test mobile application against random key inputs, it actually simulate multiple keystrokes and clicks on the screen to test the applications vulnerability against such inputs.
  • WM test framework: similar to test suit of the VSTS, new WM6 contains the test suit for the .NETCF developers.


Thursday, May 31, 2007

My Solution : Failure to connect to SQL Server with provided connection information. SQL Server4 does not exist, ...

Error: Failure to connect to SQL Server with provided connection information. SQL Server4 does not exist, access is denied because the IIS user is not a valid user on the SQL server, or the password is incorrect

Solution:
1. After creating your publication on the management studio, add the user IUSR_ in the security->login folder
Important: you don't have to create that user, this user already exist, so look it up under advanced search!!
2. Rightclick on that user and choose properties.
3. Under usermappings check the box of the database you would like to access, then click ok.
4. Rightclick on your publication and choose properties.
5. Select publication access list an add the
IUSR_ user and click ok.
6. Rightclick on your publication, select view snapshot status and generate the snapshot.
7. Execute the web synchronisation wizard the subscription wizard.
this wizard creates the virtual directory for the webaccess, choose annonymous access.
8. Execute the subscription wizard and use windowsauthentication.

Reference:

Monday, May 28, 2007

.NET Compact Framework 3.5 is coming

.NET Compact Framework 3.5 is coming with next version of Visual Studio code named "Orcas".
Details can be found at http://blogs.msdn.com/netcfteam/archive/2007/01/28/net-compact-framework-3-5-included-in-orcas-january-ctp.aspx

Download the beta version from here

Sunday, May 27, 2007

Bluetooth Settings for PocketPC Devices


For Widcomm bluetooth stack based devices settings are

For BT InboundPort : [HKEY_LOCAL_MACHINE\SOFTWARE\Widcomm\BtConfig\Services\0001]
For BT OutboundPort : [HKEY_LOCAL_MACHINE\SOFTWARE\Widcomm\BtConfig\Applications\0001]
For Bluetooth Mode Status : [HKEY_LOCAL_MACHINE\SOFTWARE\Widcomm\BtConfig\General\StackMode]



For Microsoft bluetooth stack based devices settings are

For BT InboundPort : [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Bluetooth\Services\0001]
For BT OutboundPort :
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Bluetooth\Applications\0001]
For Bluetooth Mode Status :
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Bluetooth\General\StackMode]

Friday, May 18, 2007

My Solution for "An error has occurred on the computer running IIS. Try restarting the IIS server" Error

I got this error while I was working on SQL Server mobile and Merge Replication. The solution was working fine initially but later on I switched my emulator from WM 5 to WM 6 & I got this error. I tried the same solution back on WM 5 , but it gave me same error, I tried to solved it by providing network credentials but it didn't solved my problem. So used my (or I'll say everyone's ) most effective weapon to solve ambiguous errors i.e. System reset :). I restart my machine & the solution start working fine. Magic!!!
I donno reason behind this, but it served my purpose.

Monday, May 14, 2007

Determine if a table exist in SQL Mobile database.

If you wants to find out that whether a particular table exist in a SQL Mobile database, here is a simple solution.
Fire the following query from COmmand.ExecuteScalar.
SELECT count(*) FROM INFORMATION_SCHEMA.TABLES where TABLE_NAME = @TableName

If it returns 1; it means the table exists in the database & if it returns 0 then it means the table doesn't exists.

Wednesday, May 2, 2007

The Easiest and quickest way to create a ConnectionString

Creating a connection string is always a complicated task - providing credentials, rights & all. But few years ago one of my colleagues told me a quick way to create a connection string & I guess it is the easiest way.
The steps are
1. Create a new file by right clicking on desktop; from context menu select New then select Text File (you can select any file).
2. Rename the extension of this file to "UDL"; in this case it would be from "txt" to "udl".
3. Neglect the rename message and save the file. You can see a new icon.
4. Open this file by double clicking on the icon; you can see the Providers, connection tab. So specify your server, Provider and database name and click "Ok".
5. Now Open this file in text box and you can see the connection string for the database you have selected.

Tuesday, April 3, 2007

Mobile Client Software Factory

From last few weeks I was in search of a module for .NETCF that can work with Web services in connected and disconnected mode, first I came across OpenNETCF application block, but as I mentioned in my previous blog Smart Client offline application block (SCOAB) I faced a lot of problems just to compile that and same problem continued while creating a POC using SCOAB, Later I found out Mobile client software factory a project from the Microsoft patterns & practices team @ Codeplex. I found that this Software factory provides various features for applications based on .NETCF 2.0. It includes
  • The Mobile Composite UI Application Block and ObjectBuilder
  • The Configuration Application Block
  • The Connection Monitor Application Block
  • The Data Access Application Block
  • The Data Subscription Application Block
  • The Disconnected Service Agent Application Block
  • The Endpoint Catalog Application Block
  • The Orientation Aware Control Application Block
  • The Password Authentication Application Block
Disconnected Service Agent Application Block is serving the feature that I was searching from last few weeks. It works with Configuration Application Block, Connection Monitor Application Block,Data Access Application Block, Data Subscription Application Block and Endpoint Catalog Application Block to work in connected and disconnected mode.
So overall logic behind is that when the connection is available the requests are send th Web service & when it is not available i.e. in disconnected mode the requests are stored in SQLCE database on the device & when the connection is available the requests dispatched to Web service. The overall architecture and design of these application blocks is awesome. User can easily create any mobile application using theses AB's. The most important feature I would like to mention here is the documentation provided with this Software Factory is complete & explains the technical details and Howto's in best possible way.

Looking forward to use the rest of the application blocks from Mobile Client Software Factory

Tuesday, March 27, 2007

Pocket PC services: Creation, deployment and debugging

Often Pocket PC programs need a background process and most of existing Pocket PC programs implement it by creating an executable file which is started during system start-up. But Pocket PC has 32 processes limit and having many different programs running in background can be a serious problem. Pocket PC 2003 provides special mechanism implemented in Services.exe that allows Pocket PC developers to shape their background applications into services that run in one process as different threads.

Many Pocket PC applications need a background process. For example:

  • A program that shows a window when SD card is inserted

  • A permanent backup program

  • A program that control GPRS traffic

  • A Web server

  • A program that adds a special icons to the taskbar

Now almost all Pocket PC developers create an executable file and put shortcut to this file to \Windows\StartUp so this program is started just after reset and runs in background. This approach has a serious problem because number of processes in Windows CE is limited by 32. For example in XDA II Pocket PC devices there are 28 processes running just after soft-reset. If you install 2-3 third-party programs that need background process you will have only 1-2 processes for running programs!
Microsoft has introduced a solution for this problem in Windows Mobile 2003. Windows Mobile 2003 supports services which are DLLs run in one process (services.exe) as different threads. It solves the problem but:
1. Most Pocket PC developers do not know about this technology.
2. Services are not properly documented. For example you will not find necessary headers in Pocket PC 2003 SDK.
3. This technology is not supported on Pocket PC 2000 and Pocket PC 2002. So you cannot use services if you want to create programs that will work on both Pocket PC 2002 and Windows Mobile 2003 for Pocket PC.
This article describes how to solve these problems and how to create and distribute services for Pocket PC that will work on all Pocket PC versions.
Pocket PC service interface is similar to Pocket PC driver interface. Pocket PC service is a DLL that should export a set of functions and services.exe process loads these DLLs and initializes them by calling one of the functions.


Creating Service DLL

  1. In Microsoft eMbedded Visual C++ create new WCE Dynamic-Link Library project
  2. Add exported functions definitions (you should use your own prefix instead of MYS)
DWORD MYS_Close(DWORD dwData)
{
return 0;
}
DWORD MYS_Deinit(DWORD dwData)
{
return 0;
}
DWORD MYS_Init(DWORD dwData)
{
return 1;
}
DWORD MYS_IOControl(
DWORD dwData,
DWORD dwCode,
PBYTE pBufIn,
DWORD dwLenIn,
PBYTE pBufOut,
DWORD dwLenOut,
PDWORD pdwActualOut)
{
return 1;
}
DWORD MYS_Open(
DWORD dwData,
DWORD dwAccess,
DWORD dwShareMode)
{
return 0;
}
DWORD MYS_Read(
DWORD dwData,
LPVOID pBuf,
DWORD dwLen)
{
return 0;
}
DWORD MYS_Seek(
DWORD dwData,
long pos,
DWORD type)
{
return 0;
}
DWORD MYS_Write(
DWORD dwData,
LPCVOID pInBuf,
DWORD dwInLen)
{
return 0;
}
MYS here is a prefix that is to be specified further by application calls to Services.exe (here MYS stands for MY Service).
  1. Add these functions names to your project .def file export table (you should use your own prefix instead of MYS):
Exports;
Explicit exports can go here
MYS_Close
MYS_Deinit
MYS_Init
MYS_IOControl
MYS_Open
MYS_Read
MYS_Seek
MYS_Writeb
  1. This is now time to add some specific initialization code to MYS_Init function.
Most likely you need to create a new thread here that will encapsulate all service logic. To do this defines thread controlling function. That function is the right place to create additional windows, timers or any other application-specific needs. In the sample given we create a timer and run thread message loop.
unsigned long __cdecl MyControllingFunction( LPVOID pParam )
{
g_nTimer = SetTimer(0, 0, 10 * 1000, MyTimerProc);
MSG msg;
while (GetMessage(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
DWORD MYS_Init(DWORD dwData)
{
HANDLE hThread = CreateThread( 0, 0, MyControllingFunction, 0, 0, 0);
return 1;
}
Be sure to return non-zero value from MYS_Init function as zero return value indicates service initialization failure and causes service DLL to be unloaded imediately.
Depending on application needs user can put some logic to the other MYS_... methods in the same manner.


Service Registration in Registry

In order to have service automatically started at system startup you should add an arbitrary named subkey to the registry HKEY_LOCAL_MACHINE\Services\MyService key (Service key is the name of the service, user can use there other names also) and specify the following values:
Order: REG_DWORD
Order in which Services.exe will load each service. The service with the lowest order is loaded first.
Dll : REG_SZ
Dynamic-link library (DLL) files to be loaded. Only file name without path. This DLL should be located in \Windows folder.
Keep : REG_DWORD
Must be 1 for services that should run in background, if Keep = 0, the DLL will be unloaded immediately after initialization.
Prefix : REG_SZ
Prefix of your functions exported from the service DLL (instead of xxx in xxx_Init, etc). Must be 3 symbols.
Index : REG_SZ
Service index (set to 0).
DisplayName : REG_SZ
Display service name.
Description : REG_SZ
Description of display service.
Context : REG_DWORD
Initial value passed into the initialization routine (must by 0).
For example, for the Sample MFC-based service to start as a service at boot time, the following registry key should be used.
 
[HKEY_LOCAL_MACHINE\Services\MyService]
"Dll"="MYS.dll"
"Order"=dword:8
"Keep"=dword:1
"Prefix"="MYS"
"Index"=dword:0
"Context"=dword:0
"DisplayName"="Sample Service"
"Description"="Sample Service"
User can create a C # application to register the service DLL.


Installing Pocket PC Service

To install a service you should copy your service DLL into the \Windows folder. From eVC IDE select the Pocket PC 2003 device as target platform and build the project, it will deploy the DLL into \Windows folder. For some devices while deploying the IDE may show “CE Platform PocketPC 2003 does not match remote OS version 421. Continue?” error message, neglect the warning and press “Yes”.


Start Service

Once the service is installed and registered, the PDA need to be restarted to start the service DLL.


C# code to start and stop the service DLL

Sometimes user may need to start or stop the service from code, such as backup service where before creating the backup or restoring it, we may pause the service.
[DllImport("coredll")]
private extern static int ActivateService(string lpszDevKey, int dwClientInfo);
[DllImport("coredll")]
private extern static int GetServiceHandle(string szPrefix, string szDllName, int pdwDllBuf);
[DllImport("coredll")]
private extern static bool DeregisterService(int hDevice);
Above are the declarations for the API functions that would require activating and deactivating the service.
If you want to deploy modified version of already deployed and running DLL, before deploying the new DLL, services.exe should be terminated because it won’t allow replacing existing DLL in running mode. To kill services.exe the steps are.
  1. From eVC Tools menu select Remote Process Viewer.
  2. Select your device from Select the Device popup.
  3. Select the Services.exe from Services section.
  4. Click Kill Process (X) button on the toolbar.

Activate the Service

int handle = ActivateService(“MyService”, 0);
The above code starts the service DLL.
First parameter is registry entry of the service; here it is “MyService”.
Second parameter is reserved and it should be Zero.

Stop the Service

int handle = GetServiceHandle ("MYS" + "0:", null, 0);
DeregisterService (handle);
GetServiceHandle function returns the handle of the service DLL.
The first parameter is the prefix of the service with index number; here prefix is “MYS” and index number is “0”
Second parameter is optional that contains the name of the service DLL.
Third parameter is also optional specifies the number of bytes written or the number of bytes required if the buffer is not large enough.
DeregisterService stops the instance of the service provided as handle.

Debugging Pocket PC Service

To debug your service you can attach to the services.exe process. You have to use the eVC++ 4 debugger for that because the eVC++ 3 debugger does not support attaching to remote processes. To attach the debugger to the services.exe process you need a local copy of the services.exe file. The user can copy the services.exe from the /Windows folder of PDA.
You can attach to the services.exe process using the following step-by-step instructions:
  1. Open your service project in Microsoft eMbedded C++ 4.0.
  2. Add Debugbreak() calls in proper place of your code. (Setting breakpoints in your code will not help.)
  3. Build debug configuration and upload your DLL to the device.
  4. Add registry values desired as described above.
  5. Start your service on the device (e.g. soft-reset).
  6. Attach to the services process (Build / Start Debug / Attach to WCE process...).
  7. Connect to your device.
  8. Select "services.exe" as the process to debug. Browse for your local copy of services.exe binary image.
  9. As soon as your service stops at the breakpoint debugger loop for each service DLL in services.exe as soon as it ask for local copy of your DLL, provide the local copy of DLL.
  10. It will take some time (can be from few seconds to few minutes) to reach the code still breakpoint in the service DLL.
  11. Start debugging.

Monday, March 26, 2007

Memory Profiler: Generate stat file for .NETCF 1.0 application

Remote performance monitor is available with .NETCF 2.0 to monitor the performance of application developed on the .NETCF 2.0, we can also monitor the performance of application developed on .NETCF 1.0, but it won't be real time, here a stat file will be generated for the application.

Steps to generate stat file

  • Download attached zip file.
  • Open the PMonTest solution in .Net 2005
  • Run the project, Select Pocket PC 2003 Second Edition Emulator to deploy the PMon Test application.
  • Next task is to edit the Registry. To generate the .stat file for the applications,
  • Key named as PerfMonitor need to add under
  • HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\.NETCompactFramework\\
  • Under this key one sub key named as Counters need to be added & set its value = 1
  • Set Registry button will do the step no 3 & 4.
  • First task is to read the above subkey, to do so press Read Registry button.If the subkey is missing it will show “NullReferenceException” otherwise it will show “Performance Counter On/Off” as per the value of the Counters subkey.
  • If Counters subkey is missing or its value is “0”, Press Set Regstry button , it will set the Counters value equal to “1”.
  • Press Exit Button to close the application.* don’t press the x button of the form; it will not close the application. To generate the .stat file application needs to be closed.
  • Now open any application for which you want to generate the stat file or you can open the same PMonTest application. Its path is \PMonTest .Open the PMonTest.exe. & press either Read Registry or Show Date button.
  • Close the application by pressing the Exit Button
  • Now go to root of your device, it will have stat file for your application, so if your application name is TestApp, the stat files name would be TestApp.stat.
  • Import the stat file on your computer using .Windows CE Remote file viewer.
  • Open this file in NetCFRPM.exe, the file is located in “C:\Program Files\Microsoft.NET\SDK\CompactFramework\v2.0\bin” folder.

Friday, March 16, 2007

OpenNETCF's Smart Client Offline application block

Now I am back from Virtual earth to mobile application development & task was to design a component to handle connection and data upload and download, it should able to work in online and offline modes.

While goggling for the possible solutions I came across application blocks by OpenNETCF, OpenNETCF is not new to me , I have already tried the Exception management application block provided by them & I found that they have also provides the application block for Offline, actually all these application blocks are inspired by application blocks provided by Microsoft but OpenNETCF provides these for .NET compact framework. I must say a great work by OpenNETCF poeples but felt that it lacks a small thing & i.e. how to use these complex & enormous application blocks.

After try & error methods I able to compile the error free version of the application block ( warnings were neglected ;) as usual)

I tried to use it on sample application & it stared screwing me up. Hell the call goes from one assembly to another & functions receives interfaces as input parameter (I was really horrified by this ), the designed might have included all these complexities to server the actual need of components but my god its really not mentioned any where that how to use it AS IT IS or from where you can start. Apart from these difficulties I got error in configuration section (God knows why these peoples needs config file for an pocket pc application).



so Still searching for a good alternative.

How to get source image from site created using mapcruncher?

Last week I were told by one of my colleagues to include the image of London 2012 in our POC project for Virtual Earth API's. The site was showing the Olympic stadiums to be build in London.

So first task was for me to extract the source image from that site, first feeling said it is not possible but the xml structure that microsoft research provides for map cruncher projects shows me the path to do so!

  • First of all consider that the site name is www.xyzCrunch.com where the crunched map is hosted.
  • Next step is to get the MapLayers.Crunched xml from this site, so it would be www.xyzCrunch.com/MapLayers.crunched.xml This file contains the name of crunch project in its header against attribute "SourceMashupFilename"; assume it is SourceData/xyzCruch.yum.xml.
  • Now we got the project file name, so open the project xml file , it would be www.xyzCrunch.com/SourceData/xyzCruch.yum.xml.
  • The name of the image file gets stored with each layer and the name of the image file is stored as value for SourceMapFilename attribute under SourceMap element node.The name of the file is xyz.png.
  • Now last step, we have file name & we will get that file from www.xyzCrunch.com/SourceData/xyz.png.
Remember that the Sourcedata folder contains the Map Cruncher project(.YUM) in the xml format & it also contains the source images for each layer.

So, Enjoy Crunching!

Friday, March 2, 2007

"'VEMap' is undefined "error

Today morning I faced a strange problem in my Crunched VE application, it was working fine till yesterday, but today when I tried to load it, it shown a html error 'VEMap' is undefined .
Quite strange that the other VE application that uses js from virtual earth site was working fine but this application which uses js from research.microsoft.com was giving error.

I also noticed that mapcruncher site was not operational, after googling this problem on the code project site I got a post with same problem, which tells about Fiddler. A too which logs all http traffic between computer and internet, so using it I found out that the following files not getting download on my computer

  • http://research.microsoft.com/mapcruncher/scripts/v4/MapControl-CVE-obfuscated.js
  • http://research.microsoft.com/mapcruncher/scripts/v4/CrunchControl.js
  • http://research.microsoft.com/mapcruncher/scripts/v4/LegendStyle.css
The site is still down :(.