Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to test SD card using Pocket PC Emulator 1

Status
Not open for further replies.

VenkatRastapuram

Programmer
Oct 24, 2003
46
IN
Hello Sir,

I have developed an application in C#.NET and it contails a database file. So I want to transfer this database file into a SD card connected to. So please tell me how to simulate the SD card with the Emulator and how to transfer the database file from the Pocket PC to SD card. Is there anybody who can solve my problem. Please think it as urgent.

Thank U.

Regards,
R.Venkatesh
MakeLogic
venkat@makelogicmldb.com
 
I was looking through the Visual Studio help this morning and saw an article called "Pocket PC Programming Tips". It said that in order to see what storage cards are installed you use the FindFirstFile API to obtain the names of any storage cards.

This doesn't answer your question directly but it might help you solve your problem.

To answer your question, I don't think the emulated Pocket PC has any storage cards installed. I also don't think it's possible to change the emulator so that it thinks it has a card.

Nelviticus
 
Hi Nelviticus,

Thank you for your reply.

The FindFirstFile API is used to search for a file and it does not solve my problem. It is not necessary that Pocket Pc should be a emulator. It can be a Pocket PC also. I just want to access SD card from the Pocket PC. How to do this.

Thanking U


R.Venkatesh
MakeLogic
venkat@makelogicmldb.com
 
OK, firstly I should explain that I've never programmed for Pocket PC, I just found an article about it the other day.

The sample code used the FindFirstFile API to loop through all the files that have the 'directory' flag set and the 'temporary' flag set. An SD card will be a file that's flagged as 'directory' and 'temporary'. Once you've found it you can use the reference to write to it.

If you want to see the sample code it's in the MSDN library that comes with Visual Studio .Net 2003. It's under MSDN Library/Mobile and Embedded Development/Pocket PC and Smartphone/Pocket PC/Columns/Two for the Road/Pocket PC Programming Tips.

Nelviticus
 
Hi Nelviticus,

Thank U for Ur suggestion. It helped in solving my problem.

The followin code helps in checking the existance of storage card as well as reading the files from it.


using System;
using System.Drawing;
using System.Collections;
using System.IO;
using System.Windows.Forms;
using System.Data;

using System.Text;
using System.Runtime.InteropServices;


namespace FindFirstFileSample
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class FindFirstFileSample : System.Windows.Forms.Form
{
const int MAX_PATH = 260;

/// <summary>
/// My Computer, which is a virtual folder that contains everything
/// on the local computer: storage devices, printers, and
/// Control Panel.
/// </summary>
const int CSIDL_DRIVES = 0x0011;

public class LibWrap
{

/// <summary>
/// This function retrieves the handle to the window, if any, that has
/// captured the mouse or stylus input. Only one window at a time can
/// capture the mouse or stylus input.
/// </summary>
/// <returns>The handle of the capture window associated with the current
/// thread indicates success. NULL indicates that no window in the current
/// thread has captured the mouse.</returns>
[DllImport("coredll.dll")]
public static extern IntPtr GetCapture();

/// <summary>
/// This function retrieves the path of a special folder, identified
/// by its CSIDL.
/// </summary>
/// <param name="hwndOwner">Handle to the owner window the client should
/// specify if it displays a dialog box or message box.</param>
/// <param name="lpszPath">Address of a character buffer that receives
/// the drive and path of the specified folder. This buffer must be at
/// least MAX_PATH characters in size.</param>
/// <param name="nFolder"> CSIDL that identifies the folder of interest.
/// If a virtual folder is specified, this function fails.</param>
/// <param name="fCreate">Indicates if the folder should be created if
/// it does not already exist. If this value is nonzero, the folder will
/// be created. If this value is zero, the folder will not be
/// created.</param>
/// <returns>Returns FALSE even if successful.</returns>
[DllImport("Coredll.dll")]
public static extern int SHGetSpecialFolderPath
(
IntPtr hwndOwner,
StringBuilder lpszPath,
int nFolder,
int fCreate
);

}

public FindFirstFileSample()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

try
{
//..Gets Handle to a window
IntPtr hwnd = LibWrap.GetCapture();

MessageBox.Show("Checking for storage cards...","Message");

bool bFoundOne = false;
DirectoryInfo rootDir = new DirectoryInfo("\\");
foreach (FileSystemInfo fsi in rootDir.GetFileSystemInfos())
{
if ((FileAttributes.Directory | FileAttributes.Temporary) == (fsi.Attributes & (FileAttributes.Directory | FileAttributes.Temporary)))
{
MessageBox.Show(fsi.Name,"File Name");
bFoundOne = true;
}
}

if (!bFoundOne)
MessageBox.Show("None found","Message");

//..Debug
MessageBox.Show("Finding Programs folder path","Message");

StringBuilder folderName = new StringBuilder(MAX_PATH);

//..Searches for the files in the Drives(storage card)
LibWrap.SHGetSpecialFolderPath(hwnd, folderName, CSIDL_DRIVES, 0);

if (string.Compare(folderName.ToString(), "") != 0)
{
MessageBox.Show(folderName.ToString(),"Folder Name");
}
else
{
MessageBox.Show("FAILURE : Not Found","Message");
}
}
catch(Exception exp)
{
//..Debug
MessageBox.Show(exp.ToString()+"\n"+exp.Message,"Unknown Error");
}

}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
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()
{
//
// FindFirstFileSample
//
this.Text = "FindFirstFileSample";

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>

static void Main()
{
Application.Run(new FindFirstFileSample());
}
}

}

Regards,
R.Venkatesh
MakeLogic
venkat@makelogicmldb.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top