Search code examples
c#unmanagedresources

How to dispose unmanaged resource manually?


I am using some unmanaged code like-

 [DllImport("wininet.dll")]
    private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);
    //Creating a function that uses the API function...
    public static bool IsConnectedToInternet() {
        int Desc;
        return InternetGetConnectedState(out Desc, 0);
    }

Any suggestions on how I can dispose/cleanup this extern static object when I call Dispose?


Solution

  • The thing you think is an 'extern static object' is not an object at all, it's just a set of instructions to the compiler/runtime about how to find a function in a DLL.

    As Sander says, there's nothing to clean up.