I've got a project with a pure c code and c code handled by the ObjC compiler [.m file]. The one handled by ObjC compiler has a following class:
unsigned long getMessage(char ** message) {
*message = (char*)calloc(1, [dMessage bytes], [dMessage length]);
memcpy(message, [dMessage bytes], [dMessage length])
return [dMessage length];
}
dMessage is an NSData object filled with text.
On C side, I do:
char* msg = NULL
unsigned long length = getMessage(&msg)
After the call, msg is empty, but the length variable is set to correct size.
What should I do to pass char* between objc and c?
Thank you
getMessagereally doing? The data is already allocated in theNSDataobject so just keep it around and access the raw bytes via[dMessage bytes].