Friday, September 08, 2006

Running EXE file on the S60 2nd Edition


Use this code for the 2nd edition. Note that the first half of the if statement is just so that the code works on the emulator. This is because the emulator uses a Dynamic Link Library (DLL), therefore we need to employ library functions. However the overall outcome is the same.


TRequestStatus start;
TServerStart starter(start);

#ifdef __WINS__ // On the Windows emulator the process is a DLL
RLibrary lib;
lib.Load(KBinaryName, BinaryUid);
TLibraryFunction export1 = lib.Lookup(1);
TThreadFunction threadFunction = reinterpret_cast (export1());
TName name(KBinaryName);
// Randomness ensures a unique thread name
name.AppendNum(Math::Random(), EHex);

// Now create the server thread
const TInt KMinHeapSize=0x1000;
const TInt KMaxHeapSize=0x1000000;
RThread thread;
thread.Create(name, threadFunction, KDefaultStackSize,
&starter, &lib, NULL,KMinHeapSize, KMaxHeapSize, EOwnerProcess);
lib.Close();
#else // Phone hardware
RProcess process;
process.Create(KBinaryName,starter.AsCommand(), BinaryUid);
#endif

No comments: