FreeBASIC  0.91.0
sys_dylib.c
Go to the documentation of this file.
1 /* Dynamic library loading functions */
2 
3 #include "../fb.h"
4 #include <windows.h>
5 
7 {
8  void *res = NULL;
9 
10  if( (library) && (library->data) )
11  res = LoadLibrary( library->data );
12 
13  /* del if temp */
14  fb_hStrDelTemp( library );
15 
16  return res;
17 }
18 
19 FBCALL void *fb_DylibSymbol( void *library, FBSTRING *symbol )
20 {
21  void *proc = NULL;
22  char procname[1024];
23  int i;
24 
25  if( library == NULL )
26  library = GetModuleHandle( NULL );
27 
28  if( (symbol) && (symbol->data) )
29  {
30  proc = (void*) GetProcAddress( (HINSTANCE) library, symbol->data );
31  if( (!proc) && (!strchr( symbol->data, '@' )) ) {
32  procname[1023] = '\0';
33  for( i = 0; i < 256; i += 4 ) {
34  snprintf( procname, 1023, "%s@%d", symbol->data, i );
35  proc = (void*) GetProcAddress( (HINSTANCE) library, procname );
36  if( proc )
37  break;
38  }
39  }
40  }
41 
42  /* del if temp */
43  fb_hStrDelTemp( symbol );
44 
45  return proc;
46 }
47 
48 FBCALL void *fb_DylibSymbolByOrd ( void *library, short int symbol )
49 {
50  void *proc = NULL;
51 
52  if( library == NULL )
53  library = GetModuleHandle( NULL );
54 
55  proc = (void*) GetProcAddress( (HINSTANCE) library, MAKEINTRESOURCE(symbol) );
56 
57  return proc;
58 }
59 
61 {
62  FreeLibrary((HINSTANCE) library);
63 }