Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

Problem... please help.

I have a function that looks like this:

void* func(void*,int);

I want to be able to create a pointer to the function, and call the pointer
instead of the function itself.  I tried declaring a pointer using this:

void* (*funcptr)(void*,int);

But everytime I run the program it crashes, and Windows brings up a message saying the function was prototyped incorrectly.  Any suggestions?
0
Nitro187
Asked:
Nitro187
  • 3
1 Solution
 
imladrisCommented:
The declaration looks fine. How are you using it?
0
 
hernaniCommented:
Try to use a type definition, it simplifies the code and makes things much simpler:

typedef void* (*My_Func) (void *,int);

void* pointed_func(void *,int);

void main(void) {
  My_Func func_p = *pointed_func;
  int a = 1;
  char *test = NULL;
  char *out;

  out = (void *) (*func_p)(test,a);
 
}

void* pointed_func(void *a,int b) {
....
}
0
 
Nitro187Author Commented:
The function is the DSP emulator:

void* EmuDSPX(void *Buffer, int Samples);

Buffer is the location to store the output and Samples is the number of samples to create.  The pointer returned points to the end of the buffer so the emlulator can be repeatedly called until a buffer is full.

I'm creating a pointer called DSPFunc, setting it like so:

DSPFunc=&EmuDSPX;

And calling it like this:

Buf=DSPFunc(Buf,NumSmp);

It's being called and successfully returning.  That's when Windows comes up and says something to the effect of, "the value in ESP does not match the expected return value... Make sure the function definition matches..."

The function works fine if I call it directly, but I want to create a pointer because I have two emulation routines, one that uses MMX and one that doesn't.  A pointer would be an easy way to switch between the two.

Any ideas?
0
 
Nitro187Author Commented:
The function is the DSP emulator:

void* EmuDSPX(void *Buffer, int Samples);

Buffer is the location to store the output and Samples is the number of samples to create.  The pointer returned points to the end of the buffer so the emlulator can be repeatedly called until a buffer is full.

I'm creating a pointer called DSPFunc, setting it like so:

DSPFunc=&EmuDSPX;

And calling it like this:

Buf=DSPFunc(Buf,NumSmp);

It's being called and successfully returning.  That's when Windows comes up and says something to the effect of, "the value in ESP does not match the expected return value... Make sure the function definition matches..."

The function works fine if I call it directly, but I want to create a pointer because I have two emulation routines, one that uses MMX and one that doesn't.  A pointer would be an easy way to switch between the two.

Any ideas?
0
 
Nitro187Author Commented:
Oops.. didnt see your answer.

Thanks man
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now