Dies beantwortet die Frage und ist die Prämie im Wert von
Die Lösung NSUserName in C++ unter Verwendung dlopen und dlsym zu importieren ist:
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);
}
Es ist möglich, verwenden NSString (Cocoa Type) direkt in C++ Builder durch eine Header-Datei hinzugefügt, wie:
#include <Macapi.Foundation.hpp> // note that this will cause 8080 warnings if you have this warning turned on (unused variables)
Jetzt kann ich NSString anstelle von CFStringRef (Core Foundation Type) verwenden:
UserName = TNSString::Wrap(NSUserName())->UTF8String();