I think this is a trivial question, but I am never able to get this to work!
I have made a function call through a function pointer inside a .lib and attached the .lib to an application program which sets the function pointer, outside the library. The following is the code snippet
Lib :
void (*PopulateBuffer)(byte *NALBuffer,unsigned int *readbytes); // The Declaration
PopulateBuffer(NALBuffer,&readbytes); // The function Call
Application :
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
}
Am I doing this right???
Cause when ever the function call approaches in the library, it throws me the following error :
Unhandled exception at 0x00536e88 in DecoderTestApp.exe: 0xC0000005: Access violation reading location 0x7ffef045.
Generally for dealing with function pointers, you do it in the following way:
Create a pointer variable inside the library for storing the function pointer
Provide a function from the library to set the function
Now call this function from your application
Inside the lib at appropriate place, call the
PpBuffFuncby passing appropriate parameters