Solved

Problem... please help.

Posted on 2000-03-08
5
166 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
ID: 2597990
The declaration looks fine. How are you using it?
0
 

Accepted Solution

by:
hernani earned 77 total points
ID: 2598298
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
ID: 2598363
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
ID: 2598571
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
ID: 2598577
Oops.. didnt see your answer.

Thanks man
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

896 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

18 Experts available now in Live!

Get 1:1 Help Now