i created a custom installer for my mobile application, the problem is if device is not connected to cradle it tries to install the application next time the device is connected. i dont want it to happen, i want to check if device is connected to cradle.

help please.

come on guys, none of you develop application for windows mobile devices? whenever i have a problem regarding windows mobile or compact framework, you leave me all alone.

we need to import here some god damn mobile developers..

sometimes i really dont understand. i ask a question or search google hoping that this must have been asked before milion times and end up realizing that i am the only one ask this question or i am the only one stating the question the way i do. look at my thread title, does not it sound so common to you?

Sometimes, but you must answer\put work around in a blog to make it easier for whom they come after.

i finally found this god damn thing. i am proud of it, i dedicate this post to Marty Friedman especially for his most awkward picking technique.

Form1.cs :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace CheckIfDeviceConnected
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
			
		}

		[DllImport("rapi.dll")]
		public static extern void CeRapiInitEx(ref RAPIINIT pRapiInit);

		[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
		public static extern Int32 CeRapiUninit();

		[StructLayout(LayoutKind.Sequential)]
		public struct RAPIINIT
		{
			public int cbsize;
			public IntPtr heRapiInit;
			public UInt32 hrRapiInit;
		};

		


	
		private void btnCheck_Click(object sender, EventArgs e)
		{
			try
			{
				RAPIINIT r = new RAPIINIT();
				r.cbsize = Marshal.SizeOf(r);
				CeRapiInitEx(ref r);
				if (r.hrRapiInit==0)
				{
					MessageBox.Show("Device is connected");
				}
				else
				{
					MessageBox.Show("Device is not connected");
				}
			}
			finally
			{
				CeRapiUninit();
			}
		}
	

	}
}

Form1.Designer.cs :

namespace CheckIfDeviceConnected
{
	partial class Form1
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}

		#region Windows Form Designer generated code

		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.btnCheck = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// btnCheck
			// 
			this.btnCheck.Location = new System.Drawing.Point(30, 49);
			this.btnCheck.Name = "btnCheck";
			this.btnCheck.Size = new System.Drawing.Size(219, 23);
			this.btnCheck.TabIndex = 0;
			this.btnCheck.Text = "Check If Device Connected To Cradle";
			this.btnCheck.UseVisualStyleBackColor = true;
			this.btnCheck.Click += new System.EventHandler(this.btnCheck_Click);
			// 
			// Form1
			// 
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.ClientSize = new System.Drawing.Size(277, 147);
			this.Controls.Add(this.btnCheck);
			this.Name = "Form1";
			this.Text = "Form1";
			this.ResumeLayout(false);

		}

		#endregion

		private System.Windows.Forms.Button btnCheck;
	}
}

i attach the project too.

Thanks for posting this, it helps me a lot !

Thanks for posting this, it helps me a lot !

yeah man, it took me more than a month to come up with that code.
when it is a matter of mobile development, you cant find help easily unfortunately.

Thanks Serkan. I tested your code and it works great. Now I have a base to build upon.

Scott

Thanks Serkan Sendur. The code help me to develop my first Windows Mobile application.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.