tags:

views:

34

answers:

2

Hello,

Currently I'm developing a DLL which is intended to be linked to 3rd party applications in order to test whether this application is eligible to run at a given time.

First I thought about to create a DLL and handle the needed check in TInt E32Dll() function. But I was very surprised when I've read that this function is not called on DLL load/unload in EKA2.

So now I need another way to achieve my task. My goal is to create some mechanism, which can be embedded in 3rd party applications. This mechanism should be called on application start, perform some check (presence of specific Symbian server), and if the check is failed, it should terminate the application. Another requirement is that this mechanism should be transparent at best to developers of those 3rd party applications. (The E32Dll() function was the best candidate - just link specific library to a project and you're done...)

I'll greatly appreciate any other ideas. Thanks in advance.

A: 

Hi,

I am not sure that doing something in E32Dll() even it work (but it doesn't as you figure out) is a good way, because prior to closing the application you have to show some notification or dialog to the user. Why not making a normal DLL + thin start-up code, which will load (using the RLibrary) and call the 1st ordinal function:

RLibrary library;

//UID
TUidType uidType( TUid::Uid(KDynamicLibraryUidValue), 
                  TUid::Uid(KMyInterfaceUid), 
                  TUid::Uid(KMyImplementationUid) );

// Open dll 
User::LeaveIfError( library.Load( KMyDll, uidType ) );

// Check the exported method      
TLibraryFunction ordinal1 = aLibrary.Lookup( 1 );

// Call the method...
if ( ordinal1 )
    ordinal1();

library.Close();

BR STeN


Hi Haspemulator, There is my answer to your comment:

1) No, the 1st ordinal is not E32Dll(), this method cannot be called since EKA2. Check the description below (http://developer.symbian.org/wiki/Symbian_OS_Internals/10._The_Loader):

Note that, in EKA2, the public DLL entry-point, E32Dll(TDllReason) is no longer invoked. This function must be present in every EKA1 DLL, to be called when the DLL is attached to or detached from a process or thread. Unfortunately, this entry-point system cannot provide any guarantees that E32Dll() will be called with the appropriate parameter at the specified time. Because it is not possible to support this functionality reliably, EKA2 removes support for it. This removal simplifies the kernel-side architecture for managing dynamically loaded code, which improves reliability and robustness.

2) You can find an interesting discussion regarding this topic also here: http://discussion.forum.nokia.com/forum/showthread.php?80781-What-is-the-replacement-for-E32Dll-and-TDllReason

3) In our case the 1st ordinal will be the 1st function you will export from the DLL. You can find information how to write such a DLL here: http://developer.symbian.org/main/documentation/reference/s3/pdk/GUID-4A56B285-790E-5171-88F3-8C40B2AA9699.html

4) To be more concrete what I mean by exporting a method from DLL check the code below (the method can of course return some variable - e.g. newly created object):

EXPORT_C void InitDll()
{
  // Put here your code 
}

Hope it helps... BR STeN


STeN
Is the first ordinal function is always E32Dll()?
Haspemulator
Hi, I put my comment into original answer, since the comment has limited space... BR
STeN
+1  A: 

I've actually found a way to achieve my goal - call some method when DLL is loaded. The idea was given to me at http://developer.symbian.org/forum/showthread.php?p=30244.

One just need to declare some global object in some DLL module, and its constructor will be called when the DLL will be loaded. This solution works fine for me, and, indeed, this answer should really be accepted...

... But since I'm not the author of this solution, and currently accepted answer still contain valuable information, I'll not change the mark of accepting. Just let it be so. :)

Haspemulator
Hi, this is an interesting idea! Just be aware of possible drawbacks of it - but I am not sure about them: 1) Normally writable static data are not allowed in DLL, but check the EPOCALLOWDLLDATA flag. 2) How you will load the DLL? If you will use the RLibrary, then my way is more convenient, but if you want to really automate it and you will use the static linking, then I am not sure what is really initialized at time 'DLL object' is created, e.g. will be the CleanupStack initialized or not? 3)There are some limitations on what can and cannot be done in constructors on Symbian... BR STeN
STeN
Thanks for idea to check cleanup stack! I'm pretty sure that all libraries are initialized before the main entry point, so there'll be no CleanupStack and ActiveScheduler. And, of course, this stuff shall not leave...
Haspemulator