An error occurs when a DLL function is executed from C #.
Please let me know if there is an error cause or a questionable place.
Also, when does the error "Attempted to perform a read or write operation on protected memory, possibly other memory is corrupted" occur?

The following error appears in BioAPI_IdentifyMatch.

BioAPI_HANDLE ModuleHandle = 0;
BioAPI_FAR MaxFARRequested = null;
BioAPI_FRR MaxFRRRequested = null;
BioAPI_BOOL FARPrecedence = null;
BioAPI_INPUT_BIR ProcessedBIR = null;
BioAPI_BOOL Binning = null;
uint MaxNumberOfResults;
uint NumberOfResults;
BioAPI_CANDIDATE [] Candidates = null;
int Timeout = 30000
IntPtr ptrMaxFRRRequested = IntPtr.Zero;
BioAPI_INPUT_BIR_Marshal mProcessedBIR = null;
IntPtr ptrCandidates = IntPtr.Zero;
if (MaxFRRRequested>= (BioAPI_FRR) 0)
{ptrMaxFRRRequested = BioAPIWin32.MarshalInt32 ((int) MaxFRRRequested);}
if (ProcessedBIR! = null)
{mProcessedBIR = new BioAPI_INPUT_BIR_Marshal (ProcessedBIR);}
bReturn = BioAPIWin32.BioAPI_IdentifyMatch (
Ref MaxFARRequested,
    ref FARPrecedence,
        ref Population,
    ref NumberOfResults,

■ BioAPI_IdentifyMatch definition

[DllImport ("bioapi100.dll")]
public static extern BioAPI_RETURN BioAPI_IdentifyMatch (
            BioAPI_HANDLE ModuleHandle, ref BioAPI_FAR MaxFARRequested,
            IntPtr ptrMaxFRRRequested, ref BioAPI_BOOL FARPrecedence,
            BioAPI_INPUT_BIR_Marshal ProcessedBIR,
                        ref BioAPI_IDENTIFY_POPULATION Population,
                        BioAPI_BOOL Binning,
            uint MaxNumberOfResults,
            [In, Out] ref uint NumberOfResults,
            [In, Out] IntPtr ptrCandidates,
            int Timeout);

C specification

BioAPI_RETURN BioAPI BioAPI_IdentifyMatch (
BioAPI_HANDLE ModuleHandle,
const BioAPI_FAR * MaxFARRequested,
const BioAPI_FRR * MaxFRRRequested,
const BioAPI_BOOL * FARPrecedence,
const BioAPI_INPUT_BIR * ProcessedBIR,
BioAPI_BOOL Binning,
uint32 MaxNumberOfResults,
uint32 * NumberOfResults,
sint32 Timeout

[Additional questions]
Even though Population and NumberOfResults are pointers, Dllimport is ref.

  • Answer # 1


    Although Population and NumberOfResults are pointers, they are ref in Dllimport.

    Since this kind of question comes up, I think that I am using reliable method declarations instead of my own.
    So I think that the declaration is correct.
    There is no problem marshaling a pointer to a reference. I usually do so.

    The problem is ModuleHandle and
    Whether the correct value is passed to ptrMaxFRRRequested etc.
    Before calling, place a breakpoint to make sure all arguments are correct.
    I don't know if it's correct here.
    Instead of using it properly, please learn how to use the API in advance before using it.

    Is bio100 100% Bio_100%? I think it's an old one, so it seems to have a gut to use it now.
    Please consider the option of not using it in the first place.