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 944365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:34:50+00:00 2026-05-15T22:34:50+00:00

In my solution I’ve written the following: [DllImport(kernel32.dll, SetLastError = true, CharSet = CharSet.Auto)]

  • 0

In my solution I’ve written the following:

[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern unsafe bool CopyFileEx(string lpExistingFileName,  
 string lpNewFileName, CopyProgressRoutine lpProgressRoutine, IntPtr lpData,  
 Boolean* pbCancel,    CopyFileFlags dwCopyFlags);

...

bool result;

unsafe{
  result = CopyFileEx(sourceFile, targetFile, null, IntPtr.Zero,  
                      null /* pointer */, 0);
}

if(!result)
    Win32Exception exc = new Win32Exception(Marshal.GetLastWin32Error()); 
// parameter could be omitted according to Win32Exception constructor 
// implementation

In the assumption that CopyFileEx was exported with SetLastError = true parameter of DllImport attribute, do I have a chance to get any unhalted exception here?

I’m specifically interested in non-CLR exceptions which are wrapped in RuntimeWrappedException instance. In C++ “throw 1” is a valid construct. So what exceptions should I expect from such P/Invoke calls and where I can obtain such information regarding exceptions (MSDN says nothing regarding exceptions from CopyFileEx)?

  • 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-15T22:34:51+00:00Added an answer on May 15, 2026 at 10:34 pm

    If a DLL uses the Win32 structured exception handling system, then any exceptions thrown by the DLL will be translated to OutOfMemoryException, AccessViolationException, NullReferenceException (rarely), or SEHException.

    RuntimeWrappedException is only used when managed C++ throws a non-Exception-derived object. It is not used for unmanaged DLLs. If you had a managed C++ DLL that did a throw 1, then you could catch RuntimeWrappedException.

    SEHException acts as a catch-all for the unmappable types of SEH exceptions from unmanaged DLLs. This would include any C++ class, or the throw 1 example. AFAIK, there is no way to pull the C++-specific exception info out of SEHException, though I’m sure it’s hackable if you try hard enough.

    Note that there are a few DLLs that do not use the Win32 structured exception handling system. Most notably Cygwin DLLs. In that case, any C++ exception is likely to crash the process or at least your thread. Naturally, all the Windows DLLs (including the one defining CopyFileEx) do use Win32 structured exception handling, as do any unmanaged DLLs created by Microsoft’s C++ compiler.

    Also note that the Win32 API (including CopyFileEx) does not normally report errors using Win32 structured exceptions; they report them via GetLastError. The only way to get most Win32 functions to throw a Win32 structured exception is to pass it wildly invalid arguments (such as asking it to write into the middle of ntdll.dll).

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

Sidebar

Related Questions

[Solution at the bottom] I need a tab to have the following behaveyour but
Chosen Solution Thanks for the help everyone. I've decided to do the following. public
SOLUTION The solution was to add the following to the top of production.rb: $:.unshift(File.expand_path('./lib',
Solution -- WorkflowProject   -- Workflow1   -- Workflow2 -- WebProject (WAP)   -- App_Data     -- MyDatabase.vdb3
Solution: I've misinterpreted the example from SQL Books Online. Yes, that below the section
Solution to original problem (below) may have been discovered. I commented out <identity> ...
Solution for writing a program for keep secret photos. I have many secret photos
Solution: if you have the same problem, addElement() instead of addChild() is what did
Solution: strpos turned out to be the most efficient. Can be done with substr
Solution is called Portal which holds Areas/CMS/Login folder inside it. Login controller in CMS/Controllers

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.