Hi Everyone,
I was hoping one of you kind souls could help me with the following:
I have a class method which initializes audio libraries written in C, shown below... where it says (RIGHT HERE) I am trying to create a pointer to the class MiniHost, am I doing it right?
>>>>>
void MiniHost::setupAudio()
{
////Some unimportant stuff here, then:
Pa_OpenStream(
&stream,
NULL,
&outputParameters,// ignore all this stuff
kSampleRate,
kBlockSize,
NULL,
patestCallback,
this); /////////// <- RIGHT HERE
Pa_StartStream( stream );
}
>>>>>
Here is the second part, a static method from which I am trying to call the class listed above:
>>>>>>>>>
static int patestCallback( const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void *userData ) //I can't change this stuff, the libraries need it this way
{
userData->someFunction(); //dosen't work
return paContinue;
}
>>>>>>>>>
What I need to do in the above code, is to call MiniHost through the 'userData' parameter, into which I tried to pass a pointer to the class.
Assuming I passed the pointer correctly, how do I call the class?
Thanks a lot!
Crispin
4 1957 - static int patestCallback( const void *inputBuffer, void *outputBuffer,
-
unsigned long framesPerBuffer,
-
const PaStreamCallbackTimeInfo* timeInfo,
-
PaStreamCallbackFlags statusFlags,
-
void *userData ) //I can't change this stuff, the libraries need it this way
-
{
-
-
userData->someFunction(); //dosen't work
-
-
return paContinue;
-
}
What I need to do in the above code, is to call MiniHost through the 'userData' parameter, into which I tried to pass a pointer to the class.
Assuming I passed the pointer correctly, how do I call the class?
Thanks a lot!
Crispin
I'm not sure the header syntax is correct - userData is defined as a void*, or a pointer to nothing. Maybe you can cast userData to a MiniHost*, and then try ->someFunction(), as in: - static int patestCallback( const void *inputBuffer, void *outputBuffer,
-
unsigned long framesPerBuffer,
-
const PaStreamCallbackTimeInfo* timeInfo,
-
PaStreamCallbackFlags statusFlags,
-
void *userData ) //I can't change this stuff, the libraries need it this way
-
{
-
userData = (MiniHost*)userData;
-
userData->someFunction(); //dosen't work
-
-
return paContinue;
-
}
Hi. A void pointer needs to be recast - ((MiniHost*)userData)->someFunction(); //should work
Hi,
Thanks for your help... I got it working!
I passed the class as 'this'. And added 'MiniHost *m = (MiniHost*)userData;' in the static int. To use the methods I simply type m->whatever();
Cheers,
Crispin
Hi,
Thanks for your help... I got it working!
I passed the class as 'this'. And added 'MiniHost *m = (MiniHost*)userData;' in the static int. To use the methods I simply type m->whatever();
Cheers,
Crispin
Be careful. At this point you have 2 pointers pointing to the same class. An unnecessary risk
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Andy Read |
last post by:
Dear all,
I thought I understood passing parameters ByVal and ByRef but I
clearly don't! If I define a simple class
of:
Public Class Person
Public Name as String
Public Age as Integer
End...
|
by: Andy |
last post by:
Hi
Could someone clarify for me the method parameter passing
concept?
As I understand it, if you pass a variable without
the "ref" syntax then it gets passed as a copy.
If you pass a...
|
by: jr |
last post by:
Sorry for this very dumb question, but I've clearly got a long way to go!
Can someone please help me pass an array into a function. Here's a starting
point.
void TheMainFunc()
{
// Body of...
|
by: justanotherguy63 |
last post by:
Hi,
I am designing an application where to preserve the hierachy and for
code substitability, I need to pass an array of derived class object in
place of an array of base class object. Since I...
|
by: keepyourstupidspam |
last post by:
Hi,
I want to pass a function pointer that is a class member.
This is the fn I want to pass the function pointer into:
int Scheduler::Add(const unsigned long timeout, void* pFunction, void*...
|
by: zholthran |
last post by:
Hi folks,
after reading several threads on this issue (-> subject) I fear that I
got a problem that cannot easily be solved by the offered workarounds
in an acceptable way, at least not with my...
|
by: Haxan |
last post by:
Hi,
I have an unmanaged application that converts a function pointer to a
delegate and then pass this as a parameter(delegate) to a managed function
which then invokes it. Currently Im able to...
|
by: dice |
last post by:
Hi,
In order to use an external api call that requires a function pointer I
am currently creating static wrappers to call my objects functions.
I want to re-jig this so I only need 1 static...
|
by: TS |
last post by:
I was under the assumption that if you pass an object as a param to a method
and inside that method this object is changed, the object will stay changed
when returned from the method because the...
|
by: autumn |
last post by:
Hi everybody,
I'm having problem passing pointer to member object as template argument, seems VC 2005 does not allow 'pointer to base member' to 'pointer to derived member' conversion in template...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |