×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    4

    Using a variable exported by a dll in a local variable: crash

    Hi,

    I am writing an "hello world" program with a dll. I compile and test it with CodeWarrior and Carbide.

    When I use the symbol exported by the .dll with a specific pattern, my program crashs. It does not reach the beakpoint I setup on the main() function: it crashs before the main() function. The pattern is this line:
    PHP Code:
      mystruct_t *f[1] = {myvar}; 
    where myvar is a variable exported by the dll and f is a local variable.

    If change this line with the 2 following lines, it works:
    PHP Code:
      mystruct_t *f[1];
      
    f[0] = myvar
    See the full sources below.

    Is it the expected behaviour, or a known bug?

    testdll.c:
    PHP Code:
    typedef char * (*ptrfunc_t)(char *);
    struct mystruct_s
    {
            
    ptrfunc_t a;
            
    ptrfunc_t b;
    };
    typedef struct mystruct_s mystruct_t;

    __declspec(dllexportchar *func(char *a)
    {
            
    printf("func: '%s'\n"a);
            
    sleep(5);
            return 
    "";
    }

    __declspec(dllexportmystruct_t myvar[1] = {{funcfunc}}; 
    testexe.c:
    PHP Code:
    typedef char * (*ptrfunc_t)(char *);
    struct mystruct_s
    {
            
    ptrfunc_t a;
            
    ptrfunc_t b;
    };
    typedef struct mystruct_s mystruct_t;

    __declspec(dllimportmystruct_t myvar[];


    int main(int argcchar *argv[])
    {
            
    char *t;

            
    mystruct_t *f[1] = {myvar};
            
    /*
            mystruct_t *f[1];
            f[0] = myvar;
            */

            
    printf("Hello world\n");
            
    sleep(5);
            return 
    0;

    Thanks

  2. #2
    Registered User
    Join Date
    Feb 2008
    Posts
    4

    Re: Using a variable exported by a dll in a local variable: crash

    I forget to say I am using S60_3rd_Ed_SDK_FP2_Beta_b.

    And I use EPOCALLOWDLLDATA in .mmp files (both for the exe and the dll).

  3. #3
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,740

    Re: Using a variable exported by a dll in a local variable: crash


  4. #4
    Registered User
    Join Date
    Feb 2008
    Posts
    4

    Re: Using a variable exported by a dll in a local variable: crash

    Thank you for the link.

    The panic code I get is:

    PHP Code:
    Application closed:
    Main
    KERN
    -EXEC 3 
    The documentation says: "KERN-EXEC 3 means a general unhandled exception."

    Then I enabled the just-in-time debugging and when the application crashes, the debugger prints the stack:

    Thread [Thread id: 17780] (Suspended: Signal 'Halt' received. Description: User halted thread.)
    20 0x8395F6( ekern.exe )() 0x008395f6
    19 0x8397DB( ekern.exe )() 0x008397db
    18 0x84C0C4( ekern.exe )() 0x0084c0c4
    17 0x8625FE( ekern.exe )() 0x008625fe
    16 0x862422( ekern.exe )() 0x00862422
    15 0x832138( ekern.exe )() 0x00832138
    14 0x8318FC( ekern.exe )() 0x008318fc
    13 0x831186( ekern.exe )() 0x00831186
    12 0x8326C4( ekern.exe )() 0x008326c4
    11 0x862842( ekern.exe )() 0x00862842
    10 0x8587B4( ekern.exe )() 0x008587b4
    9 0x858780( ekern.exe )() 0x00858780
    8 0x838DE1( ekern.exe )() 0x00838de1
    7 0x837107( ekern.exe )() 0x00837107
    6 0x837175( ekern.exe )() 0x00837175
    5 0x47A1005( testexe.exe )() 0x047a1005
    4 _E32Startup() F:\src\cedar\generic\base\e32\EUSER\epoc\win32\uc_exe.cpp:72 0x047a1123
    3 0x83880F( ekern.exe )() 0x0083880f
    2 0x836DC4( ekern.exe )() 0x00836dc4
    1 0x7C80B683( KERNEL32.dll )() 0x7c80b683

  5. #5
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,740

    Re: Using a variable exported by a dll in a local variable: crash

    You should click on "5" (I guess that testexe.exe is the code you are experimenting with). KERN-EXEC 3 is often related to accessing NULL/invalid pointers.

  6. #6
    Registered User
    Join Date
    Feb 2008
    Posts
    4

    Re: Using a variable exported by a dll in a local variable: crash

    Quote Originally Posted by wizard_hu_ View Post
    You should click on "5" (I guess that testexe.exe is the code you are experimenting with). KERN-EXEC 3 is often related to accessing NULL/invalid pointers.
    Yes testexe.exe is the code I am experimenting with. The code is available in my first comment (see testexe.c).

    When I click on "5", Carbide does not open any code. Other lines don't open any code either, except "4" that print an error message because the source file is not available on my computer (uc_exe.cpp is not part of my project).

    But I know it is because of the "mystruct_t *f[1] = {myvar};" line because if I remove it, it works.

    I explained in my first comment how to change that line to get it work, but I would like to know the explanation.

Similar Threads

  1. GoogleIt
    By deepika.mangla in forum Symbian
    Replies: 5
    Last Post: 2011-05-28, 11:04
  2. DLL exported APIs
    By mabdulmoniem in forum Symbian
    Replies: 5
    Last Post: 2007-10-31, 12:35
  3. Replies: 3
    Last Post: 2007-07-31, 19:27
  4. Error:When Exported function of dynamically loaded DLL is called
    By nokia_forum_chandru in forum Symbian Tools & SDKs
    Replies: 0
    Last Post: 2007-07-31, 12:51
  5. Replies: 2
    Last Post: 2006-09-26, 03:58

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×