runmidlet_md.c
来自「This is a resource based on j2me embedde」· C语言 代码 · 共 566 行 · 第 1/2 页
C
566 行
* @todo determine if it is desirable for user targeted output * messages to be sent via the log/trace service, or if * they should remain as printf calls */int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd) { int argc; char** commandlineArgs; BOOL fActivated; int status = -1; MidpString suiteID = NULL_MIDP_STRING; MidpString classname = NULL_MIDP_STRING; MidpString arg0 = NULL_MIDP_STRING; MidpString arg1 = NULL_MIDP_STRING; MidpString arg2 = NULL_MIDP_STRING; int repeatMidlet = 0; char* argv[RUNMIDLET_MAX_ARGS]; int i, used; int debugOption = MIDP_NO_DEBUG; char *progName; char* appDir = NULL; char* confDir = NULL; char* additionalPath; MidpString* pSuites = NULL; int numberOfSuites = 0; if (FAILED(ActivatePreviousInstance(_szAppName, _szTitle, &fActivated)) || fActivated) { /* Exit immediately if previous instance exists */ return 0; } _hAppInstance = hInstance; process_command_line(lpCmdLine); if (!init_gui(hInstance, hPrevInstance, nShowCmd)) { REPORT_ERROR(LC_AMS, "init_gui() failed"); MessageBox(NULL, TEXT("Failed to start JWC"), TEXT("Bye"), MB_OK); return 0; } argc = _argc; commandlineArgs = _argv; progName = commandlineArgs[0]; JVM_Initialize(); /* It's OK to call this more than once */ /* * Set Java heap capacity now so it can been overridden from command line. */ JVM_SetConfig(JVM_CONFIG_HEAP_CAPACITY, MIDP_HEAP_REQUIREMENT); JVM_SetConfig(JVM_CONFIG_HEAP_MINIMUM, MIDP_HEAP_REQUIREMENT); /* * Parse options for the VM. This is desirable on a 'development' platform * such as linux_qte. For actual device ports, copy this block of code only * if your device can handle command-line arguments. */ /* JVM_ParseOneArg expects commandlineArgs[0] to contain the first actual * parameter */ argc --; commandlineArgs ++; while ((used = JVM_ParseOneArg(argc, commandlineArgs)) > 0) { argc -= used; commandlineArgs += used; } /* Restore commandlineArgs[0] to contain the program name. */ argc ++; commandlineArgs --; commandlineArgs[0] = progName; /* * Not all platforms allow rewriting the command line arg array, * make a copy */ if (argc > RUNMIDLET_MAX_ARGS) { REPORT_ERROR(LC_AMS, "Number of arguments exceeds supported limit"); fprintf(stderr, "Number of arguments exceeds supported limit\n"); return -1; } for (i = 0; i < argc; i++) { argv[i] = commandlineArgs[i]; } if (midpRemoveOptionFlag("-debug", argv, &argc) != NULL) { debugOption = MIDP_DEBUG_SUSPEND; } if (midpRemoveOptionFlag("-loop", argv, &argc) != NULL) { repeatMidlet = 1; } /* additionalPath gets appended to the classpath */ additionalPath = midpRemoveCommandOption("-classpathext", argv, &argc); if (argc == 1) {#if ENABLE_MULTIPLE_ISOLATES argv[argc++] = "internal"; argv[argc++] = "com.sun.midp.appmanager.MVMManager";#else argv[argc++] = "internal"; argv[argc++] = "com.sun.midp.appmanager.Manager";#endif } if (argc > 6) { REPORT_ERROR(LC_AMS, "Too many arguments given\n"); fprintf(stderr, "Too many arguments given\n%s", runUsageText); return -1; } /* get midp home directory, set it */ appDir = getApplicationDir(argv[0]); if (appDir == NULL) { return -1; } /* set up appDir before calling initialize */ midpSetAppDir(appDir); /* get midp config directory, set it */ confDir = getConfigurationDir(argv[0]); if (confDir == NULL) { return -1; } /* set up confDir before calling initialize */ midpSetConfigDir(confDir); if (midpInitialize() != 0) { REPORT_ERROR(LC_AMS, "Not enough memory"); fprintf(stderr, "Not enough memory\n"); return -1; } do { int onlyDigits; int len; int i; if (argc > 5) { arg2 = midpCharsToJchars(argv[5]); if (arg2.len == OUT_OF_MEM_LEN) { REPORT_ERROR(LC_AMS, "Out of Memory"); fprintf(stderr, "Out Of Memory\n"); break; } } if (argc > 4) { arg1 = midpCharsToJchars(argv[4]); if (arg1.len == OUT_OF_MEM_LEN) { REPORT_ERROR(LC_AMS, "Out of Memory"); fprintf(stderr, "Out Of Memory\n"); break; } } if (argc > 3) { arg0 = midpCharsToJchars(argv[3]); if (arg0.len == OUT_OF_MEM_LEN) { REPORT_ERROR(LC_AMS, "Out of Memory"); fprintf(stderr, "Out Of Memory\n"); break; } } if (argc > 2) { classname = midpCharsToJchars(argv[2]); if (classname.len == OUT_OF_MEM_LEN) { REPORT_ERROR(LC_AMS, "Out of Memory"); fprintf(stderr, "Out Of Memory\n"); break; } } /* if the storage name only digits, convert it */ onlyDigits = 1; len = strlen(argv[1]); for (i = 0; i < len; i++) { if (!isdigit((argv[1])[i])) { onlyDigits = 0; break; } } if (onlyDigits) { /* Run by number */ int suiteNumber; /* the format of the string is "number:" */ if (sscanf(argv[1], "%d", &suiteNumber) != 1) { REPORT_ERROR(LC_AMS, "Invalid suite number format"); fprintf(stderr, "Invalid suite number format\n"); break; } numberOfSuites = midpGetSuiteIDs(&pSuites); if (numberOfSuites < 0) { REPORT_ERROR(LC_AMS, "Out of Memory"); fprintf(stderr, "Out Of Memory\n"); break; } if (suiteNumber > numberOfSuites || suiteNumber < 1) { REPORT_ERROR(LC_AMS, "Suite number out of range"); fprintf(stderr, "Suite number out of range\n"); midpFreeSuiteIDs(pSuites, numberOfSuites); break; } suiteID = pSuites[suiteNumber - 1]; } else { /* Run by ID */ suiteID = midpCharsToJchars(argv[1]); if (suiteID.data == NULL) { REPORT_ERROR(LC_AMS, "Out of Memory"); fprintf(stderr, "Out Of Memory\n"); break; } } if (classname.len == NULL_LEN) { classname = findMidletClass(suiteID, 1); if (classname.len == OUT_OF_MEM_LEN) { REPORT_ERROR(LC_AMS, "Out of Memory"); fprintf(stderr, "Out Of Memory 7\n"); break; } if (classname.len == NULL_LEN) { REPORT_ERROR(LC_AMS, "Could not find the first MIDlet"); fprintf(stderr, "Could not find the first MIDlet\n"); break; } } do { status = midpRunMidletWithArgsCp(suiteID, classname, arg0, arg1, arg2, debugOption, additionalPath); } while (repeatMidlet && status != MIDP_SHUTDOWN_STATUS); if (pSuites != NULL) { midpFreeSuiteIDs(pSuites, numberOfSuites); suiteID = NULL_MIDP_STRING; } else { midpFreeString(suiteID); } } while (0); midpFreeString(arg0); midpFreeString(arg1); midpFreeString(arg2); midpFreeString(classname); switch (status) { case MIDP_SHUTDOWN_STATUS: break; case MIDP_ERROR_STATUS: REPORT_ERROR(LC_AMS, "The MIDlet suite could not be run."); fprintf(stderr, "The MIDlet suite could not be run.\n"); break; case SUITE_NOT_FOUND_STATUS: REPORT_ERROR(LC_AMS, "The MIDlet suite was not found."); fprintf(stderr, "The MIDlet suite was not found.\n"); break; default: break; } midpFinalize(); return status;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?