CreateFile fails - 120 error code

A

Antoine

Hello,

I'm writing a program to send requests to my wlan pocket pc device (UIO1:
driver) in C#.

Here how I import CreateFile functions from coredll.dll with DllImport:
[DllImport("coredll.dll", SetLastError=true, CharSet=CharSet.Auto)]
public static extern IntPtr CreateFile(
string lpFileName,
uint dwDesiredAccess,
uint dwShareMode,
IntPtr lpSecurityAttributes,
uint dwCreationDisposition,
uint dwFlagsAndAttributes,
IntPtr hTemplateFile
);
[DllImport("coredll.dll", EntryPoint="CreateFileW", SetLastError = true,
CharSet=CharSet.Auto)]
private static extern IntPtr CreateFileW(
string lpFileName,
uint dwDesiredAccess,
uint dwShareMode,
IntPtr lpSecurityAttributes,
uint dwCreationDisposition,
uint dwFlagsAndAttributes,
IntPtr hTemplateFile
);

Then, I try to open the device with this code:
hMSD = CreateFileW( "UIO1:", GENERIC_READ|GENERIC_WRITE, 0,
System.IntPtr.Zero, OPEN_EXISTING, 0, System.IntPtr.Zero);
if( hMSD == new IntPtr(-1) || Marshal.GetLastWin32Error()>0)
{
System.Windows.Forms.MessageBox.Show( "ERROR
n"+Marshal.GetLastWin32Error(), "ERROR !",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Exclamation,
System.Windows.Forms.MessageBoxDefaultButton.Button1);
throw(new ApplicationException( "ERROR
["+Marshal.GetLastWin32Error()+"]: opening port."));
}

I tried to open device with CreateFile() and CECreateFileW() functions, but
none really succeeded.
* CreateFile() fails and GetLastWin32Error() returns 87 error code
(ERROR_INVALID_PARAMETER).
* CreateFileW() succeed with integrated POCKET PC 2003 EMULATOR but fails on
my Pocket PC 2003 (Windows CE 4.2) where GetLastWin32Error() returns 120
error code (ERROR_CALL_NOT_IMPLEMENTED).

Then, I tried to play with CharSet DllImport attribute, but with no success.

The same program wrote in C++ runs...

My english is poor, so I hope you understood my problem.
Thank you for you help.


Antoine.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi Antoine,

Try changing the parameters of type string to type StringBuilder.

Cheers,
 
A

Antoine

I tried to change the parameters of type string to type StringBuilder, but
this does nothing.

I wonder what makes the difference between the emulator and my pocket PC,
and why this code only succeed with the emulator and with CreateFileW()
function (whereas CreateFileA() does not exist in coredll.dll and
CreateFile() seems to be an alias of CreateFileW()) ??

This is very strange!

Thanks.

Antoine.



Ignacio Machin ( .NET/ C# MVP ) said:
Hi Antoine,

Try changing the parameters of type string to type StringBuilder.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Antoine said:
Hello,

I'm writing a program to send requests to my wlan pocket pc device (UIO1:
driver) in C#.

Here how I import CreateFile functions from coredll.dll with DllImport:
[DllImport("coredll.dll", SetLastError=true, CharSet=CharSet.Auto)]
public static extern IntPtr CreateFile(
string lpFileName,
uint dwDesiredAccess,
uint dwShareMode,
IntPtr lpSecurityAttributes,
uint dwCreationDisposition,
uint dwFlagsAndAttributes,
IntPtr hTemplateFile
);
[DllImport("coredll.dll", EntryPoint="CreateFileW", SetLastError = true,
CharSet=CharSet.Auto)]
private static extern IntPtr CreateFileW(
string lpFileName,
uint dwDesiredAccess,
uint dwShareMode,
IntPtr lpSecurityAttributes,
uint dwCreationDisposition,
uint dwFlagsAndAttributes,
IntPtr hTemplateFile
);

Then, I try to open the device with this code:
hMSD = CreateFileW( "UIO1:", GENERIC_READ|GENERIC_WRITE, 0,
System.IntPtr.Zero, OPEN_EXISTING, 0, System.IntPtr.Zero);
if( hMSD == new IntPtr(-1) || Marshal.GetLastWin32Error()>0)
{
System.Windows.Forms.MessageBox.Show( "ERROR
n"+Marshal.GetLastWin32Error(), "ERROR !",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Exclamation,
System.Windows.Forms.MessageBoxDefaultButton.Button1);
throw(new ApplicationException( "ERROR
["+Marshal.GetLastWin32Error()+"]: opening port."));
}

I tried to open device with CreateFile() and CECreateFileW() functions, but
none really succeeded.
* CreateFile() fails and GetLastWin32Error() returns 87 error code
(ERROR_INVALID_PARAMETER).
* CreateFileW() succeed with integrated POCKET PC 2003 EMULATOR but
fails
on
my Pocket PC 2003 (Windows CE 4.2) where GetLastWin32Error() returns 120
error code (ERROR_CALL_NOT_IMPLEMENTED).

Then, I tried to play with CharSet DllImport attribute, but with no success.

The same program wrote in C++ runs...

My english is poor, so I hope you understood my problem.
Thank you for you help.


Antoine.
 
A

Antoine

The most strange is that error 120 means the function is not supported on
the system (ERROR_CALL_NOT_IMPLEMENTED), but the same program written in C++
doesn't return any error.


Antoine said:
I tried to change the parameters of type string to type StringBuilder, but
this does nothing.

I wonder what makes the difference between the emulator and my pocket PC,
and why this code only succeed with the emulator and with CreateFileW()
function (whereas CreateFileA() does not exist in coredll.dll and
CreateFile() seems to be an alias of CreateFileW()) ??

This is very strange!

Thanks.

Antoine.



Ignacio Machin ( .NET/ C# MVP ) said:
Hi Antoine,

Try changing the parameters of type string to type StringBuilder.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Antoine said:
Hello,

I'm writing a program to send requests to my wlan pocket pc device (UIO1:
driver) in C#.

Here how I import CreateFile functions from coredll.dll with DllImport:
[DllImport("coredll.dll", SetLastError=true, CharSet=CharSet.Auto)]
public static extern IntPtr CreateFile(
string lpFileName,
uint dwDesiredAccess,
uint dwShareMode,
IntPtr lpSecurityAttributes,
uint dwCreationDisposition,
uint dwFlagsAndAttributes,
IntPtr hTemplateFile
);
[DllImport("coredll.dll", EntryPoint="CreateFileW", SetLastError = true,
CharSet=CharSet.Auto)]
private static extern IntPtr CreateFileW(
string lpFileName,
uint dwDesiredAccess,
uint dwShareMode,
IntPtr lpSecurityAttributes,
uint dwCreationDisposition,
uint dwFlagsAndAttributes,
IntPtr hTemplateFile
);

Then, I try to open the device with this code:
hMSD = CreateFileW( "UIO1:", GENERIC_READ|GENERIC_WRITE, 0,
System.IntPtr.Zero, OPEN_EXISTING, 0, System.IntPtr.Zero);
if( hMSD == new IntPtr(-1) || Marshal.GetLastWin32Error()>0)
{
System.Windows.Forms.MessageBox.Show( "ERROR
n"+Marshal.GetLastWin32Error(), "ERROR !",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Exclamation,
System.Windows.Forms.MessageBoxDefaultButton.Button1);
throw(new ApplicationException( "ERROR
["+Marshal.GetLastWin32Error()+"]: opening port."));
}

I tried to open device with CreateFile() and CECreateFileW()
functions,
but
none really succeeded.
* CreateFile() fails and GetLastWin32Error() returns 87 error code
(ERROR_INVALID_PARAMETER).
* CreateFileW() succeed with integrated POCKET PC 2003 EMULATOR but
fails
on
my Pocket PC 2003 (Windows CE 4.2) where GetLastWin32Error() returns 120
error code (ERROR_CALL_NOT_IMPLEMENTED).

Then, I tried to play with CharSet DllImport attribute, but with no success.

The same program wrote in C++ runs...

My english is poor, so I hope you understood my problem.
Thank you for you help.


Antoine.
 

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