I am trying to call method available in C++ dll
HRESULT WINAPI TestMethod( _Out_ BOOL *isSuccess, _In_opt_ DWORD UsernmaeLength, _Out_opt_ LPWSTR userName ); Wrapper method Which I have written in C# looks like this
[DllImport("Test.dll", CharSet = CharSet.Unicode, SetLastError = true ,CallingConvention = CallingConvention.StdCall)] public static extern int TestMethod ( IntPtr isSuccess, [In, Optional] int UsernmaeLength, out string userName ); I am calling this method in program
Wrapper. TestMethod (isSuccess, 200, out userName); I am getting System.AccessViolationException
tried changing the C# wrapper method with
[DllImport("Test.dll", CharSet = CharSet.Unicode, SetLastError = true ,CallingConvention = CallingConvention.StdCall)] public static extern int TestMethod ( bool isSuccess, [In, Optional] int UsernmaeLength, out string userName ); //Caller bool isSuccess = false; Wrapper. TestMethod (isSuccess, 200, out userName); Could you please help me to understand what I am doing wrong here?
uint UsernmaeLengthout IntPtr userNamepublic static extern int TestMethod ( [Out] ref bool isSuccess, [In, Optional] uint UsernmaeLength, [Out, Optional] IntPtr userName );isSuccessis also out param