#include #include #include #include #include #include #include /*---------------------------------------------------------------------------* template data *---------------------------------------------------------------------------*/ extern u8 my_letter_arc_begin[]; extern u8 my_letter_arc_end[]; /*---------------------------------------------------------------------------* A simple demo to post a message. *---------------------------------------------------------------------------*/ void PostTestMsg( void ); MEMHeapHandle HeapHndl; MEMAllocator Allocator; int main(void) { NWC24Err err; s32 result; void* arenaLo; void* arenaHi; char* libWorkMem; // Memory allocator initialization arenaLo = OSGetMEM1ArenaLo(); arenaHi = OSGetMEM1ArenaHi(); HeapHndl = MEMCreateExpHeap(arenaLo, (u32)arenaHi - (u32)arenaLo); OSSetMEM1ArenaLo(arenaHi); MEMInitAllocatorForExpHeap(&Allocator, HeapHndl, 32); result = NANDInit(); if ( result != NAND_RESULT_OK ) { OSHalt("NANDInit() failed.\n"); } VFInit(); OSReport("*******************************************************\n"); OSReport(" NWC24 Letter demo\n"); OSReport("*******************************************************\n"); libWorkMem = MEMAllocFromAllocator(&Allocator, NWC24_WORK_MEM_SIZE); err = NWC24OpenLib(libWorkMem); if ( err != NWC24_OK ) { OSReport("NWC24OpenLib(): Error %d\n", err); OSHalt("Failed.\n"); } // Post a message. PostTestMsg(); err = NWC24CloseLib(); if ( err != NWC24_OK ) { OSReport("NWC24CloseLib(): Error %d\n", err); OSHalt("Failed.\n"); } MEMFreeToAllocator(&Allocator, libWorkMem); OSHalt("\nCompleted.\n"); return 0; } /*---------------------------------------------------------------------------* Data for this test. "TestMsgText" and "TestAltName" are sent in the UTF_16BE charset. *---------------------------------------------------------------------------*/ static char* TestSubject = "Test Message"; static wchar_t TestMsgText[] = L"Hello WiiConnect24 World!!\x0d\x0a" L"This is a test mail with an original template.\x0d\x0a" L"Thank you.\x0d\x0a" L"\x0d\x0a" L"AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDDDDDDDDEEEEEEEEEE\x0d\x0a"; static wchar_t TestAltName[] = L"Wii Game"; void PostTestMsg(void) { NWC24Err err; NWC24MsgObj msgObj; NWC24UserId testIdTo; // Initializes the object, specifies Wii-to-Wii message. err = NWC24InitMsgObj(&msgObj, NWC24_MSGTYPE_WII_MENU); if ( err != NWC24_OK ) { OSReport("NWC24InitMsgObj(): error %d\n", err); return; } // To address (by user id) err = NWC24GetMyUserId(&testIdTo); if( err != NWC24_OK ) { OSReport("NWC24GetMyUserId(): error %d\n", err); return; } err = NWC24SetMsgToId(&msgObj, testIdTo); if ( err != NWC24_OK ) { OSReport("NWC24SetMsgToId(): error %d\n", err); return; } // Subject err = NWC24SetMsgSubject(&msgObj, TestSubject, (u32)strlen(TestSubject)); if ( err != NWC24_OK ) { OSReport("NWC24SetMsgSubject(): error %d\n", err); return; } // Message body (text) err = NWC24SetMsgText(&msgObj, (const char*)TestMsgText, (u32)sizeof(TestMsgText) - 2, NWC24_UTF_16BE, NWC24_ENC_BASE64); if ( err != NWC24_OK ) { OSReport("NWC24SetMsgText(): error %d\n", err); return; } // Attached template file. err = NWC24SetMsgAttached(&msgObj, (const char*)my_letter_arc_begin, (u32)(my_letter_arc_end - my_letter_arc_begin), NWC24_APP_WII_MSGBOARD); if ( err != NWC24_OK ) { OSReport("NWC24SetMsgAttached(): error %d\n", err); return; } // Set alternate name. err = NWC24SetMsgAltName(&msgObj, (const u16*)TestAltName, (u32)sizeof(TestAltName) - 2); if ( err != NWC24_OK ) { OSReport("NWC24SetMsgAltName(): error %d\n", err); return; } // Commit settings and post the message into the send box. err = NWC24CommitMsg(&msgObj); if ( err != NWC24_OK ) { OSReport("NWC24CommitMsg: error %d\n", err); return; } OSReport("Posted a test message successfully.\n"); return; }