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("core dll.dll", SetLastError=tr ue, CharSet=CharSet .Auto)]
public static extern IntPtr CreateFile(
string lpFileName,
uint dwDesiredAccess ,
uint dwShareMode,
IntPtr lpSecurityAttri butes,
uint dwCreationDispo sition,
uint dwFlagsAndAttri butes,
IntPtr hTemplateFile
);
[DllImport("core dll.dll", EntryPoint="Cre ateFileW", SetLastError = true,
CharSet=CharSet .Auto)]
private static extern IntPtr CreateFileW(
string lpFileName,
uint dwDesiredAccess ,
uint dwShareMode,
IntPtr lpSecurityAttri butes,
uint dwCreationDispo sition,
uint dwFlagsAndAttri butes,
IntPtr hTemplateFile
);
Then, I try to open the device with this code:
hMSD = CreateFileW( "UIO1:", GENERIC_READ|GE NERIC_WRITE, 0,
System.IntPtr.Z ero, OPEN_EXISTING, 0, System.IntPtr.Z ero);
if( hMSD == new IntPtr(-1) || Marshal.GetLast Win32Error()>0)
{
System.Windows. Forms.MessageBo x.Show( "ERROR
n"+Marshal.GetL astWin32Error() , "ERROR !",
System.Windows. Forms.MessageBo xButtons.OK,
System.Windows. Forms.MessageBo xIcon.Exclamati on,
System.Windows. Forms.MessageBo xDefaultButton. Button1);
throw(new ApplicationExce ption( "ERROR
["+Marshal.GetLa stWin32Error()+ "]: opening port."));
}
I tried to open device with CreateFile() and CECreateFileW() functions, but
none really succeeded.
* CreateFile() fails and GetLastWin32Err or() 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 GetLastWin32Err or() 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. 3 7474
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("core dll.dll", SetLastError=tr ue, CharSet=CharSet .Auto)] public static extern IntPtr CreateFile( string lpFileName, uint dwDesiredAccess , uint dwShareMode, IntPtr lpSecurityAttri butes, uint dwCreationDispo sition, uint dwFlagsAndAttri butes, IntPtr hTemplateFile ); [DllImport("core dll.dll", EntryPoint="Cre ateFileW", SetLastError = true, CharSet=CharSet .Auto)] private static extern IntPtr CreateFileW( string lpFileName, uint dwDesiredAccess , uint dwShareMode, IntPtr lpSecurityAttri butes, uint dwCreationDispo sition, uint dwFlagsAndAttri butes, IntPtr hTemplateFile );
Then, I try to open the device with this code: hMSD = CreateFileW( "UIO1:", GENERIC_READ|GE NERIC_WRITE, 0, System.IntPtr.Z ero, OPEN_EXISTING, 0, System.IntPtr.Z ero); if( hMSD == new IntPtr(-1) || Marshal.GetLast Win32Error()>0) { System.Windows. Forms.MessageBo x.Show( "ERROR n"+Marshal.GetL astWin32Error() , "ERROR !", System.Windows. Forms.MessageBo xButtons.OK, System.Windows. Forms.MessageBo xIcon.Exclamati on, System.Windows. Forms.MessageBo xDefaultButton. Button1); throw(new ApplicationExce ption( "ERROR ["+Marshal.GetLa stWin32Error()+ "]: opening port.")); }
I tried to open device with CreateFile() and CECreateFileW() functions,
but none really succeeded. * CreateFile() fails and GetLastWin32Err or() 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 GetLastWin32Err or() 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 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.mach in AT dot.state.fl.us > a
écrit dans le message de news:ug******** ******@TK2MSFTN GP10.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("core dll.dll", SetLastError=tr ue, CharSet=CharSet .Auto)] public static extern IntPtr CreateFile( string lpFileName, uint dwDesiredAccess , uint dwShareMode, IntPtr lpSecurityAttri butes, uint dwCreationDispo sition, uint dwFlagsAndAttri butes, IntPtr hTemplateFile ); [DllImport("core dll.dll", EntryPoint="Cre ateFileW", SetLastError = true, CharSet=CharSet .Auto)] private static extern IntPtr CreateFileW( string lpFileName, uint dwDesiredAccess , uint dwShareMode, IntPtr lpSecurityAttri butes, uint dwCreationDispo sition, uint dwFlagsAndAttri butes, IntPtr hTemplateFile );
Then, I try to open the device with this code: hMSD = CreateFileW( "UIO1:", GENERIC_READ|GE NERIC_WRITE, 0, System.IntPtr.Z ero, OPEN_EXISTING, 0, System.IntPtr.Z ero); if( hMSD == new IntPtr(-1) || Marshal.GetLast Win32Error()>0) { System.Windows. Forms.MessageBo x.Show( "ERROR n"+Marshal.GetL astWin32Error() , "ERROR !", System.Windows. Forms.MessageBo xButtons.OK, System.Windows. Forms.MessageBo xIcon.Exclamati on, System.Windows. Forms.MessageBo xDefaultButton. Button1); throw(new ApplicationExce ption( "ERROR ["+Marshal.GetLa stWin32Error()+ "]: opening port.")); }
I tried to open device with CreateFile() and CECreateFileW() functions, but none really succeeded. * CreateFile() fails and GetLastWin32Err or() 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 GetLastWin32Err or() 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.
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.mach in AT dot.state.fl.us > a écrit dans le message de news:ug******** ******@TK2MSFTN GP10.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("core dll.dll", SetLastError=tr ue, CharSet=CharSet .Auto)] public static extern IntPtr CreateFile( string lpFileName, uint dwDesiredAccess , uint dwShareMode, IntPtr lpSecurityAttri butes, uint dwCreationDispo sition, uint dwFlagsAndAttri butes, IntPtr hTemplateFile ); [DllImport("core dll.dll", EntryPoint="Cre ateFileW", SetLastError =
true, CharSet=CharSet .Auto)] private static extern IntPtr CreateFileW( string lpFileName, uint dwDesiredAccess , uint dwShareMode, IntPtr lpSecurityAttri butes, uint dwCreationDispo sition, uint dwFlagsAndAttri butes, IntPtr hTemplateFile );
Then, I try to open the device with this code: hMSD = CreateFileW( "UIO1:", GENERIC_READ|GE NERIC_WRITE, 0, System.IntPtr.Z ero, OPEN_EXISTING, 0, System.IntPtr.Z ero); if( hMSD == new IntPtr(-1) || Marshal.GetLast Win32Error()>0) { System.Windows. Forms.MessageBo x.Show( "ERROR n"+Marshal.GetL astWin32Error() , "ERROR !", System.Windows. Forms.MessageBo xButtons.OK, System.Windows. Forms.MessageBo xIcon.Exclamati on, System.Windows. Forms.MessageBo xDefaultButton. Button1); throw(new ApplicationExce ption( "ERROR ["+Marshal.GetLa stWin32Error()+ "]: opening port.")); }
I tried to open device with CreateFile() and CECreateFileW()
functions, but none really succeeded. * CreateFile() fails and GetLastWin32Err or() 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 GetLastWin32Err or() 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.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 WriteFile
I have written C code which works fine, just the VB translation/port
|
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 our QA server from build
8.00.928 to SP4. Since then, the Snapshot Agent fails to create files
on our File Server. We have checked and double-checked all
permissions, shares, etc. But we keep getting the following error
randomly on any step:
|
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 (returning a -1).
Here's the code:
Const GENERIC_READ = &H80000000
Const OPEN_EXISTING = 3
Const FILE_SHARE_READ = &H1
Const FILE_SHARE_WRITE = &H2
Const FILE_ATTRIBUTE_NORMAL = &H80
|
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 (ERROR_ACCESS_DENIED) as if the
COM port is inaccessible from the program. I am including a code snippit with
the createFile call in hopes that someone out there has seen this before and
can help. abytes is a string "COM1", and imode is set to the overlapped...
|
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 with this defination:
Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal
lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode
As Long, ByVal NULLSecurityAttributes As Long, ByVal
dwCreationDisposition As Long,...
| |
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 CRC-32 calculation can
be performed on all of the bytes of the logical drive. This is my first
experience with the CreateFile function.
Here is the problem(s) that I am having.
|
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);
With VC++6.0, this executes fine and I am able to establish a
connection w/ a device via COM1 however I recently installed VC++8
(.net 2005) and this code no longer works. It last error to
ERROR_INVALID_NAME. Any recommendations will be greatly...
|
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 message:
A call to PInvoke function 'BlastronicsGpi!BlastronicsGpi.cGpi::CreateFile'
has unbalanced the stack. This is likely because the managed PInvoke
signature does not match the unmanaged target signature. Check that the
calling convention...
|
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, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)
but this fails to open folders ("Access is Denied") or files that are
already used (as far as I understand).
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |