Solved

Problem... please help.

Posted on 2000-03-08
5
165 Views
Last Modified: 2010-04-15
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
Comment
Question by:Nitro187
  • 3
5 Comments
 
LVL 16

Expert Comment

by:imladris
Comment Utility
The declaration looks fine. How are you using it?
0
 

Accepted Solution

by:
hernani earned 77 total points
Comment Utility
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
 

Author Comment

by:Nitro187
Comment Utility
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
 

Author Comment

by:Nitro187
Comment Utility
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
 

Author Comment

by:Nitro187
Comment Utility
Oops.. didnt see your answer.

Thanks man
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now