File open mode malfunction between C # and C ++

I am exporting a function from a vC ++ DLL to write to a binary. In C ++ code, a file is opened using

FILE* fp = ::_tfopen (FilePath, _T("a+b"));

I use mode "a+b"to add a file later, and b for binary mode.

Now I am importing this function into my C # application. When I make a call to this function from C # with the correct arguments, the file is written, but not in add mode. I mean, the function opens the file, but doesn’t seem to add its contents, instead it destroys its contents and then writes all my C # arguments.

Platform - VS2005. Any help please?

- thanks to Viren

Imported from comments

[DllImport("NameOfTheDLL.dll", CharSet = CharSet.Ansi)] 
public static extern int function_name(IntPtr ptr, 
   [MarshalAs(UnmanagedType.LPWStr)] string FilePath); 

The following is a function call:

IntPtr ptr = some_Init_function(); 
function_name(handle, "C:\\FileName"); 
+3
source share
2

#?

FileStream s2 = new FileStream(name, FileMode.Open, FileAccess.Read, FileShare.Read);
+2

++ , #? DLL.

0

Source: https://habr.com/ru/post/1714309/


All Articles