Dll lookup error

Login to reply to this topic.
Mon, 2007-02-05 23:36
Joined: 2007-01-24
Forum posts: 10
I have the following code which calls a polymorphic dll functio:
RLibrary library;
if (library.Load(_L("ModuloDll.dll")) != KErrNone)
{

typedef TInt (*TMyFunc)(TReal);
TLibraryFunction theFunc = library.Lookup(1);
TInt aux = theFunc();
library.Close();
}

The dll function is the following:
/*******/
.h
/*******/
#ifndef __ModuloDll_H__
#define __ModuloDll_H__


//  Include Files

#include <e32base.h>


IMPORT_C public TInt Get10(TReal /*aVal*/);
GLDEF_C TInt E32Main();


#endif  // __ModuloDll_H__
/*******/
.cpp file
/*******/
#include "ModuloDll.h"
#include <e32base.h>
#include <e32std.h>
#include <e32cons.h>           


EXPORT_C public TInt Get10(TReal /*aVal*/)
{
return 10;
}

EXPORT_C TInt E32Dll(TDllReason /*aReason*/)
    {
    return KErrNone;
    }


The .dll is placed in the same directory as the application (if I placed in different place(\Epoc32\release\wins\udeb) it fails).

The application crashes in the lookup call, I was trying many things but I do not know which fails. I though the dll implementation is not correct but I am not sure.
Another question, is it necessary that the dll has a constructor?
Thanks for all




Tue, 2007-02-06 14:20
Forum Nokia Champion
Joined: 2003-10-01
Forum posts: 723
Re: Dll lookup error
First of all, you did not specify which SDK you're using. It might be important as as of Platform Security a DLL does not have to have an E32Dll function.

Second, even in pre-PlatSec world the aforementioned E32Dll did not have to be exported. You simply had to use GLDEF_C (and/or maybe GLREF_C). See examples in your SDK.

Finally, I think your dll should have only one exported method at ordinal 0 (zero).

Hope this helps,

Tote

