retrieve SD (secure digital) card number, etc

A

achen

Hi All,
I'm trying to convert our software run in Palm OS
to C# in .NET CF.

the software uses Palm OS API to check the presence of the SD (secure digital) card,
retrieve the SD card number, get notification upon the removal of the SD card.

what are the methods or API in .NET CF for these jobs ?
I've been searching for this unsuccessfully and appreciate all your help !
 
N

Nazim Lala [MSFT]

Bottom line is you will need to use native (WinCE) code written in C to
achieve this, and then P/invoke down to your native code from C#. What you
want to do is pretty much driver level stuff and NETCF won't have wrappers
for stuff like that. There's a whole section on interop with native code at
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/faq/default.a
spx#6.0
Here's some stuff that might get you started though.

As far as notifications for insertion/removal of SD cards goes I guess you
can listen for WM_FILECHANGEINFO message. It notifies you of file /
directory changes (including SD card changes). LPARAM in this case is
FILECHANGEINFO structure. Fci value should be SHCNE_CREATE or SHCNE_DELETE.

As for the SD card id you would need to use DeviceIOControl(), something
like ...

DWORD fileAttr = GetFileAttributes( VolumeString );
if( ( fileAttr != -1 ) &&( fileAttr & ( FILE_ATTRIBUTE_DIRECTORY |
FILE_ATTRIBUTE_TEMPORARY ) ) ) {
wcscpy( volString, VolumeString );
wcscat( volString, L"Vol:" );
hVolume = CreateFile( volString, GENERIC_READ|GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, 0, NULL);
if( hVolume != INVALID_HANDLE_VALUE ) {
DeviceIoControl( hVolume, IOCTL_DISK_GET_STORAGEID, NULL, 0,
DiskID, MAX_VOLUME_NAME, &dwBytesRead, NULL );
CloseHandle( hVolume );
}
}
if( dwBytesRead ) {
pDiskID = (PSTORAGE_IDENTIFICATION)DiskID;
cbHwId = dwBytesRead - pDiskID->dwSerialNumOffset - 1;
pbHwId = (BYTE *)(DiskID + pDiskID->dwSerialNumOffset);
}
else {
cbHwId = dwUniqueIDLen;
pbHwId = lpUniqueID;
}


PS: I haven't tried compiling this code ...



This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------
 
N

Nazim Lala [MSFT]

Oops, I got the wrong values for FCI below. They should be SHCNE_DRIVEADD
and SHCNE_DRIVEREMOVED.


This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------
X-Tomcat-ID: 53302278
References: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
From: (e-mail address removed) (Nazim Lala [MSFT])
Organization: Microsoft
Date: Wed, 14 Jan 2004 01:58:38 GMT
Subject: RE: retrieve SD (secure digital) card number, etc
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
Lines: 80
Path: cpmsftngxa07.phx.gbl
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.compactframework:42942
NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182

Bottom line is you will need to use native (WinCE) code written in C to
achieve this, and then P/invoke down to your native code from C#. What you
want to do is pretty much driver level stuff and NETCF won't have wrappers
for stuff like that. There's a whole section on interop with native code athttp://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/faq/default.a
spx#6.0
Here's some stuff that might get you started though.

As far as notifications for insertion/removal of SD cards goes I guess you
can listen for WM_FILECHANGEINFO message. It notifies you of file /
directory changes (including SD card changes). LPARAM in this case is
FILECHANGEINFO structure. Fci value should be SHCNE_CREATE or SHCNE_DELETE.

As for the SD card id you would need to use DeviceIOControl(), something
like ...

DWORD fileAttr = GetFileAttributes( VolumeString );
if( ( fileAttr != -1 ) &&( fileAttr & ( FILE_ATTRIBUTE_DIRECTORY |
FILE_ATTRIBUTE_TEMPORARY ) ) ) {
wcscpy( volString, VolumeString );
wcscat( volString, L"Vol:" );
hVolume = CreateFile( volString, GENERIC_READ|GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, 0, NULL);
if( hVolume != INVALID_HANDLE_VALUE ) {
DeviceIoControl( hVolume, IOCTL_DISK_GET_STORAGEID, NULL, 0,
DiskID, MAX_VOLUME_NAME, &dwBytesRead, NULL );
CloseHandle( hVolume );
}
}
if( dwBytesRead ) {
pDiskID = (PSTORAGE_IDENTIFICATION)DiskID;
cbHwId = dwBytesRead - pDiskID->dwSerialNumOffset - 1;
pbHwId = (BYTE *)(DiskID + pDiskID->dwSerialNumOffset);
}
else {
cbHwId = dwUniqueIDLen;
pbHwId = lpUniqueID;
}


PS: I haven't tried compiling this code ...



This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: (e-mail address removed)
Newsgroups: microsoft.public.dotnet.framework.compactframework
Subject: retrieve SD (secure digital) card number, etc
Date: 25 Nov 2003 08:35:10 -0800
Organization: http://groups.google.com
Lines: 9
Message-ID: <[email protected]>
NNTP-Posting-Host: 66.20.18.101
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: posting.google.com 1069778111 30756 127.0.0.1 (25 Nov 2003 16:35:11 GMT)
X-Complaints-To: (e-mail address removed)
NNTP-Posting-Date: Tue, 25 Nov 2003 16:35:11 +0000 (UTC)
Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08..phx.gbl!news-out.cwix.com!newsfeed.cwix.com!news.maxwell.syr.edu!postnews1.
google.com!not-for-mail
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.compactframework:39317
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

Hi All,
I'm trying to convert our software run in Palm OS
to C# in .NET CF.

the software uses Palm OS API to check the presence of the SD (secure digital) card,
retrieve the SD card number, get notification upon the removal of the
SD
card.

what are the methods or API in .NET CF for these jobs ?
I've been searching for this unsuccessfully and appreciate all your help !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top