I have a C routine that wants to call a method of its user.
In this case the method is a method inside a class.
The C routine is passed a void * which can be used by the user any way
they like.
I use that parameter and pass the actual instance of the C++ class
that performed the call.
The C callback handler then uses the instance of the class and calls
the appropriate method.
Here is the code but it doesn't work. What am I doing wrong? -
void DeviceFoundCallBack(void * userRefCon,
-
IOBluetoothDeviceInquiryRef inquiryRef, IOBluetoothDeviceRef
-
deviceRef)
-
{
-
userRefCon->DeviceFoundCallBack(inquiryRef, deviceRef);
-
}
-
-
void CompleteCallback(void * userRefCon, IOBluetoothDeviceInquiryRef
-
inquiryRef, IOBluetoothDeviceRef deviceRef)
-
{
-
userRefCon->CompleteCallBack(inquiryRef, deviceRef);
-
}
-
-
void BlueTooth::startSearch(void)
-
{
-
_inquiry =
-
IOBluetoothDeviceInquiryCreateWithCallbackRefCon(this); // This will
-
be passed back to us to let us know the instance.
-
IOBluetoothDeviceInquirySetDeviceFoundCallback(_inquiry,
-
&DeviceFoundCallBack);
-
}
-
3 2048
SpreadTooThin wrote:
I have a C routine that wants to call a method of its user.
In this case the method is a method inside a class.
The C routine is passed a void * which can be used by the user any way
they like.
I use that parameter and pass the actual instance of the C++ class
that performed the call.
The C callback handler then uses the instance of the class and calls
the appropriate method.
Here is the code but it doesn't work. What am I doing wrong?
-
void DeviceFoundCallBack(void * userRefCon,
-
IOBluetoothDeviceInquiryRef inquiryRef, IOBluetoothDeviceRef
-
deviceRef)
-
{
-
userRefCon->DeviceFoundCallBack(inquiryRef, deviceRef);
-
-
'userRefCon' has to be of a class type or pointer to a class to use
-
the -syntax. You have a void*, which is not a class. You need to
-
convert your 'void*' into a pointer to the class:
-
-
someclasstype* pObj = static_cast<someclasstype*>(userRefCon);
-
-
only then you will be alble to call your member function.
-
-
-
}
-
void CompleteCallback(void * userRefCon, IOBluetoothDeviceInquiryRef
-
inquiryRef, IOBluetoothDeviceRef deviceRef)
-
{
-
userRefCon->CompleteCallBack(inquiryRef, deviceRef);
-
}
-
void BlueTooth::startSearch(void)
-
{
-
_inquiry =
-
IOBluetoothDeviceInquiryCreateWithCallbackRefCon(this); // This will
-
be passed back to us to let us know the instance.
-
IOBluetoothDeviceInquirySetDeviceFoundCallback(_inquiry,
-
&DeviceFoundCallBack);
-
-
-
You may have problems with the second argument here. See the FAQ about
-
the callbacks and member functions.
-
-
-
}
-
-
-
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
SpreadTooThin <bj********@gmail.comwrote in
news:11*********************@x40g2000prg.googlegro ups.com:
I have a C routine that wants to call a method of its user.
Uh.. then it's not really a C routine is it? C routines would have no
concept of "method"s. (It may be a C++ routine with C linkage....)
In this case the method is a method inside a class.
The C routine is passed a void * which can be used by the user any way
they like.
I use that parameter and pass the actual instance of the C++ class
that performed the call.
The C callback handler then uses the instance of the class and calls
the appropriate method.
Here is the code but it doesn't work. What am I doing wrong?
-
void DeviceFoundCallBack(void * userRefCon,
-
IOBluetoothDeviceInquiryRef inquiryRef, IOBluetoothDeviceRef
-
deviceRef)
-
{
-
userRefCon->DeviceFoundCallBack(inquiryRef, deviceRef);
-
}
-
-
userRefCon is a void*. voids don't have methods. You need to cast that
-
pointer back to the appropriate type first.
-
-
-
>
-
void CompleteCallback(void * userRefCon, IOBluetoothDeviceInquiryRef
-
inquiryRef, IOBluetoothDeviceRef deviceRef)
-
{
-
userRefCon->CompleteCallBack(inquiryRef, deviceRef);
-
}
-
-
-
Same as above.
-
-
-
void BlueTooth::startSearch(void)
-
{
-
_inquiry =
-
IOBluetoothDeviceInquiryCreateWithCallbackRefCon(this); // This will
-
be passed back to us to let us know the instance.
-
IOBluetoothDeviceInquirySetDeviceFoundCallback(_inquiry,
-
&DeviceFoundCallBack);
-
}
-
-
-
SpreadTooThin wrote:
I have a C routine that wants to call a method of its user.
In this case the method is a method inside a class.
The C routine is passed a void * which can be used by the user any way
they like.
I use that parameter and pass the actual instance of the C++ class
that performed the call.
The C callback handler then uses the instance of the class and calls
the appropriate method.
Here is the code but it doesn't work. What am I doing wrong?
-
void DeviceFoundCallBack(void * userRefCon,
-
IOBluetoothDeviceInquiryRef inquiryRef, IOBluetoothDeviceRef
-
deviceRef)
-
{
-
userRefCon->DeviceFoundCallBack(inquiryRef, deviceRef);
-
-
userRefCon is a void* and does not have a member called
-
DeviceFoundCallBack.
-
You must use a cast in this situation to tell the compiler what type of
-
object userRefCon actually points to.
-
-
static_cast<BlueTotth>(userRefCon)->DeviceFoundCallBack(inquiryRef,
-
deviceRef);
-
-
-
}
-
void CompleteCallback(void * userRefCon, IOBluetoothDeviceInquiryRef
-
inquiryRef, IOBluetoothDeviceRef deviceRef)
-
{
-
userRefCon->CompleteCallBack(inquiryRef, deviceRef);
-
-
-
Same problem here.
-
-
-
}
-
void BlueTooth::startSearch(void)
-
{
-
_inquiry =
-
IOBluetoothDeviceInquiryCreateWithCallbackRefCon(this); // This will
-
be passed back to us to let us know the instance.
-
IOBluetoothDeviceInquirySetDeviceFoundCallback(_inquiry,
-
&DeviceFoundCallBack);
-
}
-
-
-
Bart v Ingen Schenau
--
a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq
c.l.c FAQ: http://www.eskimo.com/~scs/C-faq/top.html
c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: lawrence |
last post by:
I've been bad about documentation so far but I'm going to try to be
better. I've mostly worked alone so I'm the only one, so far, who's
suffered from my bad habits. But I'd like other programmers...
|
by: Brian |
last post by:
Hi all,
I am implementing an object that is currently using function pointers
for callbacks to let me do something on assignment:
template <class T>
class MyClass{
private:
typedef T& (*...
|
by: He Shiming |
last post by:
Hi,
I've developed a class that implements an interface definition. It looks
like this:
class IRecord {
public:
// define interface methods by pure virtual methods
// no member variables
}
|
by: Ken |
last post by:
I am familiar with C and Java, I would like to use a style that I have
become accustomed to in Java with C++ but each time I do this I have
name conflict. In the past I have just worked around it...
|
by: John Rivers |
last post by:
hi, here is how to do it and restore sanity to aspx html rendering:
(please only reply with sensible architectural discussion - juan)
put this at the end of an aspx file (or use an include at...
|
by: Jarod_24 |
last post by:
What is the point with Delegates in VB.Net
What can these things do that we can not allready do with the use of Interfaces, Events and Event handlers and so on...
I'd like a discussion on this,...
|
by: noone |
last post by:
consider the following problem:
You have a C style library and API that uses callbacks to implement
functionality. Examples of this are X11 API, OpenGL/GLUT...The List goes
on.
The power of...
|
by: John Bode |
last post by:
I need a way to fake reflection in C++ code that makes as few
assumptions about the data types involved as possible. I suspect
there is no good answer for what I need to do, but I'll present the...
|
by: Dahak |
last post by:
I'm trying to generate dynamic functions to use as separate
callbacks for an AJAX API call.
The API doesn't seem to allow for the inclusion of any parameters
in the callback, so I can't...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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:
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |