We help IT Professionals succeed at work.
Get Started

NativeOverlapped* lpOverlapped = null?

riceman0
riceman0 asked
on
1,745 Views
Last Modified: 2012-06-27
Hello experts:

How would one set the Argument 5 of the function below to be NULL?  The MSDN reference says that if we are not doing an asynchronous write then it needs to be set to NULL.

I have tried 0, null and IntPtr.Zero unsuccessfully.   My attempts to create a fake NativeOverlapped* struct led me down a path where I had to declare unsafe and isolate the WriteFile from any access to necessary buffers and parameters.

The write file call:
success = FileIO.WriteFile
            (pWriteHandle,
             pBuffer,    
             ibytesToWrite,
             pbytesWritten,
             IntPtr.Zero);   <- error CS1503: Argument '5': cannot convert from 'System.IntPtr' to 'System.Threading.NativeOverlapped*'


Pinvoke method

[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Ansi)]
internal static extern unsafe int WriteFile(IntPtr handle, IntPtr buffer, int numBytesToWrite, IntPtr numBytesWritten, NativeOverlapped* lpOverlapped);

I made sure the Write Handle is not flagging the OVERLAPPED argument.

IntPtr pWriteHandle = FileIO.CreateFile
                       (myDevInfo.myDevicePathName,
                       (FileIO.GENERIC_WRITE),
                       FileIO.FILE_SHARE_WRITE,
                       IntPtr.Zero,
                       FileIO.OPEN_EXISTING,
                       FileIO.FILE_ATTRIBUTE_NORMAL,
                       IntPtr.Zero);


Thanks in advance for any insight.
Comment
Watch Question
Serves the Most High - Not Religion
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE