ta odpowiada na pytanie i warto nagrodę
rozwiązaniem jest import NSUserName w C++ przy użyciu dlopen i 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);
}
Jest możliwe użycie NSString (Rodzaj kakao) bezpośrednio w C++ Builder, dodając plik nagłówkowy jako:
#include <Macapi.Foundation.hpp> // note that this will cause 8080 warnings if you have this warning turned on (unused variables)
Teraz mogę użyć NSString zamiast CFStringRef (Core Foundation Type):
UserName = TNSString::Wrap(NSUserName())->UTF8String();