dimanche 13 décembre 2015

randomly Access violation in unmanaged DLL

in native DLL, I have:

ReturnMode Decoder::Decode(int16 samples[], int num_samples, char** hypothesis){

char *hypstr = NULL;

try
{
        // some other...

        if (s3_decode(&decoder, NULL, &hypstr, NULL) == 0)
        {

            *hypothesis = (char*)CoTaskMemAlloc(strlen(hypstr) + 1);
            strcpy(*hypothesis, hypstr);
        }


        if (hypstr != NULL)
        {
            free(hypstr);
            hypstr = NULL;

        }

}
catch (...)
{
    return FatalError;
}


return Ok;}

that call in C#:

string Hypothesis = string.Empty;
Result = DecoderWrap.Decode(mDecoder, samples, num_samples, out Hypothesis);

and imported this way:

        [DllImport("ShenavaDec.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
    static public extern ShProxy.ReturnMode Decode(IntPtr pDec, short[] samples, int num_samples, out string Hypothesis);

randomly AV occurred when called s3_decode API. now i want to know where is my mistake? is it related to marshaling data or no. thanks.




Aucun commentaire:

Enregistrer un commentaire