Trying to get an image from a C++ dll in C# using DLLImport

I'm trying to get an image from a C++ DLL with DLLImport by getting a byte array but I get an AccessViolationException.

DLL Import function:

 [DllImport("DLL.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern IntPtr getDPimgPtr();


unsigned char* getDPimgPtr();


 public int imgPtr
                IntPtr result = getDPimgPtr(); 
                byte[] managedArray = new byte[imgSnippetSize];
                    Marshal.Copy(result, managedArray, 0, imgSnippetSize);
                catch (Exception ex)
                    MessageBox.Show("Error " + ex.Message);
                return BitConverter.ToInt32(managedArray, 0);

And this is how I get the byte array in the end to convert to an image:

  byte[] arr = new byte[dc.imgSnippetSize];

  Marshal.Copy((IntPtr)imgPtr, arr, 0, imgSnippetSize);

I get the exception at the Marshal.Copy((IntPtr)imgPtr, arr, 0, imgSnippetSize); line.