0

これは些細な質問だと思いますが、これを機能させることはできません!

.lib 内の関数ポインターを介して関数呼び出しを行い、.lib を、ライブラリーの外で関数ポインターを設定するアプリケーション プログラムにアタッチしました。以下はコードスニペットです

ライブラリ:

void (*PopulateBuffer)(byte *NALBuffer,unsigned int *readbytes); // The Declaration

PopulateBuffer(NALBuffer,&readbytes); // The function Call

応用 :

extern void (*PopulateBuffer)(char *NALBuffer,unsigned int *readbytes);


void UpdateNALBuff(char *Buffer,unsigned int *readbytes)

{

    //Buffer content is updated
    //readbytes is updated

}

main()

{

    PopulateBuffer= &UpdateNALBuff;

        LibMain(); // this is the main call in which the function pointer is called
}

私はこれを正しくやっていますか?ライブラリで関数呼び出しが近づくと、次のエラーがスローされます。

DecoderTestApp.exe の 0x00536e88 で未処理の例外: 0xC0000005: アクセス違反の読み取り場所 0x7ffef045。

4

3 に答える 3

0

とった!:)

問題は、同じファイルのプロトタイプを提供せずに、別のファイルで関数ポインタを呼び出していたことです。

したがって、「戻り型」をINTとして取り、関数が戻り型voidであるため、エラーがスローされていました。..それはばかげた間違いでした!みんな、ありがとう!:)

于 2012-08-14T13:15:10.820 に答える
0

It seems ok, however I suspect the buffer that you read into is too small and that is why you are getting access violation.

void UpdateNALBuff(char *Buffer,unsigned int *readbytes)
{
   //put values in Buffer but no more than *readbytes passed in,
   //finally update *readbytes with actual number of bytes read.
}
于 2012-08-14T11:23:23.627 に答える
0

通常、関数ポインタを処理するには、次の方法で行います。

typedef void (*PopulateBuffer)(byte *NALBuffer,unsigned int *readbytes); //This should be exposed from the library

関数ポインタを格納するためにライブラリ内にポインタ変数を作成します

PopulateBuffer PpBuffFunc = NULL;

ライブラリから関数を提供して関数を設定する

void setPopulateBufferFuncPointer(PopulateBuffer func)
{
    PpBuffFunc = func;
}

アプリケーションからこの関数を呼び出します

setPopulateBufferFuncPointer(UpdateNALBuff);

PpBuffFuncライブラリ内の適切な場所で、適切なパラメータを渡して を呼び出します

于 2012-08-14T11:41:17.823 に答える