Gabor Torok
Software architect, Agil Eight (http://www.agileight.com/)
Blog: http://mobile-thoughts.blogspot.com/

Tue, 2007-02-06 16:27
Joined: 2004-09-14
Forum posts: 140
Re: Dll lookup error
DLL exports (oridinals) start and 1 and not 0.

Secondly the code is blatently wrong.

typedef TInt (*TMyFunc)(TReal);
TLibraryFunction theFunc = library.Lookup(1);
TInt aux = theFunc();

should read

TMyFunc theFunc = (TMyFunc)library.Lookup(1);
TInt aux = theFunc(1.032);/ / or what ever the real is

Paul Todd

Mon, 2007-02-26 21:37
Joined: 2007-01-24
Forum posts: 10
Re: Dll lookup error
I tried all but it does not work. I will give more details: I use S60 v2 SDK.
I create a dll using the carbide wizard for Microsoft Visual Studio (I tried: New Proyect->Symbian OS DLL and Symbian OS EXEDLL)and I place de .dll obtained in the c folder of the emulator (C:\Symbian\7.0s\Series60_v20\Epoc32\wins\c).
Then, in my project I do:
RLibrary library;
         if (library.Load(_L("dll2602.dll")) != KErrNone)
         {
            TLibraryFunction theFunc = library.Lookup(1);
            iEikonEnv->InfoMsg(_L("Open"));
            CAknInformationNote* note = new (ELeave) CAknInformationNote;
            note->ExecuteLD(_L("Loaded"));
         }
         else
         {
            CAknInformationNote* note2 = new (ELeave) CAknInformationNote;
            note2->ExecuteLD(_L("Not Loaded"));
         }
I do not call the function because the error is in the line:
TLibraryFunction theFunc = library.Lookup(1);
I tried calling the function as Paul explained( typedef TInt (*TMyFunc)(TReal);
TLibraryFunction theFunc = library.Lookup(1);
TInt aux = theFunc()Wink but it does not worked, any idea.
Thanks for all
Thu, 2007-09-27 21:40
Joined: 2007-09-27
Forum posts: 2
Re: Dll lookup error

Hi.

I have a problem related with this topic but I'm using s60 v3 SDK. I have a DLL which has a function that receives a TInt parameter and then sets a variable with that value. But, when I call the dll's function from another application and I send a TInt value, it receives an incorrect value.

Here is the code for my dll's function where first it displays the received value in a global note and then it sets the variable. For example:

EXPORT_C void CExampleDll::SetValue(TInt newValue)
{
        _LIT(KListFormat, "%d");
        TBuf<10> buf;
        buf.Format(KListFormat, newValue);

        CAknGlobalNote* note = CAknGlobalNote::NewLC();
        note->SetSoftkeys(R_AVKON_SOFTKEYS_OK_EMPTY);
        TInt id = note->ShowNoteL(EAknGlobalTextNote, buf);
        User::After(2000000);
        note->CancelNoteL(id);
        CleanupStack::PopAndDestroy(note);

        // HERE THE CODE TO SET THE VARIABLE
}

Here is the code from the application to call the dll's function:

RLibrary lib;
lib.Load(_L("functionslibrary.dll"));

typedef void (*TMyFunc)(TInt);               
TMyFunc FSetValue = (TMyFunc)lib.Lookup(1);
TInt y(5);
FSetValue(y);

I tried to use the TLibraryEntry instead of create my own typedef function, but it didn't work too. I also tried to do an static cast to the value received in the dll's function, but it didn't work too.

So, if you had a similar problem, would you tell me please what did you do to solve it?

Thanks.

Fri, 2007-09-28 08:46
Joined: 2004-06-08
Forum posts: 148
Re: Dll lookup error

Hi, juanaranda.
I think you mixed things up a little bit. Is it a static or polymorphic DLL you are trying to create?
If it is a static dll, there is no need to load the library like this. Just add the header file with the exported functions in your code, and then add the .lib (or .dso for GCCE) files in project, when the linker asks for them.
If it is a polymorphic dll you have, here is the thing that works for me. I think this is the right way to export your functions.
In your dll, there is only one function exported.

EXPORT_C CMyClass* NewPlugin()
{
return new (ELeave) CMyClass;
}
This is why you look for it at ordinal 1 when you want to use it.

And you can load the library like this.

User::LeaveIfError(library.Load(aPluginName));
// Check second UID is as expected; leave if not
if (library.Type()[1] != KDLLUidValue)
{
User::Leave(KErrGeneral);
}
TLibraryFunction entry=library.Lookup(1);
if(entry)
{
// Call the function to create new CMyClass
CMyClass* iMyClass=(CMyClass*) entry();
.....
delete iMyClass;
}

Now you have your class exported. You can have whatever member functions you like in this class, and you can use them trough the iMyClass object.

Mon, 2007-10-01 18:33
Joined: 2007-09-27
Forum posts: 2
Re: Dll lookup error

Hi.

Thanks filio for reply my post, I appreciate your help a lot Smiling . I was trying to create a polymorphic dll. I followed your way to create it and I also found out more about it. I created an interface (abstract class with virtual methods) that I called CMyClassLib and there I defined the functions that the dll should have. I implemented the interface in the CMyClass class and I exported only one function:

EXPORT_C CMyClass* NewPlugin()
{
return new (ELeave) CMyClass;
}

I compiled everything and the dll file was created. But, when I was trying to call a dll’s function in other application (that I called CMyClassApp and is in a different project and folder) I got an error in the part where I’m casting the function returned by the Lookup(). For example:

void CMyClassApp::HandleCommandL(TInt aCommand)
{
//MORE CODE HERE

User::LeaveIfError(library.Load(aPluginName));
// Check second UID is as expected; leave if not
if (library.Type()[1] != KDLLUidValue)
{
User::Leave(KErrGeneral);
}
TLibraryFunction entry=library.Lookup(1);
if(entry)
{
// Call the function to create new CMyClass
CMyClass* iMyClass=(CMyClass*) entry();
.....
delete iMyClass;
}

//MORE CODE HERE
}

The error I got was that CMyClass was undeclared. I don’t know if I have to copy the interface or dll’s class in the CMyClassApp’s directory and import them in the CMyClassApp’s cpp file. So if you can give a hint about what should I do, I appreciate it a lot.

Mon, 2007-10-08 16:11
Joined: 2004-06-08
Forum posts: 148
Re: Dll lookup error

Hello, juanaranda.
I'm really sorry for the late reply. I hope you found the answer yourself already. Probably you have your interface declaration in a header file. Just include the .h file in CMyClassApp, and it will compile.

  • Login to reply to this topic.