views:

327

answers:

4

Hello,

I have a little problem with the WOsclib. Not particularly with the library, it's more the callback function. The listen to specific osc commands i have to put up some callback method like

void TheOscStartMethod::Method(
                          const WOscMessage *message,
                          const WOscTimeTag& when,
                          const TheNetReturnAddress* networkReturnAddress)
{
    std::cout << "Got the start signal";
    start.alpha = 1.0;
}

start is IBOutlet UIImageView.

But the compiler says me, that start is out of scope. If I try to access start in obj-c code, it works like it should.

How can i get my Objective C Objects into the c code or at least call a objective-c function.

Thank you

+1  A: 

Make the file an objective C++ file with extension .mm Then you can call object C and C++ objects in the same code.

XCode will call the correct compiler from the file extension (ie adding -x objective-c++ to the compile command)

Not that C++ and objective C are different languages and do not understand each others objects so to move data between them you will need to convert the data to a C type e.g. void, char int and pointers to them.

Mark
Hum, i already did that, not the file extension, but in the info panel. It looks like this right now: http://grab.by/28Ld
Philip
Ah then I supect this is not the issue. we need to see the header for the class of start?
Mark
Like i said, `start` is an UIViewImage.maybe i should choose a better example. `start` could be a method or so. `[self methodName]` doesn't work either.
Philip
Ok it says start is out of scope - where is start declared?
Mark
`Start` is declared in the header as ´IBOutlet UIButton* start;`As far as I know, c++ code gets his scope outside the objective c container objects. Even if I write it in the specific object.
Philip
Yes but as part of what object? You need to provide more code
Mark
Ok, i deletet some code that isn't needed in that context. Here is it: http://paste-it.net/public/if51774/
Philip
Beteer to paste in question so I an create a new reply - but how is start passed into the function also TheOscStartMethod::Method is that meant to be part of a C++ object. You cannot have a function in both a C++ class and a objective C class
Mark
Thank you for your, help, I got it working now :)
Philip
+1  A: 

It sounds like start is an instance variable belonging to some Objective-C object and you're trying to access it just by writing its name from a C++ object. If this is the case, it should be pretty obvious why it won't work: The C++ object doesn't know anything about start. The solution is to somehow give the C++ object a reference to the Objective-C object that owns start.

Chuck
WOuld be great to know how this somehow works :)
Philip
My explanation was as specific as possible. There is no general answer to how you do it. You have to structure your program so that your code knows about the data it needs. What this program structure specifically looks like depends on the specifics of the program, which we don't have here.
Chuck
Uff, now i'm feeling like digging into something I have absolutely no knowledge of. But let's try. I have a normal AppDelegate which handels some Buttons and Labels. That works fine for me. The hard part is the OSC Library i'm using. That one is written in C++, but platform independent. I implemented it and it works. I can send an receive osc signals via network. Now, if i get a osc signal, a specific method is called, a c++ method. Thats were my problem starts. I want to use that method to change the interface. Don't know if that helps to specify my case? Thank you anyway :)
Philip
Thank you for your help, i got it working :)
Philip
A: 

You'll have to make the start object available to your other code.

You can pass it, you can pass the portions you'll be using, you can create an API for the two code bases to use. There are other options as well, all depending on precisely how you wish to use the various objects

Liz Albin
A: 

The Solution:

I don't know if this is the best way to do it, but it works.

There must be an empty c object, which later will become our objective c object that holds all the stuff we want to access.

static gsSearchForIp* delegate = NULL;

We must define a function to set the objective c object

void setCallbackDelegate(gsSearchForIp* del)
{
    delegate = del;
}

And then call it. ( I called it in the initWithFrame method)

setCallbackDelegate(self);

Now i can call a method with [delegate methodName:firstPara] in my c++ method. In this function i have access to all my stuff that I need from the gsSearchForIp class.

Philip