This answers the question and is worth the bounty
The solution is to import NSUserName in C++ by using dlopen and dlsym:
void* (*NSUserName)();
String UserName;
void *hLib = dlopen("/System/Library/Frameworks/Foundation.framework/Foundation", RTLD_GLOBAL);
if(hLib)
{
NSUserName = (void*(*)())dlsym(hLib, "NSUserName");
CFStringRef srUserName = (CFStringRef)NSUserName();
if(srUserName)
{
UserName = CFStringGetCStringPtr(srUserName, 0);
}
dlclose(hLib);
}
It is possible to use NSString (Cocoa Type) directly in C++ Builder by adding a header file as:
#include <Macapi.Foundation.hpp> // note that this will cause 8080 warnings if you have this warning turned on (unused variables)
Now I can use NSString instead CFStringRef (Core Foundation Type):
UserName = TNSString::Wrap(NSUserName())->UTF8String();