FROM : Rolf Nilsson
DATE : Thu Oct 07 15:17:48 2004
Hi,
My app has a Cocoa GUI but most of the code is C++.
My problem is how to call an Obj-C method from a C++ class.
This is what I do:
When I create my C++ object in my Cocoa method, I supply a pointer to
the Cocoa class:
@implementation MyController
- (void)someCocoaMethod
{
SomeCPPClass *p = new SomeCPPClass(self);
}
- (void) aCocoaMethodWithOneArgument:(int)theArgument;
- (void) aCocoaMethodWithTwoArguments:(int *)pAnIntPointer
anIntValue:(int) anIntValue;
@end
in my C++ class I want to be able to call either of the two methods
aCocoaMethodWithOneArgument or aCocoaMethodWithTwoArguments
class SomeCPPClass
{
public:
SomeCPPClass(MyController *pMyControllerCocoaObj) {
m_pMyControllerCocoaObj = pMyControllerCocoaObj; }
void foo();
protected:
MyController *m_pMyControllerCocoaObj;
}
// here I want to call (send a message to ) the Obj-C method
void SomeCPPClass::foo()
{
int * pAnIntPointer;
int anIntValue;
............
other code here
............
// this works for a method with one argument but there may be a better
way?
[ (id)m_pMyControllerCocoaObj
performSelector:@selector(aCocoaMethodWithOneArgument:) withObject:
(id) pAnIntPointer];
}
But, I can't find out how to call the method with two arguments?
Thanks for any help,
Rolf
DATE : Thu Oct 07 15:17:48 2004
Hi,
My app has a Cocoa GUI but most of the code is C++.
My problem is how to call an Obj-C method from a C++ class.
This is what I do:
When I create my C++ object in my Cocoa method, I supply a pointer to
the Cocoa class:
@implementation MyController
- (void)someCocoaMethod
{
SomeCPPClass *p = new SomeCPPClass(self);
}
- (void) aCocoaMethodWithOneArgument:(int)theArgument;
- (void) aCocoaMethodWithTwoArguments:(int *)pAnIntPointer
anIntValue:(int) anIntValue;
@end
in my C++ class I want to be able to call either of the two methods
aCocoaMethodWithOneArgument or aCocoaMethodWithTwoArguments
class SomeCPPClass
{
public:
SomeCPPClass(MyController *pMyControllerCocoaObj) {
m_pMyControllerCocoaObj = pMyControllerCocoaObj; }
void foo();
protected:
MyController *m_pMyControllerCocoaObj;
}
// here I want to call (send a message to ) the Obj-C method
void SomeCPPClass::foo()
{
int * pAnIntPointer;
int anIntValue;
............
other code here
............
// this works for a method with one argument but there may be a better
way?
[ (id)m_pMyControllerCocoaObj
performSelector:@selector(aCocoaMethodWithOneArgument:) withObject:
(id) pAnIntPointer];
}
But, I can't find out how to call the method with two arguments?
Thanks for any help,
Rolf
| Related mails | Author | Date |
|---|---|---|
| Rolf Nilsson | Oct 7, 15:17 | |
| Karin Kosina | Oct 7, 15:25 | |
| Roni Music | Oct 7, 16:18 |






Cocoa mail archive

