Symbian3/SDK/Source/GUID-9D278187-8B5E-581D-9869-EE8861048F93.dita
changeset 2 ebc84c812384
parent 0 89d6a7a84779
equal deleted inserted replaced
1:25a17d01db0c 2:ebc84c812384
    17 a DLL at compile time, meaning that the linker will match the DLL's symbols
    17 a DLL at compile time, meaning that the linker will match the DLL's symbols
    18 (such as function names and variables) with references from the program and
    18 (such as function names and variables) with references from the program and
    19 ascertain the address within the DLL of the functions or variables. </p> <p>Alternatively
    19 ascertain the address within the DLL of the functions or variables. </p> <p>Alternatively
    20 a program can dynamically load a DLL into memory during execution, locate
    20 a program can dynamically load a DLL into memory during execution, locate
    21 the address of a symbol, use it and then unload the DLL. Traditionally and
    21 the address of a symbol, use it and then unload the DLL. Traditionally and
    22 for greater memory efficiency, Symbian platform links by ordinal, whereas
    22 for greater memory efficiency, the Symbian platform links by
    23 Unix-like operating systems link by name. The following sections provide example
    23 ordinal, whereas Unix-like operating systems link by name. The following sections
    24 code to illustrate how the DLL loader works with each operating system. </p><p>The
    24 provide example code to illustrate how the DLL loader works with each operating
    25 Symbian platform v9.3 kernel supports all functionalities of P.I.P.S. libraries
    25 system. </p><p>The Symbian platform v9.3 kernel supports all functionalities
    26 - referred to as "P.I.P.S.- ready". Pre v9.3 the kernel only supports the
    26 of P.I.P.S. libraries - referred to as "P.I.P.S.- ready". Pre v9.3 the kernel
    27 Symbian platform- standard ordinal lookup in DLLs; it does not support symbolic
    27 only supports the Symbian platform- standard ordinal lookup in DLLs; it does
    28 lookup. Thus the function <codeph>dlsym()</codeph> cannot be used with a symbolic
    28 not support symbolic lookup. Thus the function <codeph>dlsym()</codeph> cannot
    29 name. To overcome this restriction, pass the function's ordinal number as
    29 be used with a symbolic name. To overcome this restriction, pass the function's
    30 symbol parameter refer the library's list of exports (the DEF file) for the
    30 ordinal number as symbol parameter refer the library's list of exports (the
    31 function's ordinal number. For example, instead of: <codeph>dlsym(&amp;handle,
    31 DEF file) for the function's ordinal number. For example, instead of: <codeph>dlsym(&amp;handle,
    32 "foo")</codeph> use <codeph>dlsym (&amp;handle, "3")</codeph> where the function <codeph>foo()</codeph> has
    32 "foo")</codeph> use <codeph>dlsym (&amp;handle, "3")</codeph> where the function <codeph>foo()</codeph> has
    33 ordinal 3.</p> </section>
    33 ordinal 3.</p> </section>
    34 <section id="GUID-CCE3F3DC-307A-41F2-BAB4-523834C12E93"><title>Using shared
    34 <section id="GUID-CCE3F3DC-307A-41F2-BAB4-523834C12E93"><title>Using shared
    35 libraries in a Unix-like environment</title><p>The following code shows how
    35 libraries in a Unix-like environment</title><p>The following code shows how
    36 a shared library is dynamically loaded and used in a Unix-like environment
    36 a shared library is dynamically loaded and used in a Unix-like environment
    78 </codeblock><p>As an example, the <codeph>shareddll</codeph> might have a
    78 </codeblock><p>As an example, the <codeph>shareddll</codeph> might have a
    79 function such as:</p><codeblock xml:space="preserve">void printSum(int a, int b)
    79 function such as:</p><codeblock xml:space="preserve">void printSum(int a, int b)
    80     {
    80     {
    81     printf("Result is : %d\n", a + b);
    81     printf("Result is : %d\n", a + b);
    82     }</codeblock></section>
    82     }</codeblock></section>
    83 <section id="GUID-7C649A95-3F73-454B-AAD4-80889D6B34E3"><title>DLLs on Symbian
    83 <section id="GUID-7C649A95-3F73-454B-AAD4-80889D6B34E3"><title>DLLs on the
    84 platform(prior to v9.3)</title><p>Symbian platform programs uses the function
    84 Symbian platform(prior to v9.3)</title><p>Symbian platform programs uses the
    85 or variable's ordinal position within a DLL to link with DLLs. For example,
    85 function or variable's ordinal position within a DLL to link with DLLs. For
    86 implementing a shared DLL on Symbian platform could look like this:</p><codeblock xml:space="preserve">EXPORT_C void printSum(int a, int b)
    86 example, implementing a shared DLL on the Symbian platform could look like
       
    87 this:</p><codeblock xml:space="preserve">EXPORT_C void printSum(int a, int b)
    87     {
    88     {
    88     printf("Result is : %d\n", a + b);
    89     printf("Result is : %d\n", a + b);
    89     }</codeblock><p>Compiling this will generate a <filepath>.def</filepath> file,
    90     }</codeblock><p>Compiling this will generate a <filepath>.def</filepath> file,
    90 which contains the ordinals of each symbol in the DLL. For instance:</p><codeblock xml:space="preserve">EXPORTS
    91 which contains the ordinals of each symbol in the DLL. For instance:</p><codeblock xml:space="preserve">EXPORTS
    91     printSum @ 1 NONAME</codeblock><p>Here, the <filepath>.def</filepath> shows
    92     printSum @ 1 NONAME</codeblock><p>Here, the <filepath>.def</filepath> shows
   136 for the <xref href="GUID-51FB35C0-CFC2-357A-8ACA-FE7480C53AD3.dita"><apiname>dlopen()</apiname></xref> function is irrelevant and the library
   137 for the <xref href="GUID-51FB35C0-CFC2-357A-8ACA-FE7480C53AD3.dita"><apiname>dlopen()</apiname></xref> function is irrelevant and the library
   137 will be loaded immediately. So although <codeph>RTLD_LAZY</codeph> is the
   138 will be loaded immediately. So although <codeph>RTLD_LAZY</codeph> is the
   138 mode parameter in the example, it will behave just as <codeph>RTLD_NOW</codeph>.
   139 mode parameter in the example, it will behave just as <codeph>RTLD_NOW</codeph>.
   139 Also note that there is no facility to call any library constructor and destructor
   140 Also note that there is no facility to call any library constructor and destructor
   140 functions using <codeph>__attribute((constructor))</codeph> or <codeph>__attribute((destructor))</codeph>. </p></section>
   141 functions using <codeph>__attribute((constructor))</codeph> or <codeph>__attribute((destructor))</codeph>. </p></section>
   141 <section id="GUID-DEF804DF-CECC-4739-9ACD-24F46A945F6E"><title>DLLs on Symbian
   142 <section id="GUID-DEF804DF-CECC-4739-9ACD-24F46A945F6E"><title>DLLs on the
   142 platform (v9.3 onwards)</title><p>P.I.P.S. provides APIs from libdl to support
   143 Symbian platform (v9.3 onwards)</title><p>P.I.P.S. provides APIs from libdl
   143 dynamic lookup by name, which is used in Unix-like platforms, instead of the
   144 to support dynamic lookup by name, which is used in Unix-like platforms, instead
   144 native Symbian platform lookup by ordinal mechanism. Lookup by name is possible
   145 of the native Symbian platform lookup by ordinal mechanism. Lookup by name
   145 thanks to the new libdl, which in turn uses the existing <ph>RLibrary</ph> functions
   146 is possible thanks to the new libdl, which in turn uses the existing <ph>RLibrary</ph> functions
   146 to load and unload DLLs. </p><p>A symbol name lookup version of the dlsym()
   147 to load and unload DLLs. </p><p>A symbol name lookup version of the dlsym()
   147 function is provided, similar to UNIX®, which does not need any special treatment
   148 function is provided, similar to UNIX®, which does not need any special treatment
   148 (the example shown in the <b>Using Shared libraries in a Unix-like environment</b> section
   149 (the example shown in the <b>Using Shared libraries in a Unix-like environment</b> section
   149 will suffice). However, it is still necessary to generate the <filepath>.def</filepath> file
   150 will suffice). However, it is still necessary to generate the <filepath>.def</filepath> file
   150 for the DLL. The following sections provides a brief summary of the functionality
   151 for the DLL. The following sections provides a brief summary of the functionality