Solved

Problem... please help.

Posted on 2000-03-08
5
169 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

749 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