Posts

Showing posts with the label dllimport

DllImport causing access violation exception

DllImport causing access violation exception The C dll header is this: HRESULT App_Process(char *FileName, char *Output, const bool& LogInformation); My C# DllImport looks like this: [DllImport("App.dll")] public static extern Int32 App_Process( [MarshalAs(UnmanagedType.LPStr)]string FileName, [MarshalAs(UnmanagedType.LPStr)]string Output, [MarshalAs(UnmanagedType.Bool)]bool LogInformation); The exception is: var result = App_Process("MyFile.txt", "Output.txt", true); System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Now the strange this is that the method is successfully doing everything its supposed to do. Any ideas? Perhaps last parameter should be a ref bool ? – Daisy Shipton Jun 28 at 10:44 ref bool ...