First and foremost, I'm a C# developer working on a project that was thrust on me and I'm feeling very outside of my comfort zone.
That being said, I'm currently attempting to pass 2 callback functions to a C
library. I have the functions defined as free functions in my C++
console application.
When I run the application I'm receiving the following extremely unhelpful error at the point that I attempt to pass the functions to the library.
Exception thrown at 0x0000000000000000 in YourApp.exe: 0xC0000005: Access violation executing location 0x0000000000000000
The callbacks are defined in the header file for the accompanying C
source file which I have listed below. Note, I did not write the following header.
header.h
typedef void( __stdcall * Callback1 )( void *, int, unsigned int, int, int, int, int );
typedef void( __stdcall * Callback2 )( void *, int, int, unsigned int, unsigned int );
__declspec(dllimport) int open( Callback1 cb1, Callback2 cb2 );
From my C++
console application I first include
the C
header.
extern "C"
{
#include "header.h"
}
I then declare the 2 free functions I'm attempting to pass as parameters to the open
function exposed through the header.h
file.
void __stdcall callback1(
void *data,
int count,
unsigned int colorId,
int flag,
int pageNumber,
int width,
int height )
{
if ( count <= 0 ) return;
std::cout << "callback1" << std::endl;
}
void __stdcall callback2(
void *data,
int count,
int offset,
unsigned int colorId,
unsigned int side )
{
if ( count <= 0 ) return;
std::cout << "callback2" << std::endl;
}
Within main I then attempt to pass the above functions as parameters to the open
function.
int main( int argc, char *argv[ ], char *envp[ ] )
{
// This is the line where the error is thrown.
open( callback1, callback2 );
}
I'm currently using VS2015. I'm unsure how to proceed as I find that error extremely unhelpful.
I'm currently doing everything in the code file that main
is defined in. So the functions I have posted above are not methods of a class.
User contributions licensed under CC BY-SA 3.0