Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include SetLastError = true into all winapi functions #43

Closed
akastalker opened this issue Jul 19, 2014 · 4 comments
Closed

Include SetLastError = true into all winapi functions #43

akastalker opened this issue Jul 19, 2014 · 4 comments
Assignees
Milestone

Comments

@akastalker
Copy link

If every imported function (that potentially can fail) in SharpGL.Win32 namespace will be changed from:

        [DllImport(OpenGL32)]
        public static extern IntPtr wglCreateContext(IntPtr hdc);

to:

        [DllImport(OpenGL32, SetLastError = true)]
        public static extern IntPtr wglCreateContext(IntPtr hdc);

, user can actually get what was wrong with the his call, if it fails, just by calling System.Runtime.InteropServices.Marshal.GetLastWin32Error() or better - by creating and\or throwing System.ComponentModel.Win32Exception().

Without SetLastError, trying to call GetLastWin32Error() after obviously failed winapi call (it returned zero) returns error code 0 ("The operation completed successfully"), as if no error occured.

See remarks section on: http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.getlastwin32error%28v=vs.100%29.aspx

@dwmkerr
Copy link
Owner

dwmkerr commented Jul 21, 2014

Hi @akastalker that sounds like good advice, let me pencil this in for the next release and look over the documentation and any impact it will have in other areas - thanks for raising this issue!

@dwmkerr dwmkerr self-assigned this Jul 21, 2014
@dwmkerr dwmkerr added this to the SharpGL 2.4 milestone Jul 21, 2014
@robinsedlaczek
Copy link
Contributor

Hi @dwmkerr! I implemented the SetLastError for all dll imports in the core project. All samples are working fine. I will do some performance tests now with the performance test suite. If I get it running... :) Please find my changes in the pull request for branch Issue43-SetLastError.

@robinsedlaczek
Copy link
Contributor

Hi @dwmkerr! I cannot really say something about the performance this time. I tried to execute the test suite. I run it with the nunit test runner gui. But there is only one test and I don't know, if this test make sense. What is the approach for performance testing and how does the test project fits into? The test project is not open source?

Thanks in advance for info!

@dwmkerr
Copy link
Owner

dwmkerr commented Jan 20, 2015

Work completed. Will be released as part of 2.4

@dwmkerr dwmkerr closed this as completed Jan 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants