/*---------------------------------------------------------------------------* Project: Wii Connect 24 API demos File: MsgPost.c Copyright 2006 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Log: MsgPost.c,v $ Revision 1.2 2007/08/31 10:25:08 hirose_kazuki Added NWC24Check() call. Revision 1.1 2006/09/27 08:56:17 torigoe_nobutaka Moved from nwc24demo/src. Revision 1.4 2006/09/13 08:14:22 yosizaki changed to call VFInit(). Revision 1.3 2006/09/10 09:20:56 hirose_kazuki Changed to use NWC24OpenLib/NWC24CloseLib instead of obsoleted APIs. Revision 1.2 2006/07/13 12:51:42 hirose_kazuki Updated due to the API spec change. Revision 1.1 2006/06/29 12:46:21 hirose_kazuki Moved from another repository. Revision 1.1 2006/06/12 07:37:18 hirose Initial check in. *---------------------------------------------------------------------------*/ #include #include #include #include #include #include #include /*---------------------------------------------------------------------------* A simple demo to post a message. *---------------------------------------------------------------------------*/ void PostTestMsg( void ); /*---------------------------------------------------------------------------*/ MEMHeapHandle HeapHndl; MEMAllocator Allocator; /*---------------------------------------------------------------------------* Main *---------------------------------------------------------------------------*/ 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(" A simple demo to post a message.\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"); } err = NWC24Check(NWC24_USE_MESSAGES); if ( err != NWC24_OK ) { OSReport("NWC24Check(): Error %d (Code: %06d)\n", err, - NWC24GetErrorCode()); 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. *---------------------------------------------------------------------------*/ static char* TestSubject = "Test Message"; static char* TestMsgText = "Hello WiiConnect24 World!!\x0d\x0a" "This is a test mail.\x0d\x0a" "Thank you.\x0d\x0a"; static NWC24UserId TestIdTo = 9999999999999999ULL; /* Invalid destination */ /*---------------------------------------------------------------------------* Post a test message into the send box. *---------------------------------------------------------------------------*/ void PostTestMsg( void ) { NWC24Err err; NWC24MsgObj msgObj; // Initializes the object, specifies Wii-to-Wii message. err = NWC24InitMsgObj(&msgObj, NWC24_MSGTYPE_WII); if ( err != NWC24_OK ) { OSReport("NWC24InitMsgObj(): error %d\n", err); return; } // To address (by user id.) 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, TestMsgText, (u32)strlen(TestMsgText), NWC24_US_ASCII, NWC24_ENC_7BIT); if ( err != NWC24_OK ) { OSReport("NWC24SetMsgText(): 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; }