- 時間撮記:
- 2009-2-17 下午12:49:35 (16 年 以前)
- 檔案:
-
- 複製 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/Main/cbinding/tstXPCOMCGlue.c
r16829 r16835 1 1 /* $Revsion: $ */ 2 /** @file tst LinuxC.c2 /** @file tstXPCOMCGlue.c 3 3 * Demonstrator program to illustrate use of C bindings of Main API. 4 4 * … … 22 22 */ 23 23 24 /******************************************************************************* 25 * Header Files * 26 *******************************************************************************/ 27 #include "VBoxXPCOMCGlue.h" 24 28 #include <stdio.h> 25 29 #include <string.h> 26 30 #include <stdlib.h> 27 31 #include <sys/stat.h> 28 #include "cbinding.h"29 32 30 33 static char *nsIDToString(nsID *guid); … … 114 117 115 118 machine->vtbl->GetName(machine, &machineNameUtf16); 116 VBoxUtf16ToUtf8(machineNameUtf16,&machineName);119 g_pVBoxFuncs->pfnUtf16ToUtf8(machineNameUtf16,&machineName); 117 120 printf("\tName: %s\n", machineName); 118 121 119 VBoxUtf8Free(machineName);120 VBoxComUnallocMem(machineNameUtf16);122 g_pVBoxFuncs->pfnUtf8Free(machineName); 123 g_pVBoxFuncs->pfnComUnallocMem(machineNameUtf16); 121 124 } 122 125 else … … 135 138 136 139 free(uuidString); 137 VBoxComUnallocMem(iid);140 g_pVBoxFuncs->pfnComUnallocMem(iid); 138 141 } 139 142 … … 145 148 146 149 machine->vtbl->GetSettingsFilePath(machine, &configFile); 147 VBoxUtf16ToUtf8(configFile, &configFile1);150 g_pVBoxFuncs->pfnUtf16ToUtf8(configFile, &configFile1); 148 151 printf("\tConfig file: %s\n", configFile1); 149 152 150 153 free(configFile1); 151 VBoxComUnallocMem(configFile);154 g_pVBoxFuncs->pfnComUnallocMem(configFile); 152 155 } 153 156 … … 168 171 virtualBox->vtbl->GetGuestOSType(virtualBox, typeId, &osType); 169 172 osType->vtbl->GetDescription(osType, &osNameUtf16); 170 VBoxUtf16ToUtf8(osNameUtf16,&osName);173 g_pVBoxFuncs->pfnUtf16ToUtf8(osNameUtf16,&osName); 171 174 printf("\tGuest OS: %s\n\n", osName); 172 175 173 176 osType->vtbl->nsisupports.Release((void *)osType); 174 VBoxUtf8Free(osName);175 VBoxComUnallocMem(osNameUtf16);176 VBoxComUnallocMem(typeId);177 g_pVBoxFuncs->pfnUtf8Free(osName); 178 g_pVBoxFuncs->pfnComUnallocMem(osNameUtf16); 179 g_pVBoxFuncs->pfnComUnallocMem(typeId); 177 180 } 178 181 } … … 198 201 startVM(virtualBox, session, iid); 199 202 200 VBoxComUnallocMem(iid);203 g_pVBoxFuncs->pfnComUnallocMem(iid); 201 204 } 202 205 } … … 240 243 } 241 244 242 VBoxUtf8ToUtf16("gui", &sessionType);245 g_pVBoxFuncs->pfnUtf8ToUtf16("gui", &sessionType); 243 246 244 247 rc = virtualBox->vtbl->OpenRemoteSession( … … 251 254 ); 252 255 253 VBoxUtf16Free(sessionType);256 g_pVBoxFuncs->pfnUtf16Free(sessionType); 254 257 255 258 if (NS_FAILED(rc)) … … 280 283 progress->vtbl->GetErrorInfo(progress, &errorInfo); 281 284 errorInfo->vtbl->GetText(errorInfo, &textUtf16); 282 VBoxUtf16ToUtf8(textUtf16, &text);285 g_pVBoxFuncs->pfnUtf16ToUtf8(textUtf16, &text); 283 286 printf("Error: %s\n", text); 284 287 285 VBoxComUnallocMem(textUtf16);286 VBoxUtf8Free(text);288 g_pVBoxFuncs->pfnComUnallocMem(textUtf16); 289 g_pVBoxFuncs->pfnUtf8Free(text); 287 290 } 288 291 else … … 309 312 nsresult rc; /* Result code of various function (method) calls. */ 310 313 311 /*312 * Guess where VirtualBox is installed not mentioned in the environment.313 * (This will be moved to VBoxComInitialize later.)314 */315 316 if (!VBoxGetEnv("VBOX_APP_HOME"))317 {318 if (stat("/opt/VirtualBox/VBoxXPCOMC.so", &stIgnored) == 0)319 {320 VBoxSetEnv("VBOX_APP_HOME","/opt/VirtualBox/");321 }322 if (stat("/usr/lib/virtualbox/VBoxXPCOMC.so", &stIgnored) == 0)323 {324 VBoxSetEnv("VBOX_APP_HOME","/usr/lib/virtualbox/");325 }326 }327 328 314 printf("Starting Main\n"); 329 315 … … 335 321 */ 336 322 337 VBoxComInitialize(&vbox, &session); 338 323 if (VBoxCGlueInit(NULL) != 0) 324 { 325 fprintf(stderr, "%s: FATAL: VBoxCGlueInit failed: %s\n", 326 argv[0], g_szVBoxErrMsg); 327 return EXIT_FAILURE; 328 } 329 330 g_pVBoxFuncs->pfnComInitialize(&vbox, &session); 339 331 if (vbox == NULL) 340 332 { … … 375 367 { 376 368 char *version = NULL; 377 VBoxUtf16ToUtf8(versionUtf16, &version);369 g_pVBoxFuncs->pfnUtf16ToUtf8(versionUtf16, &version); 378 370 printf("\tVersion: %s\n", version); 379 VBoxUtf8Free(version);380 VBoxComUnallocMem(versionUtf16);371 g_pVBoxFuncs->pfnUtf8Free(version); 372 g_pVBoxFuncs->pfnComUnallocMem(versionUtf16); 381 373 } 382 374 else … … 392 384 { 393 385 char *homefolder = NULL; 394 VBoxUtf16ToUtf8(homefolderUtf16, &homefolder);386 g_pVBoxFuncs->pfnUtf16ToUtf8(homefolderUtf16, &homefolder); 395 387 printf("\tHomeFolder: %s\n", homefolder); 396 VBoxUtf8Free(homefolder);397 VBoxComUnallocMem(homefolderUtf16);388 g_pVBoxFuncs->pfnUtf8Free(homefolder); 389 g_pVBoxFuncs->pfnComUnallocMem(homefolderUtf16); 398 390 } 399 391 else … … 412 404 */ 413 405 414 VBoxComUninitialize(); 406 g_pVBoxFuncs->pfnComUninitialize(); 407 VBoxCGlueTerm(); 415 408 printf("Finished Main\n"); 416 409
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器