home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
lpathext.zip
/
lpathext.INF
(
.txt
)
< prev
next >
Wrap
OS/2 Help File
|
2001-12-11
|
21KB
|
760 lines
ΓòÉΓòÉΓòÉ 1. Copyright and Notices ΓòÉΓòÉΓòÉ
IBM and OS/2 are registered trademarks of International Business Machines Corp.
ΓòÉΓòÉΓòÉ 1.1. OS/2 LIBPATH Extension Manipulation Functions ΓòÉΓòÉΓòÉ
COPYRIGHT AND LICENSING INFORMATION
This suite of subroutines is freeware, distributed as is, without any warranty
of its usefulness for any purpose. You may use it freely. You may also
redistribute it, provided no charge is levied beyond the price of its
distribution medium.
However, the author retains all intellectual property rights.
Copyright (C) David W. Noon, 2001.
OBTAINING TECHNICAL SUPPORT
You can obtain technical support via Internet e-mail, Compuserve, or FidoNet
Netmail. My addresses are as follows.
Internet: dwnoon@os2bbs.com
dwnoon@ntlworld.com
dwnoon@compuserve.com
dnoon@acm.org
Compuserve: 72172,431
FidoNet: David Noon 2:257/609
David Noon 1:109/347
The first FidoNet mailbox and the Internet mailboxes I check almost every day.
The second FidoNet mailbox and the Compuserve mailbox are checked once or
twice a week.
Turn-around time on problems might not be spectacular, especially if I have
other issues to handle. This is freeware and you should expect no more than
you pay for.
ΓòÉΓòÉΓòÉ 2. Preparing these Functions for your Development Environment ΓòÉΓòÉΓòÉ
The subroutines and functions supplied here are offered as complete source
code. I have also included compiled libraries prepared using the EMX+GCC
compiler, release 0.96d fixpack #4. Unless you are using this same set-up, you
will need to compile these functions with your chosen C/C++ compiler. This
detail I must leave to you.
I am assuming that you are familiar with your chosen compiler's usage of
environment variables to handle its header file and static link library
resolution.
Once you have suitable libraries built, copy the lpathext.h file to a directory
that is in your compiler's INCLUDE directory list. For the Watcom compiler,
this will be the OS2_INCLUDE directory list. For EMX+GCC this will be the
C_INCLUDE_PATH and CPLUS_INCLUDE_PATH directory lists; a directory that occurs
in both would be the ideal location.
You should also copy the lpathext.lib file to a directory that is in your
linker's LIB directory list. If you are using EMX+GCC you will need also to
copy lpathext.a to a directory in the LIBRARY_PATH list.
You might also care to copy this file, lpathext.inf, to a directory that is in
your BOOKSHELF directory list.
ΓòÉΓòÉΓòÉ 3. The Two Extensions to LIBPATH for DLL Loading ΓòÉΓòÉΓòÉ
There are two buffer areas, each 1024 bytes in size, that are provided in each
OS/2 address space for directory lists that can be searched to resolve requests
to load DLLs. One directory list is searched before the main LIBPATH list is
searched; this is the pre-system extension. The other list is searched after
the LIBPATH list has failed to yield a matching DLL name; this is the
post-system extension.
The purposes of these two extensions are quite straightforward:
The pre-system extension is used when you definitely want to override any
default system library with an application-specific library.
The post-system extension is used when you want to proved some lowest common
denominator library as a last resort, but expect the user to have installed
some like-named library with more specific functionality, typically as some
form of customization, into a LIBPATH directory.
You should also be aware that the OS/2 loader performs a lookaside of
already-loaded modules for a matching basename before scanning LIBPATH or
either of its extensions. This means that if some other application has already
loaded a DLL with matching basename, all your attempts to direct the loading
process will be for nought. There is only one way to overcome this problem: You
must specify a fully qualified path/filename, complete with extension, to the
DosLoadModule() API instead of supplying just the basename. While this is not
the idiomatic way to load a library, it is the only way around the basename
lookaside issue. If you choose obscure basenames for your dynamic libraries
then you will usually avoid the problem. A quick scan through the x:\OS2\DLL
directory will give you a hint on what basenames to avoid; a look through
x:\MMOS2\DLL will provide you with more basenames to avoid.
The purpose of these library routines is to remove the constraint of changing
your current working directory during execution and thereby losing the ability
to load DLLs through the "dot" entry in the LIBPATH list, as well providing the
override and fallback features of the basic extensions.
Constraint: These extensions only take effect after the API or library call
has been made. If you use linker fix-ups from an import library, the DLL(s)
required for those must be present in the LIBPATH (or the shell's LIBPATH
extensions) before the program starts; so these routines will provide you with
no help there. The intent of these routines is for those who use DLL technology
in the fullest sense of the adjective "dynamic", using the DosLoadModule() API
or some wrapper function.
ΓòÉΓòÉΓòÉ 4. The Subroutines ΓòÉΓòÉΓòÉ
These subroutines are fairly thin wrappers on the DosQueryExtLIBPATH() and
DosSetExtLIBPATH() API calls. You need to be aware that these API calls were
not added to OS/2 until version 2.11, so any code that uses these routines will
not run under OS/2 2.1 or earlier.
You should also be aware that calling these routines will not affect in any way
the values of the surrounding shell's BEGINLIBPATH and ENDLIBPATH environment
variables. In fact, once you start using these routines you should forget all
about those environment variables, as they were always just an ugly kludge.
[That is not to say that this library is not a kludge too. It just isn't as
ugly as the environment variable approach.]
ΓòÉΓòÉΓòÉ 4.1. set_beginlibpath ΓòÉΓòÉΓòÉ
This subroutine sets the pre-system LIBPATH extension to the directory in which
the executable that started the address space resides.
Syntax
Parameters
Returned results
Remarks
ΓòÉΓòÉΓòÉ <hidden> set_beginlibpath Syntax ΓòÉΓòÉΓòÉ
unsigned long set_beginlibpath(void);
Example of set_beginlibpath
#include "lpathext.h"
int main(int argc, char ** argv)
{
/* Add program directory to LIBPATH */
if (set_beginlibpath() != 0)
{
fputs("Unable to set LIBPATH extension.", stderr);
return EXIT_FAILURE;
}
/* Rest of program */
}
ΓòÉΓòÉΓòÉ <hidden> set_beginlibpath Parameters ΓòÉΓòÉΓòÉ
This function takes no parameters.
ΓòÉΓòÉΓòÉ <hidden> set_beginlibpath Returned results ΓòÉΓòÉΓòÉ
This function normally returns zero. Any other value indicates an error
returned by the DosSetExtLIBPATH() API, but these should never occur.
ΓòÉΓòÉΓòÉ <hidden> set_beginlibpath Remarks ΓòÉΓòÉΓòÉ
If the directory path in which the main executable resides ends with a final
node of BIN (case-insensitive) then a check is made to see if there exists an
otherwise identical directory path that ends in DLL instead. If so, then this
DLL directory path is used instead for the pre-system LIBPATH extension.
For example, if your program is H:\Site_software\bin\Program_1.exe then the
directory path is H:\Site_software\bin. If the directory path
H:\Site_software\dll exists then that is used to set the LIBPATH extension,
otherwise the H:\Site_software\bin path is used.
ΓòÉΓòÉΓòÉ 4.2. set_endlibpath ΓòÉΓòÉΓòÉ
This subroutine sets the post-system LIBPATH extension to the directory in
which the executable that started the address space resides.
Syntax
Parameters
Returned results
Remarks
ΓòÉΓòÉΓòÉ <hidden> set_endlibpath Syntax ΓòÉΓòÉΓòÉ
unsigned long set_endlibpath(void);
Example of set_endlibpath
#include "lpathext.h"
int main(int argc, char ** argv)
{
/* Add program directory to LIBPATH */
if (set_endlibpath() != 0)
{
fputs("Unable to set LIBPATH extension.", stderr);
return EXIT_FAILURE;
}
/* Rest of program */
}
ΓòÉΓòÉΓòÉ <hidden> set_endlibpath Parameters ΓòÉΓòÉΓòÉ
This function takes no parameters.
ΓòÉΓòÉΓòÉ <hidden> set_endlibpath Returned results ΓòÉΓòÉΓòÉ
This function normally returns zero. Any other value indicates an error
returned by the DosSetExtLIBPATH() API, but these should never occur.
ΓòÉΓòÉΓòÉ <hidden> set_endlibpath Remarks ΓòÉΓòÉΓòÉ
If the directory path in which the main executable resides ends with a final
node of BIN (case-insensitive) then a check is made to see if there exists an
otherwise identical directory path that ends in DLL instead. If so, then this
DLL directory path is used instead for the post-system LIBPATH extension.
For example, if your program is H:\Site_software\bin\Program_1.exe then the
directory path is H:\Site_software\bin. If the directory path
H:\Site_software\dll exists then that is used to set the LIBPATH extension,
otherwise the H:\Site_software\bin path is used.
ΓòÉΓòÉΓòÉ 4.3. query_beginlibpath ΓòÉΓòÉΓòÉ
This subroutine queries the pre-system LIBPATH extension into a buffer supplied
by the caller.
Syntax
Parameters
Returned results
Remarks
ΓòÉΓòÉΓòÉ <hidden> query_beginlibpath Syntax ΓòÉΓòÉΓòÉ
unsigned long query_beginlibpath(char * buffer_area);
Example of query_beginlibpath
#include "lpathext.h"
int main(int argc, char ** argv)
{
char buffer_area[1024];
/* Retrieve current LIBPATH extension */
if (query_beginlibpath(buffer_area) != 0)
{
fputs("Unable to query LIBPATH extension.", stderr);
return EXIT_FAILURE;
}
/* Rest of program */
puts(buffer_area);
.
.
.
}
ΓòÉΓòÉΓòÉ <hidden> query_beginlibpath Parameters ΓòÉΓòÉΓòÉ
There is only one parameter for this function.
buffer_area (char [])
Needs to be as large as the current pre-system LIBPATH
extension string, including a trailing semi-colon and a
trailing NUL. A length of 1024 will always be safe.
ΓòÉΓòÉΓòÉ <hidden> query_beginlibpath Returned results ΓòÉΓòÉΓòÉ
This function normally returns zero. Any other value indicates an error
returned by the DosQueryExtLIBPATH() API, but these should never occur.
ΓòÉΓòÉΓòÉ <hidden> query_beginlibpath Remarks ΓòÉΓòÉΓòÉ
For some stupid reason, the API always adds a trailing semi-colon even though
it is totally redundant.
ΓòÉΓòÉΓòÉ 4.4. query_endlibpath ΓòÉΓòÉΓòÉ
This subroutine queries the post-system LIBPATH extension into a buffer
supplied by the caller.
Syntax
Parameters
Returned results
Remarks
ΓòÉΓòÉΓòÉ <hidden> query_endlibpath Syntax ΓòÉΓòÉΓòÉ
unsigned long query_endlibpath(char * buffer_area);
Example of query_endlibpath
#include "lpathext.h"
int main(int argc, char ** argv)
{
char buffer_area[1024];
/* Retrieve current LIBPATH extension */
if (query_endlibpath(buffer_area) != 0)
{
fputs("Unable to query LIBPATH extension.", stderr);
return EXIT_FAILURE;
}
/* Rest of program */
puts(buffer_area);
.
.
.
}
ΓòÉΓòÉΓòÉ <hidden> query_endlibpath Parameters ΓòÉΓòÉΓòÉ
There is only one parameter for this function.
buffer_area (char [])
Needs to be as large as the current post-system LIBPATH
extension string, including a trailing semi-colon and a
trailing NUL. A length of 1024 will always be safe.
ΓòÉΓòÉΓòÉ <hidden> query_endlibpath Returned results ΓòÉΓòÉΓòÉ
This function normally returns zero. Any other value indicates an error
returned by the DosQueryExtLIBPATH() API, but these should never occur.
ΓòÉΓòÉΓòÉ <hidden> query_endlibpath Remarks ΓòÉΓòÉΓòÉ
For some stupid reason, the API always adds a trailing semi-colon even though
it is totally redundant.
ΓòÉΓòÉΓòÉ 4.5. clear_beginlibpath ΓòÉΓòÉΓòÉ
This subroutine sets the pre-system LIBPATH extension to an empty string.
Syntax
Parameters
Returned results
Remarks
ΓòÉΓòÉΓòÉ <hidden> clear_beginlibpath Syntax ΓòÉΓòÉΓòÉ
unsigned long clear_beginlibpath(void);
Example of clear_beginlibpath
#include "lpathext.h"
int main(int argc, char ** argv)
{
/* Remove LIBPATH extension */
if (clear_beginlibpath() != 0)
{
fputs("Unable to clear LIBPATH extension.", stderr);
return EXIT_FAILURE;
}
/* Rest of program */
}
ΓòÉΓòÉΓòÉ <hidden> clear_beginlibpath Parameters ΓòÉΓòÉΓòÉ
This function takes no parameters.
ΓòÉΓòÉΓòÉ <hidden> clear_beginlibpath Returned results ΓòÉΓòÉΓòÉ
This function normally returns zero. Any other value indicates an error
returned by the DosSetExtLIBPATH() API, but these should never occur.
ΓòÉΓòÉΓòÉ <hidden> clear_beginlibpath Remarks ΓòÉΓòÉΓòÉ
This function removes all entries from the pre-system LIBPATH directory list.
This includes any that might have been put there by the shell from its
BEGINLIBPATH environment variable.
ΓòÉΓòÉΓòÉ 4.6. clear_endlibpath ΓòÉΓòÉΓòÉ
This subroutine sets the post-system LIBPATH extension to an empty string.
Syntax
Parameters
Returned results
Remarks
ΓòÉΓòÉΓòÉ <hidden> clear_endlibpath Syntax ΓòÉΓòÉΓòÉ
unsigned long clear_endlibpath(void);
Example of clear_endlibpath
#include "lpathext.h"
int main(int argc, char ** argv)
{
/* Remove LIBPATH extension */
if (clear_endlibpath() != 0)
{
fputs("Unable to clear LIBPATH extension.", stderr);
return EXIT_FAILURE;
}
/* Rest of program */
}
ΓòÉΓòÉΓòÉ <hidden> clear_endlibpath Parameters ΓòÉΓòÉΓòÉ
This function takes no parameters.
ΓòÉΓòÉΓòÉ <hidden> clear_endlibpath Returned results ΓòÉΓòÉΓòÉ
This function normally returns zero. Any other value indicates an error
returned by the DosSetExtLIBPATH() API, but these should never occur.
ΓòÉΓòÉΓòÉ <hidden> clear_endlibpath Remarks ΓòÉΓòÉΓòÉ
This function removes all entries from the post-system LIBPATH directory list.
This includes any that might have been put there by the shell from its
ENDLIBPATH environment variable.
ΓòÉΓòÉΓòÉ 4.7. append_beginlibpath ΓòÉΓòÉΓòÉ
This concatenates the supplied list of directories to end of the pre-system
LIBPATH extension.
Syntax
Parameters
Returned results
Remarks
ΓòÉΓòÉΓòÉ <hidden> append_beginlibpath Syntax ΓòÉΓòÉΓòÉ
unsigned long append_beginlibpath(const char * buffer_area);
Example of append_beginlibpath
#include "lpathext.h"
int main(int argc, char ** argv)
{
APIRET rc;
HMODULE lib_handle;
char buffer_area[1024];
strcpy(buffer_area, "X:\\ThisApp\\DLL");
/* Extend further the current LIBPATH extension */
if (append_beginlibpath(buffer_area) != 0)
{
fputs("Unable to extend LIBPATH extension.", stderr);
return EXIT_FAILURE;
}
/* Rest of program */
rc = DosLoadModule(buffer_area, sizeof buffer_area, "DYNALIB", &lib_handle);
.
.
.
}
ΓòÉΓòÉΓòÉ <hidden> append_beginlibpath Parameters ΓòÉΓòÉΓòÉ
There is only one parameter for this function.
buffer_area (const char [])
The list of directories to be concatenated onto the end of
the current pre-system LIBPATH extension.
ΓòÉΓòÉΓòÉ <hidden> append_beginlibpath Returned results ΓòÉΓòÉΓòÉ
This function normally returns zero. Any other value indicates an error
returned by the DosSetExtLIBPATH() API. The most likely error values to be
returned are 8 (ERROR_NOT_ENOUGH_MEMORY) and 161 (ERROR_BAD_PATHNAME).
ΓòÉΓòÉΓòÉ <hidden> append_beginlibpath Remarks ΓòÉΓòÉΓòÉ
The directory names should be fully qualified and built into a string,
separated by semi-colons, just one would when coding the LIBPATH list in
CONFIG.SYS. You do not need a trailing semi-colon.
See also the prepend_beginlibpath() function.
ΓòÉΓòÉΓòÉ 4.8. append_endlibpath ΓòÉΓòÉΓòÉ
This concatenates the supplied list of directories to end of the post-system
LIBPATH extension.
Syntax
Parameters
Returned results
Remarks
ΓòÉΓòÉΓòÉ <hidden> append_endlibpath Syntax ΓòÉΓòÉΓòÉ
unsigned long append_endlibpath(const char * buffer_area);
Example of append_endlibpath
#include "lpathext.h"
int main(int argc, char ** argv)
{
APIRET rc;
HMODULE lib_handle;
char buffer_area[1024];
strcpy(buffer_area, "X:\\ThisApp\\DLL");
/* Extend further the current LIBPATH extension */
if (append_endlibpath(buffer_area) != 0)
{
fputs("Unable to extend LIBPATH extension.", stderr);
return EXIT_FAILURE;
}
/* Rest of program */
rc = DosLoadModule(buffer_area, sizeof buffer_area, "DYNALIB", &lib_handle);
.
.
.
}
ΓòÉΓòÉΓòÉ <hidden> append_endlibpath Parameters ΓòÉΓòÉΓòÉ
There is only one parameter for this function.
buffer_area (const char [])
The list of directories to be concatenated onto the end of
the current post-system LIBPATH extension.
ΓòÉΓòÉΓòÉ <hidden> append_endlibpath Returned results ΓòÉΓòÉΓòÉ
This function normally returns zero. Any other value indicates an error
returned by the DosSetExtLIBPATH() API. The most likely error values to be
returned are 8 (ERROR_NOT_ENOUGH_MEMORY) and 161 (ERROR_BAD_PATHNAME).
ΓòÉΓòÉΓòÉ <hidden> append_endlibpath Remarks ΓòÉΓòÉΓòÉ
The directory names should be fully qualified and built into a string,
separated by semi-colons, just one would when coding the LIBPATH list in
CONFIG.SYS. You do not need a trailing semi-colon.
See also the prepend_endlibpath() function.
ΓòÉΓòÉΓòÉ 4.9. prepend_beginlibpath ΓòÉΓòÉΓòÉ
This concatenates the supplied list of directories to start of the pre-system
LIBPATH extension.
Syntax
Parameters
Returned results
Remarks
ΓòÉΓòÉΓòÉ <hidden> prepend_beginlibpath Syntax ΓòÉΓòÉΓòÉ
unsigned long prepend_beginlibpath(const char * buffer_area);
Example of prepend_beginlibpath
#include "lpathext.h"
int main(int argc, char ** argv)
{
APIRET rc;
HMODULE lib_handle;
char buffer_area[1024];
strcpy(buffer_area, "X:\\ThisApp\\DLL");
/* Extend further the current LIBPATH extension */
if (prepend_beginlibpath(buffer_area) != 0)
{
fputs("Unable to extend LIBPATH extension.", stderr);
return EXIT_FAILURE;
}
/* Rest of program */
rc = DosLoadModule(buffer_area, sizeof buffer_area, "DYNALIB", &lib_handle);
.
.
.
}
ΓòÉΓòÉΓòÉ <hidden> prepend_beginlibpath Parameters ΓòÉΓòÉΓòÉ
There is only one parameter for this function.
buffer_area (const char [])
The list of directories to be concatenated onto the start
of the current pre-system LIBPATH extension.
ΓòÉΓòÉΓòÉ <hidden> prepend_beginlibpath Returned results ΓòÉΓòÉΓòÉ
This function normally returns zero. Any other value indicates an error
returned by the DosSetExtLIBPATH() API. The most likely error values to be
returned are 8 (ERROR_NOT_ENOUGH_MEMORY) and 161 (ERROR_BAD_PATHNAME).
ΓòÉΓòÉΓòÉ <hidden> prepend_beginlibpath Remarks ΓòÉΓòÉΓòÉ
The directory names should be fully qualified and built into a string,
separated by semi-colons, just one would when coding the LIBPATH list in
CONFIG.SYS. You do not need a trailing semi-colon.
See also the apppend_beginlibpath() function.
ΓòÉΓòÉΓòÉ 4.10. prepend_endlibpath ΓòÉΓòÉΓòÉ
This concatenates the supplied list of directories to start of the post-system
LIBPATH extension.
Syntax
Parameters
Returned results
Remarks
ΓòÉΓòÉΓòÉ <hidden> prepend_endlibpath Syntax ΓòÉΓòÉΓòÉ
unsigned long prepend_endlibpath(const char * buffer_area);
Example of prepend_endlibpath
#include "lpathext.h"
int main(int argc, char ** argv)
{
APIRET rc;
HMODULE lib_handle;
char buffer_area[1024];
strcpy(buffer_area, "X:\\ThisApp\\DLL");
/* Extend further the current LIBPATH extension */
if (prepend_endlibpath(buffer_area) != 0)
{
fputs("Unable to extend LIBPATH extension.", stderr);
return EXIT_FAILURE;
}
/* Rest of program */
rc = DosLoadModule(buffer_area, sizeof buffer_area, "DYNALIB", &lib_handle);
.
.
.
}
ΓòÉΓòÉΓòÉ <hidden> prepend_endlibpath Parameters ΓòÉΓòÉΓòÉ
There is only one parameter for this function.
buffer_area (const char [])
The list of directories to be concatenated onto the start
of the current post-system LIBPATH extension.
ΓòÉΓòÉΓòÉ <hidden> prepend_endlibpath Returned results ΓòÉΓòÉΓòÉ
This function normally returns zero. Any other value indicates an error
returned by the DosSetExtLIBPATH() API. The most likely error values to be
returned are 8 (ERROR_NOT_ENOUGH_MEMORY) and 161 (ERROR_BAD_PATHNAME).
ΓòÉΓòÉΓòÉ <hidden> prepend_endlibpath Remarks ΓòÉΓòÉΓòÉ
The directory names should be fully qualified and built into a string,
separated by semi-colons, just one would when coding the LIBPATH list in
CONFIG.SYS. You do not need a trailing semi-colon.
See also the append_endlibpath() function.