473,322 Members | 1,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

CreateFile fails - 120 error code

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.Butto n1);
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.



Nov 15 '05 #1
3 7441
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" <an***********@free.fr> wrote in message
news:40***********************@news.free.fr...
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.Butto n1);
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.



Nov 15 '05 #2
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 )" <ignacio.machin AT dot.state.fl.us> a
écrit dans le message de news:ug**************@TK2MSFTNGP10.phx.gbl...
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" <an***********@free.fr> wrote in message
news:40***********************@news.free.fr...
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.Butto n1);
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.




Nov 15 '05 #3
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" <an************@iaai.fr> a écrit dans le message de
news:40***********************@news.free.fr...
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 )" <ignacio.machin AT dot.state.fl.us> a
écrit dans le message de news:ug**************@TK2MSFTNGP10.phx.gbl...
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" <an***********@free.fr> wrote in message
news:40***********************@news.free.fr...
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.Butto n1);
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.





Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chuck Rittersdorf | last post by:
Hi There I am having a problem using the win32 API from VB6. I am trying to send a command string to a printer(zebra TLP 2742) on LPT1 using the folowing API functions CreateFile and...
0
by: deepakjgupta | last post by:
Hello all, We are using SQL Server 2000 (Enterprise Edition) Merge Replication to synchronize databases between a main server database and about 200 local MSDE databases. Recently, we upgraded...
12
by: Terry Olsen | last post by:
I'm trying to create a disk image of a floppy disk. Since I can't open the device using the system.io methods, i'm trying to use the CreateFile API to get a handle for me. But the call fails...
0
by: JohnnyBoy | last post by:
I am playing with a Microsoft code example that uses the creatFile call to open a stream to a serial COM port. When I execute the example, the createFile call fails with an error code 5...
5
by: Fla | last post by:
Hy! I'm a newbie to VB 2005 and I have to connect my program to a driver previously developed for a custom ISA card. With my old VB 6 code I used the routine CreateFileA exported from kernel32...
2
by: Jim Flanagan | last post by:
Hi... I am using VB.net Express to experiment with the Win32 API functions that are available. The current project is an application that will read the raw sectors of a logical drive so that a...
5
by: =?Utf-8?B?R2FyeQ==?= | last post by:
Been struggling with the code below for the last couple of days: m_hSerialHandle = CreateFile("COM1:", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, /*FILE_FLAG_OVERLAPPED*/0, NULL); ...
2
by: Lou | last post by:
i am using CreateFile in a VB6 app but it doesn't work in VB .NET COM dll. hGpiFile = CreateFile("\\.\BLIO1", GENERIC_READ Or GENERIC_WRITE, 0, gblSecurity, OPEN_EXISTING, 0, 0) I get an error...
9
by: =?Utf-8?B?SGVyemwgUmVnZXY=?= | last post by:
What arguments do I need to give CreateFile? I want to open a file or folder for reading, even if it is already opened from another place. I'm trying: CreateFile (argv, GENERIC_READ,...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.