FILE* type in C#

I have a c api that I have to integrate. It is not COM. It is just plain c that was compiled into a dll. I have been able to wrap all functions except this one

FILE** OpenFileWrite (CHAR*);

I need to be able to create a dllimport similar to this

[DllImport(DllPath,EntryPoint=ApiNameMappings.OpenFileWrite)]

public static extern OpenFile(string FileName);

Any and all suggestions will be appreciated



Answer this question

FILE* type in C#

  • AlexBB

    Here is your answer, you have to use an IntPtr. Here is the sig-declaration and the OFSTRCUT.
    But what are you trying todo

    Method signature:

    [DllImport("kernel32.dll")]
    static extern IntPtr OpenFile(string lpFileName, out OFSTRUCT lpReOpenBuff,
    uint uStyle);



    OFSTRCUT:

    [System.Runtime.InteropServices.StructLayout(LayoutKind.Sequential)]
    public struct OFSTRUCT
    {
    public byte cBytes;
    public byte fFixedDisc;
    public UInt16 nErrCode;
    public UInt16 Reserved1;
    public UInt16 Reserved2;
    [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst = 128)]
    public string szPathName;
    }




  • FILE* type in C#