R
Rampf
Hello
Is it possible to format a storage card with .NET CF?
THanks a lot!
Rampf
Is it possible to format a storage card with .NET CF?
THanks a lot!
Rampf
Really the only way to find out actual values for those things, unless you
want to recreate the structure that the .h files use (macro CTL_CODE,
various values in various parameters to that, etc.), is to actually write a
little C program and run it to get the value. That's how I got the IOCTL
values that OpenNETCF.Net uses for various operations.
Paul T.
- Show quoted text -
Rampf said:Thanks
I was risky and looped all values Until I found it
Dirty but working
"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> schrieb im Newsbeitrag
Really the only way to find out actual values for those things, unless
you want to recreate the structure that the .h files use (macro CTL_CODE,
various values in various parameters to that, etc.), is to actually write
a little C program and run it to get the value. That's how I got the
IOCTL values that OpenNETCF.Net uses for various operations.
Paul T.
Ron Weiner said:I also have a need for this capability, would you mind sharing?
Thanx
Ron W
Rampf said:Thanks
I was risky and looped all values Until I found it
Dirty but working
"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam
DOT com> schrieb im Newsbeitrag
Really the only way to find out actual values for those things, unless
you want to recreate the structure that the .h files use (macro
CTL_CODE, various values in various parameters to that, etc.), is to
actually write a little C program and run it to get the value. That's
how I got the IOCTL values that OpenNETCF.Net uses for various
operations.
Paul T.
I had a difficult time finding that file, for some reason, but a google
search turned up this:
#define IOCTL_DISK_FORMAT_VOLUME CTL_CODE(IOCTL_DISK_BASE, 0x0088,
METHOD_BUFFERED, FILE_ANY_ACCESS)
This will be defined in diskio.h (part of the Windows CE SDK). I don't
have
this SDK installed so can't tell you what the value is.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com
:
Ok Second Try:
<DllImport("CoreDll.dll")> Shared Function DeviceIoControl(ByVal
hDevice
As Integer, ByVal dwIoControlCode As Integer, _
ByVal lpInBuffer As String, ByVal
nInBufferSize As
Integer, _
ByVal lpOutBuffer() As Byte, ByVal
nOutBufferSize
As Integer, _
ByRef lpBytesReturned As Integer, ByVal
lpOverlapped As Integer) As Integer
End Function
Const OPEN_EXISTING As Integer = 3
Const GENERIC_READ As Integer = &H80000000
Const GENERIC_WRITE As Integer = &H40000000
Declare Function CreateFile Lib "coredll" (ByVal lpFileName As
String,
ByVal dwDesiredAccess As Integer, ByVal dwShareMode As Integer, ByVal
lpSecurityAttributes As Integer, ByVal dwCreationDisposition As
Integer,
ByVal dwFLagsAndAttributes As Integer, ByVal hTemplateFile As
Integer) As
Integer
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim hVolume As IntPtr = CreateFile("\Speicherkarted\Vol:",
(GENERIC_READ Or GENERIC_WRITE), 0, Nothing, OPEN_EXISTING, 0,
Nothing)
DeviceIoControl(hVolume, IOCTL_DISK_FORMAT_VOLUME, 0, 0,
Nothing,
Nothing, 0, Nothing)
End Sub
But I still dont have the IOCTL_DISK_FORMAT_VOLUME value?
Rampf said:Of course I can share it:
Declare Function DeviceIoControl Lib "coredll" (ByVal hDevice As
Integer, ByVal dwIoControlCode As Integer, _
ByVal lpInBuffer As String, ByVal nInBufferSize As
Integer, _
ByVal lpOutBuffer() As Byte, ByVal nOutBufferSize As
Integer, _
ByRef lpBytesReturned As Integer, ByVal lpOverlapped
As Integer) As Integer
Declare Function CreateFile Lib "coredll" (ByVal lpFileName As String,
ByVal dwDesiredAccess As Integer, ByVal dwShareMode As Integer, ByVal
lpSecurityAttributes As Integer, ByVal dwCreationDisposition As Integer,
ByVal dwFLagsAndAttributes As Integer, ByVal hTemplateFile As Integer) As
Integer
Public Shared Function Format(ByVal StorageCard As String) As Boolean
If IsStorageCard(StorageCard) Then
Try
Return
(DeviceIoControl(CreateFile(IIf(StorageCard.EndsWith("\"), StorageCard &
"Vol:", StorageCard & "\Vol:"), (&H80000000 Or &H40000000), 0, Nothing, 3,
0, Nothing), 459296, 0, 0, Nothing, Nothing, 0, Nothing))
Catch ex As Exception
Return False
End Try
Else
Return False
End If
End Function
Private Shared Function IsStorageCard(ByVal Path) As Boolean
' Check if storage card
Dim fsi As New System.IO.DirectoryInfo(Path)
If fsi.Attributes = IO.FileAttributes.Temporary Or
IO.FileAttributes.Directory Then
Return True
Else
Return False
End If
End Function
Ron Weiner said:I also have a need for this capability, would you mind sharing?
Thanx
Ron W
Rampf said:Thanks
I was risky and looped all values Until I found it
Dirty but working
"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam
DOT com> schrieb im Newsbeitrag
Really the only way to find out actual values for those things, unless
you want to recreate the structure that the .h files use (macro
CTL_CODE, various values in various parameters to that, etc.), is to
actually write a little C program and run it to get the value. That's
how I got the IOCTL values that OpenNETCF.Net uses for various
operations.
Paul T.
I had a difficult time finding that file, for some reason, but a google
search turned up this:
#define IOCTL_DISK_FORMAT_VOLUME CTL_CODE(IOCTL_DISK_BASE, 0x0088,
METHOD_BUFFERED, FILE_ANY_ACCESS)
This will be defined in diskio.h (part of the Windows CE SDK). I
don't have
this SDK installed so can't tell you what the value is.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com
:
Ok Second Try:
<DllImport("CoreDll.dll")> Shared Function DeviceIoControl(ByVal
hDevice
As Integer, ByVal dwIoControlCode As Integer, _
ByVal lpInBuffer As String, ByVal
nInBufferSize As
Integer, _
ByVal lpOutBuffer() As Byte, ByVal
nOutBufferSize
As Integer, _
ByRef lpBytesReturned As Integer, ByVal
lpOverlapped As Integer) As Integer
End Function
Const OPEN_EXISTING As Integer = 3
Const GENERIC_READ As Integer = &H80000000
Const GENERIC_WRITE As Integer = &H40000000
Declare Function CreateFile Lib "coredll" (ByVal lpFileName As
String,
ByVal dwDesiredAccess As Integer, ByVal dwShareMode As Integer,
ByVal
lpSecurityAttributes As Integer, ByVal dwCreationDisposition As
Integer,
ByVal dwFLagsAndAttributes As Integer, ByVal hTemplateFile As
Integer) As
Integer
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim hVolume As IntPtr = CreateFile("\Speicherkarted\Vol:",
(GENERIC_READ Or GENERIC_WRITE), 0, Nothing, OPEN_EXISTING, 0,
Nothing)
DeviceIoControl(hVolume, IOCTL_DISK_FORMAT_VOLUME, 0, 0,
Nothing,
Nothing, 0, Nothing)
End Sub
But I still dont have the IOCTL_DISK_FORMAT_VOLUME value?
87 == invalid parameter, so something you're sending it it doesn't like. Do
you have a working example in C? That's where I'd start.
--
Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded communityhttp://community.OpenNETCF.com
Youraputz said:87 == invalid parameter, so something you're sending it it doesn't like.
Do
you have a working example in C? That's where I'd start.
--
Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded communityhttp://community.OpenNETCF.com
I just wrote a version in C to remove any of the C# issues that may
exist. I still get 87 when I run this code, but here it is, I've
included wince600\public\common\oak\inc and wince600\public\common\sdk
\inc in the project. I also tried changing "storage card" to "hard
disk" and tried with a usb drive, same error 87.
#include <windows.h>
#include <diskio.h>
#include <winioctl.h>
#include <stdio.h>
void main(int argc, char *argv[])
{
HANDLE hDevice;
BOOL bResult;
DWORD junk;
hDevice = CreateFile(TEXT("\\Storage Card\\Vol:"), 0, FILE_SHARE_READ
| FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if (hDevice == INVALID_HANDLE_VALUE)
{
printf("Invalid Handle\n");
return;
}
bResult = DeviceIoControl(hDevice,IOCTL_DISK_FORMAT_VOLUME, NULL, 0,
NULL, 0, &junk, (LPOVERLAPPED)NULL);
if (bResult == false)
{
printf("Last Error: %d\n", GetLastError());
}
CloseHandle(hDevice);
return;
}
I'm 99% certain that the "VOL:" text in the name is case sensitive and
*must* be all upper case (thank Paul Tobey for his pain last week in finding
that during an unrelated issue).
--
Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded communityhttp://community.OpenNETCF.com
I just wrote a version in C to remove any of the C# issues that may
exist. I still get 87 when I run this code, but here it is, I've
included wince600\public\common\oak\inc and wince600\public\common\sdk
\inc in the project. I also tried changing "storage card" to "hard
disk" and tried with a usb drive, same error 87.#include <windows.h>
#include <diskio.h>
#include <winioctl.h>
#include <stdio.h>void main(int argc, char *argv[])
{
HANDLE hDevice;
BOOL bResult;
DWORD junk;hDevice = CreateFile(TEXT("\\Storage Card\\Vol:"), 0, FILE_SHARE_READ
| FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);if (hDevice == INVALID_HANDLE_VALUE)
{
printf("Invalid Handle\n");
return;
}bResult = DeviceIoControl(hDevice,IOCTL_DISK_FORMAT_VOLUME, NULL, 0,
NULL, 0, &junk, (LPOVERLAPPED)NULL);if (bResult == false)
{
printf("Last Error: %d\n", GetLastError());
}
}
Youraputz said:Actually I just found this post, which claims the IOCTL I'm trying to
use has been removed in 6.0.
http://groups.google.com/group/micr...506e0?lnk=gst&q=formatvolume#59f8a86df27506e0
I'm 99% certain that the "VOL:" text in the name is case sensitive and
*must* be all upper case (thank Paul Tobey for his pain last week in
finding
that during an unrelated issue).
--
Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded communityhttp://community.OpenNETCF.com
On May 29, 11:07 am, "Chris Tacke, eMVP" <ctacke.at.opennetcf.dot.com>
wrote:
87 == invalid parameter, so something you're sending it it doesn't
like.
Do
you have a working example in C? That's where I'd start.
Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded communityhttp://community.OpenNETCF.comI tried changing the nulls to IntPtr.Zero, and as for the escaped
char, sorry, I missed the @ before the string. Checking GetLatError
is returning 87.I just wrote a version in C to remove any of the C# issues that may
exist. I still get 87 when I run this code, but here it is, I've
included wince600\public\common\oak\inc and wince600\public\common\sdk
\inc in the project. I also tried changing "storage card" to "hard
disk" and tried with a usb drive, same error 87.#include <windows.h>
#include <diskio.h>
#include <winioctl.h>
#include <stdio.h>void main(int argc, char *argv[])
{
HANDLE hDevice;
BOOL bResult;
DWORD junk;hDevice = CreateFile(TEXT("\\Storage Card\\Vol:"), 0, FILE_SHARE_READ
| FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);if (hDevice == INVALID_HANDLE_VALUE)
{
printf("Invalid Handle\n");
return;
}bResult = DeviceIoControl(hDevice,IOCTL_DISK_FORMAT_VOLUME, NULL, 0,
NULL, 0, &junk, (LPOVERLAPPED)NULL);if (bResult == false)
{
printf("Last Error: %d\n", GetLastError());
}
}
Youraputz said:Actually I just found this post, which claims the IOCTL I'm trying to
use has been removed in 6.0.
http://groups.google.com/group/micr...506e0?lnk=gst&q=formatvolume#59f8a86df27506e0
I'm 99% certain that the "VOL:" text in the name is case sensitive and
*must* be all upper case (thank Paul Tobey for his pain last week in
finding
that during an unrelated issue).
--
Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded communityhttp://community.OpenNETCF.com
On May 29, 11:07 am, "Chris Tacke, eMVP" <ctacke.at.opennetcf.dot.com>
wrote:
87 == invalid parameter, so something you're sending it it doesn't
like.
Do
you have a working example in C? That's where I'd start.
Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded communityhttp://community.OpenNETCF.comI tried changing the nulls to IntPtr.Zero, and as for the escaped
char, sorry, I missed the @ before the string. Checking GetLatError
is returning 87.I just wrote a version in C to remove any of the C# issues that may
exist. I still get 87 when I run this code, but here it is, I've
included wince600\public\common\oak\inc and wince600\public\common\sdk
\inc in the project. I also tried changing "storage card" to "hard
disk" and tried with a usb drive, same error 87.#include <windows.h>
#include <diskio.h>
#include <winioctl.h>
#include <stdio.h>void main(int argc, char *argv[])
{
HANDLE hDevice;
BOOL bResult;
DWORD junk;hDevice = CreateFile(TEXT("\\Storage Card\\Vol:"), 0, FILE_SHARE_READ
| FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);if (hDevice == INVALID_HANDLE_VALUE)
{
printf("Invalid Handle\n");
return;
}bResult = DeviceIoControl(hDevice,IOCTL_DISK_FORMAT_VOLUME, NULL, 0,
NULL, 0, &junk, (LPOVERLAPPED)NULL);if (bResult == false)
{
printf("Last Error: %d\n", GetLastError());
}
}