Changeset 16835 in vbox
- Timestamp:
- Feb 17, 2009 12:49:35 PM (16 years ago)
- Location:
- trunk/src/VBox/Main/cbinding
- Files:
-
- 3 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/cbinding/Makefile.kmk
r16833 r16835 88 88 89 89 # 90 # C testcase using the dynamic glue. 91 # 92 PROGRAMS.linux += tstXPCOMCGlue 93 tstXPCOMCGlue_TEMPLATE = VBOXR3 94 tstXPCOMCGlue_INCS = \ 95 $(VBOX_PATH_SDK)/bindings/xpcom/include \ 96 $(VBOX_PATH_SDK)/bindings/xpcom/include/nsprpub 97 tstXPCOMCGlue_INTERMEDIATES = \ 98 $(VBOX_PATH_SDK)/bindings/xpcom/include/VirtualBox_CXPCOM.h 99 tstXPCOMCGlue_SOURCES = \ 100 tstXPCOMCGlue.c 101 tstXPCOMCGlue_LIBS = \ 102 $(VBoxXPCOMCGlue_1_TARGET) 103 104 # 90 105 # The testcase (also in samples). 91 106 # -
trunk/src/VBox/Main/cbinding/VBoxXPCOMCGlue.c
r16832 r16835 50 50 void *g_hVBoxXPCOMC = NULL; 51 51 /** The last load error. */ 52 char g_szVBox XPCOMErrMsg[256];52 char g_szVBoxErrMsg[256]; 53 53 /** Pointer to the VBoxXPCOMC function table. */ 54 54 PCVBOXXPCOM g_pVBoxFuncs = NULL; … … 77 77 if (!pszBuf) 78 78 { 79 sprintf(g_szVBox XPCOMErrMsg, "malloc(%u) failed", (unsigned)cbBuf);79 sprintf(g_szVBoxErrMsg, "malloc(%u) failed", (unsigned)cbBuf); 80 80 if (pszMsgPrefix) 81 fprintf(stderr, "%s%s\n", pszMsgPrefix, g_szVBox XPCOMErrMsg);81 fprintf(stderr, "%s%s\n", pszMsgPrefix, g_szVBoxErrMsg); 82 82 return -1; 83 83 } … … 107 107 rc = 0; 108 108 else 109 sprintf(g_szVBox XPCOMErrMsg, "%.80s: pfnGetFunctions(%#x) failed",109 sprintf(g_szVBoxErrMsg, "%.80s: pfnGetFunctions(%#x) failed", 110 110 pszBuf, VBOX_XPCOMC_VERSION); 111 111 } 112 112 else 113 sprintf(g_szVBox XPCOMErrMsg, "dlsym(%.80s/%.32s): %128s",113 sprintf(g_szVBoxErrMsg, "dlsym(%.80s/%.32s): %128s", 114 114 pszBuf, VBOX_GET_XPCOMC_FUNCTIONS_SYMBOL_NAME, dlerror()); 115 115 } 116 116 else 117 sprintf(g_szVBox XPCOMErrMsg, "dlopen(%.80s): %128s", pszBuf, dlerror());117 sprintf(g_szVBoxErrMsg, "dlopen(%.80s): %128s", pszBuf, dlerror()); 118 118 free(pszBuf); 119 119 return rc; -
trunk/src/VBox/Main/cbinding/VBoxXPCOMCGlue.h
r16832 r16835 32 32 extern void *g_hVBoxXPCOMC; 33 33 /** The last load error. */ 34 extern char g_szVBox XPCOMErrMsg[256];34 extern char g_szVBoxErrMsg[256]; 35 35 /** Pointer to the VBoxXPCOMC function table. */ 36 36 extern PCVBOXXPCOM g_pVBoxFuncs; -
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
Note:
See TracChangeset
for help on using the changeset viewer.