How do I create a function in my library for passing user callback function



Hello

I am writing a library which will write data to a user defined callback
function. The function the user of my library will supply is:

int (*callbackfunction)(const char*);

In my libary do I create a function where user passes this callback
function? How would I define the function?

I tried this

callbackfunction clientfunction;

void SpecifyCallbackfunction(cbFunction cbFn)
{
clientfunction = cbFn;
}

Then called like this:
clientfunction(sz); // sz is a C-string.

But program crashes with access violation when attempt to call
clientfunction



What am I doing wrong?


.



Relevant Pages

  • Re: How do I create a function in my library for passing user callback function
    ... I am writing a library which will write data to a user defined callback ... int; ... callbackfunction clientfunction; ... void SpecifyCallbackfunction(cbFunction cbFn) ...
    (comp.lang.c)
  • Re: [patch 1/7] Immediate Values - Architecture Independent Code
    ... static unsigned int stopmachine_num_threads; ... * help our sisters onto their CPUs. ... all the other CPUs will execute the callback concurrently. ...
    (Linux-Kernel)
  • Re: Trying to use a legacy C function from DLL in managed code
    ... /* LINGO DLL definitions header ... This is usually done by passing it through the pUserData parameter (for example make a GCHandle and cast in the callback), but since .NET does runtime codegen this is unnecessary. ... int FormMain::SolverCallback ... if (dBestIP < *pdBestObjective) ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Why error?
    ... >I am trying to test the callback function between C# and C++. ... > public static int Add ... > different calling convention. ... Your callback declaration: ...
    (microsoft.public.dotnet.framework.interop)
  • Re: function pointer help!
    ... //the return void and input prameters are defined in the manual... ... void MyProjectView::CallHandler(int,unsigned int, unsigned int, void*) ... You are attempting to use a C++ member function as the callback, but the callback is defined in terms or C, not C++. ... The underlying problem is that C++ functions receive a hidden parameter, the 'this' pointer, so their signature is incompatible with C definitions. ...
    (microsoft.public.vc.mfc)