Solved

Problem... please help.

Posted on 2000-03-08
5
171 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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
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 opening and writing to files in the C programming language.

615 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