Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3665264
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:44:25+00:00 2026-05-19T01:44:25+00:00

I am running the following scenerio: SafeFileHandle handle = Win32API.CreateFile((deviceName + \\ + pipeName),

  • 0

I am running the following scenerio:

SafeFileHandle handle = Win32API.CreateFile((deviceName + "\\" + pipeName),
                           DesiredAccess.GENERIC_WRITE | DesiredAccess.GENERIC_READ,
                           ShareMode.FILE_SHARE_WRITE | ShareMode.FILE_SHARE_READ,
                           IntPtr.Zero,
                           CreationDisposition.OPEN_EXISTING,
                           FlagsAndAttributes.FILE_ATTRIBUTE_NORMAL | FlagsAndAttributes.FILE_FLAG_OVERLAPPED,
                           IntPtr.Zero); // Marshal.GetLastWin32Error() returns 0 (success)

bool pass = Win32API.WriteFile(writeHandle, message.ToArray(), (uint)message.Count, ref bytes_written, ref over_lapped);

pass is false but to be expected since im running overlapped.
The problem is Marshal.GetLastWin32Error() doesnt return ERROR_IO_PENDING
it returns ERROR_ALREADY_EXISTS. Which is weird to me because the error didnt show that when I created the file, but when I write it shows up. Now I am trying to figure out how to close the handle that I dont seem to have access to or atleast get an explanation as to why this is happening.

EDIT: Ok, I have norrowed the problem down and I know what is causing the problem.

  private void ErrorOccurred(string detailedError)
  {
     lock (mLogLock)
     {
        try
        {
           System.IO.File.AppendAllText("Device" + mDeviceHandle + "Log.txt",
           DateTime.Now.ToLongTimeString() + ": " + detailedError + Environment.NewLine);
        }
        catch (Exception ex)
        {
           System.Windows.Forms.MessageBox.Show(ex.Message);
        }
     }
  }

Apparently, internally the AppendAllText call is creating an error. Should I reset the error after this log call? I guess this would have been helpful to know that the framework doesnt reset low level calls in the internal workings of its functions. Ahh, you learn something new every day.

I guess the new question I have is, should I reset the low level error after this call, or is there some other way to log output (not using 3rd party tools like log4Net or getting fancy with the Debug.Trace output)? Bascially someway to open a file for appending that doesnt affect the Marshal.GetLastWin32Error(); output.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:44:26+00:00Added an answer on May 19, 2026 at 1:44 am

    I’ve determined using Marshal.GetLastWin32Error for debugging is not the best way to go.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am running the following feature: Scenario: viewing existing images Given I am on
I am running following LINQ query in order to group by CategoryID var test
I am running following code to create bmp image from pdf using Ghost4j i
I am running following query. SELECT T1.C1, T2.C2..., IF( T1.C1<>T2.C1,Changed,1) AS NewColumn From T1
I am running following query.. Select T1.* from T1 LEFT JOIN T2 ON T1.C1
I am running following query in SQL*Plus CREATE TABLE tbl_audit_trail ( id NUMBER(11) NOT
I'm getting unexpected output when running following code, DateFormat df = new SimpleDateFormat(YYYY-MM-dd); Date
Assume I have one threadpool and each thread is running following method: void runMe(HashMap
Running the following line in my script gives me a Permission denied error: $config_out
Running the following program on gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 and Intel(R) Core(TM)2 Duo CPU,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.