© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
7 replies
kianyuen

How should Error Status Code returned from a DLLImport function be handled?

        //Output:    None
        //return:    0 - success, <0 - failure(refer to error code definition)
        //Note:        None
        [DllImport("./libraries/something.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int OpenDevice(int nPort, int nBaud);
        //Output:    None
        //return:    0 - success, <0 - failure(refer to error code definition)
        //Note:        None
        [DllImport("./libraries/something.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int OpenDevice(int nPort, int nBaud);

I am thinking defining a different function that wrap it and throw exception.
Or should I just use the function as is?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ DllImport From C Library
C#CC# / help
3y ago
DllImport Troubles
C#CC# / help
4y ago
❔ How read data returned from a query?
C#CC# / help
4y ago
✅ DllImport a C-Styled array
C#CC# / help
4y ago