Update contrib.
1 // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\euser\epoc\up_lib.cpp
24 //#define __DEBUG_IMAGE__ 1
26 #if defined(__DEBUG_IMAGE__) && defined (__EPOC32__)
30 #define __IF_DEBUG(t) {debug.t;}
36 #define __SIZE(len) ((len)<<1)
38 #define __SIZE(len) (len)
47 EXPORT_C TInt RLibrary::LoadRomLibrary(const TDesC& aFileName, const TDesC& aPath)
49 return Load(aFileName,aPath);
56 Loads the named DLL which matches the specified UID type.
58 If successful, the function increments the usage count by one.
59 No additional search paths can be specified with this function.
61 @param aFileName A descriptor containing the name of the DLL to be loaded.
62 The length of the file name must not be greater than KMaxFileName.
63 @param aType A UID type (a triplet of UIDs) which the DLL must match.
64 Individual UIDs can contain the KNullUid wild card.
66 @return KErrNone, if successful;
67 KErrBadName, if the length of aFileName is greater than KMaxFileName;
68 otherwise one of the other system wide error codes.
70 EXPORT_C TInt RLibrary::Load(const TDesC& aFileName, const TUidType& aType)
73 return Load(aFileName, KNullDesC, aType);
82 If successful, the function increments the usage count by one.
84 @param aFileName A descriptor containing the name of the DLL to be loaded.
85 The length of the file name must not be greater than KMaxFileName.
86 @param aPath A descriptor containing a list of path names, each separated by
87 a semicolon. When specified, these paths are searched for the DLL
88 before the standard search locations. By default,
89 no pathnames are specified.
91 @return KErrNone, if successful;
92 KErrBadName, if the length of aFileName is greater than KMaxFileName;
93 otherwise one of the other system wide error codes.
95 EXPORT_C TInt RLibrary::Load(const TDesC& aFileName, const TDesC& aPath)
98 return Load(aFileName, aPath, TUidType());
105 Loads the named DLL that matches the specified UID type.
107 If successful, the function increments the usage count by one.
109 @param aFileName A descriptor containing the name of the DLL to be loaded.
110 The length of the file name must not be greater than KMaxFileName.
111 @param aPath A descriptor containing a list of path names, each separated by
112 a semicolon. When specified, these paths are searched for the DLL
113 before the standard search locations.
114 @param aType A UID type (a triplet of UIDs) that the DLL must match. Individual UIDs
115 can contain the KNullUid wild card.
117 @return KErrNone, if successful;
118 KErrBadName, if the length of aFileName is greater than KMaxFileName;
119 otherwise one of the other system wide error codes.
121 EXPORT_C TInt RLibrary::Load(const TDesC& aFileName, const TDesC& aPath, const TUidType& aType)
123 return Load(aFileName, aPath, aType, KModuleVersionWild);
130 Loads the named DLL that matches the specified UID type and version.
132 If successful, the function increments the usage count by one.
134 @param aFileName A descriptor containing the name of the DLL to be loaded.
135 The length of the file name must not be greater
137 @param aPath A descriptor containing a list of path names, each
138 separated by a semicolon. When specified, these paths
139 are searched for the DLL before the standard search locations.
140 @param aType A UID type (a triplet of UIDs) that the DLL must match.
141 Individual UIDs can contain the KNullUid wild card.
142 @param aModuleVersion A version specification that the DLL must match. Major
143 version must match exactly and minor version must be >= the
144 specified minor version.
146 @return KErrNone, if successful;
147 KErrBadName, if the length of aFileName is greater than KMaxFileName;
148 otherwise one of the other system wide error codes.
150 EXPORT_C TInt RLibrary::Load(const TDesC& aFileName, const TDesC& aPath, const TUidType& aType, TUint32 aModuleVersion)
153 __IF_DEBUG(Print(_L("RLibrary::Load ##")));
156 TInt r=loader.Connect();
160 r=loader.LoadLibrary(iHandle, aFileName, aPath, aType, aModuleVersion);
171 Gets information about the specified DLL.
173 @param aFileName A descriptor containing the name of the DLL to be checked.
174 The length of the file name must not be greater than KMaxFileName.
175 @param aInfoBuf On return, contains information about the DLL (RLibrary::TInfo)
177 @return KErrNone, if successful;
178 KErrBadName, if the length of aFileName is greater than KMaxFileName;
179 otherwise one of the other system wide error codes.
181 EXPORT_C TInt RLibrary::GetInfo(const TDesC& aFileName, TDes8& aInfoBuf)
183 __IF_DEBUG(Print(_L("RLibrary::GetInfo ##")));
185 TInt r=loader.Connect();
188 r=loader.GetInfo(aFileName, aInfoBuf);
197 Gets information about an executable binary, (DLL or EXE), based on header data
198 from that binaries image.
200 @param aHeader A descriptor containing the data from the start of the binaries image.
201 This data should be of size RLibrary::KRequiredImageHeaderSize or the
202 total length of the binary image, whichever is smallest.
203 @param aInfoBuf A descriptor which will be filled with the extracted information.
204 This information will be in the form of a RLibrary::TInfo structure.
205 This should usually be an object of type RLibrary::TInfoBuf.
207 @return KErrNone, if successful;
208 KErrUnderflow, if the size of aHeader is too small;
209 KErrCorrupt, if the data in aHeader isn't a valid executable image header;
210 Otherwise one of the other system wide error codes.
214 EXPORT_C TInt RLibrary::GetInfoFromHeader(const TDesC8& aHeader, TDes8& aInfoBuf)
217 TInt r=loader.Connect();
220 r=loader.GetInfoFromHeader(aHeader, aInfoBuf);
228 TInt RLibrary::InitL()
230 // Initialise any static data following a DLL load
233 TLinAddr ep[KMaxLibraryEntryPoints];
234 TInt numEps=KMaxLibraryEntryPoints;
235 E32Loader::LibraryAttach(iHandle, numEps, ep);
239 for (i=0; i<numEps; ++i)
241 TLibraryEntry f=(TLibraryEntry)ep[i];
242 TInt r = (*f)(KModuleEntryReasonProcessAttach);
246 return E32Loader::LibraryAttached(iHandle);
252 GLREF_C void Panic(TCdtPanic aPanic);
260 EXPORT_C TInt RLibrary::Init()
263 TRAPD(s,r=InitL()); // catch attempts to leave from constructors
264 __ASSERT_ALWAYS(s==KErrNone, Panic(EDllStaticConstructorLeave));
274 The function decrements the usage count by one.
276 This handle must have been used to load the DLL using
277 one of the Load() functions.
279 EXPORT_C void RLibrary::Close()
283 RHandleBase::Close();