C# AccessViolationException when call c++

  access-violation, c++, dllimport

i’m trying to call a function of a c++ library. On result there is a AccessViolationException but i haven’t any other details. How can i have more details of the error? Here there is my code Thanks
This is the section where i declare the functions

[DllImport("library.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr getResult();


        public delegate Result CallbackDelegate();

This is the code where i call the methods

IntPtr ptr = getResult();
                    CallbackDelegate callback = Marshal.GetDelegateForFunctionPointer<CallbackDelegate>(ptr);
                    Result result = callback();

Source: Windows Questions C++

LEAVE A COMMENT