Launch Applet?

Discussion in '3DS - Homebrew Development and Emulators' started by gudenau, Feb 13, 2016.

  1. gudenau
    OP

    gudenau Never a unique idea

    Member
    3,257
    1,225
    Jul 7, 2010
    United States
    /dev/random
    I am attempting to launch the web browser from an installed title, but when it "returns" to the home menu it crashes. Any ideas?

    Code:
    #include <3ds.h>
    #include <stdio.h>
    
    #define WHITE_ERRORS
    
    static PrintConsole errorScreen;
    static PrintConsole logScreen;
    
    void printError(const char* message, Result result);
    
    extern NS_APPID currentAppId;
    
    int main(int argc, char **argv){
        Result result;
        u8 temp = 0;
       
        gfxInitDefault();
       
        // Setup the consoles, make the error one red
        consoleInit(GFX_TOP, &logScreen);
        consoleInit(GFX_BOTTOM, &errorScreen);
        #ifdef WHITE_ERRORS
            printError("Errors:", 0);
        #else
            printError("\x1b[31mErrors:", 0);
        #endif
       
        aptOpenSession();
        printError("APT_ReplySleepQuery", APT_ReplySleepQuery(currentAppId, 0));
        aptCloseSession();
       
        aptOpenSession();
        printError("APT_PrepareToStartSystemApplet", APT_PrepareToStartSystemApplet(APPID_WEB));
        aptCloseSession();
       
        u8 buffer[16];
        aptOpenSession();
        printError("APT_StartSystemApplet", APT_StartSystemApplet(APPID_WEB, /* buffer size */ 0, CUR_PROCESS_HANDLE, buffer));
        aptCloseSession();
       
        for(;;){
            aptOpenSession();
            result = APT_IsRegistered(APPID_WEB, &temp);
            aptCloseSession();
            if(R_FAILED(result)){
                goto error;
            }
           
            if(temp != 0){
                break;
            }
        }
       
        GSPGPU_ReleaseRight();
       
        goto noerror;
        //return 0;
       
        error:
        printf("There was an error, aborting operations.\n");
       
        noerror:
       
        while (aptMainLoop()){
            hidScanInput();
           
            if(hidKeysDown() & KEY_START){
                break;
            }
           
            gfxFlushBuffers();
            gfxSwapBuffers();
           
            gspWaitForVBlank();
        }
       
        gfxExit();
        return 0;
    }
    
    void printError(const char* message, Result result){
        consoleSelect(&errorScreen);
        printf("%s\n", message);
        if(result){
            printf("%08lx\n", result);
        }
        consoleSelect(&logScreen);
    }