2010-11-14 8 views

risposta

12

Nel caso in cui si preferisce utilizzare gli X API native del sistema operativo invece di system("open ...")

È possibile utilizzare questo codice:

#include <string> 
#include <CoreFoundation/CFBundle.h> 
#include <ApplicationServices/ApplicationServices.h> 

using namespace std; 

void openURL(const string &url_str) { 
    CFURLRef url = CFURLCreateWithBytes (
     NULL,      // allocator 
     (UInt8*)url_str.c_str(),  // URLBytes 
     url_str.length(),   // length 
     kCFStringEncodingASCII,  // encoding 
     NULL       // baseURL 
    ); 
    LSOpenCFURLRef(url,0); 
    CFRelease(url); 
} 

int main() { 
    string str("http://www.example.com"); 
    openURL(str); 
} 

che si deve compilare con le dovute quadri OS X:

g++ file.cpp -framework CoreFoundation -framework ApplicationServices 
Problemi correlati