CreateFile

J

JLW

I'm having alot of difficulty with this one. I have seen no less than 20
different ways to use this function with a named pipe. I'm trying to use
\\.\TAPE0 (TapeDrive).
Here's my decleration:

[DllImport(
"kernel32.dll",
SetLastError=true,
EntryPoint="CreateFileA"
)]
internal static extern IntPtr CreateFile(
String filename,
UInt32 desiredAccess,
UInt32 shareMode,
IntPtr attributes, // Really, this is the SECURITY_ATTRIBUTES pointer
UInt32 creationDisposition,
UInt32 flagsAndAttributes,
IntPtr templateFile
);

And here's my call:
_Handle = CreateFile(
@"\\.\TAPE0",
GENERIC_READ | GENERIC_WRITE,
0,
IntPtr.Zero,
CREATE_NEW,
0,
IntPtr.Zero
);

It returns -1, so it's not working.

Thanks
JLW
 
N

Nicholas Paldino [.NET/C# MVP]

JLW,

I would use the following declaration for CreateFile:

[DllImport("kernel32.dll", SetLastError=true, CharSet=CharSet.Auto)]
internal static extern IntPtr CreateFile(
String filename,
UInt32 desiredAccess,
UInt32 shareMode,
IntPtr attributes, // Really, this is the SECURITY_ATTRIBUTES pointer
UInt32 creationDisposition,
UInt32 flagsAndAttributes,
IntPtr templateFile);

I have a feeling that the conversion of the string is not occuring
correctly, and that is the cause of the problem.

Hope this helps.
 
J

JLW

Well, nothing seems to wanna work, so I guess I'm going to have to scrap
this project alltogether and chalk it up to "Not dooable at this time"

Thanks,
JLW
 

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