chklib: print function pointer as a pointer, gcc 4.4 warning
[reactos.git] / rosapps / applications / sysutils / chklib / chklib.c
1 /* $Id$
2 *
3 * chklib.c
4 *
5 * Copyright (C) 1998, 1999 Emanuele Aliberti.
6 *
7 * --------------------------------------------------------------------
8 *
9 * This software is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
13 *
14 * This software is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public
20 * License along with this software; see the file COPYING. If
21 * not, write to the Free Software Foundation, Inc., 675 Mass Ave,
22 * Cambridge, MA 02139, USA.
23 *
24 * --------------------------------------------------------------------
25 * Check a PE DLL for loading and get an exported symbol's address
26 * (relocated).
27 *
28 */
29 //#define UNICODE
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <assert.h>
33
34 #include <stdarg.h>
35 #include <windef.h>
36 #include <winbase.h>
37
38 #include "win32err.h"
39
40 #ifdef DISPLAY_VERSION
41 static
42 void
43 DisplayVersion(
44 HANDLE dll,
45 PCHAR ModuleName
46 )
47 {
48 DWORD Zero;
49 DWORD Size;
50 PVOID vi = NULL;
51
52 assert(ModuleName);
53 Size = GetFileVersionInfoSize(
54 ModuleName,
55 & Zero
56 );
57 if (Size == 0)
58 {
59 PrintWin32Error(
60 L"GetFileVersionInfoSize",
61 GetLastError()
62 );
63 return;
64 }
65 vi = (PVOID) LocalAlloc(LMEM_ZEROINIT,Size);
66 if (!vi) return;
67 assert(dll != INVALID_HANDLE_VALUE);
68 if (0 == GetFileVersionInfo(
69 ModuleName,
70 (DWORD) dll,
71 Size,
72 vi
73 )
74 ) {
75 PrintWin32Error(
76 L"GetFileVersionInfo",
77 GetLastError()
78 );
79 return;
80 }
81 /*
82 VerQueryValue(
83 vi,
84 L"\\StringFileInfo\\040904E4\\FileDescription",
85 & lpBuffer,
86 & dwBytes
87 );
88 */
89 LocalFree(vi);
90 }
91 #endif /* def DISPLAY_VERSION */
92
93
94 static
95 void
96 DisplayEntryPoint(
97 const HANDLE dll,
98 LPCSTR SymbolName
99 )
100 {
101 FARPROC EntryPoint;
102
103 printf(
104 "[%s]\n",
105 SymbolName
106 );
107 EntryPoint = GetProcAddress(
108 dll,
109 SymbolName
110 );
111 if (!EntryPoint)
112 {
113 PrintWin32Error(
114 L"GetProcAddress",
115 GetLastError()
116 );
117 return;
118 }
119 printf(
120 "0x%p %s\n",
121 EntryPoint,
122 SymbolName
123 );
124 }
125
126
127 /* --- MAIN --- */
128
129
130 int
131 main(
132 int argc,
133 char * argv []
134 )
135 {
136 HINSTANCE dll;
137 TCHAR ModuleName [_MAX_PATH];
138
139 if (argc < 2)
140 {
141 fprintf(
142 stderr,
143 "\
144 ReactOS System Tools\n\
145 Check a Dynamic Link Library (DLL) for loading\n\
146 Copyright (c) 1998, 1999 Emanuele Aliberti\n\n\
147 usage: %s module [symbol [, ...]]\n",
148 argv[0]
149 );
150 exit(EXIT_FAILURE);
151 }
152 dll = LoadLibraryA(argv[1]);
153 if (!dll)
154 {
155 UINT LastError;
156
157 LastError = GetLastError();
158 PrintWin32Error(L"LoadLibrary",LastError);
159 fprintf(
160 stderr,
161 "%s: loading %s failed (%d).\n",
162 argv[0],
163 argv[1],
164 LastError
165 );
166 exit(EXIT_FAILURE);
167 }
168 GetModuleFileName(
169 (HANDLE) dll,
170 ModuleName,
171 sizeof ModuleName
172 );
173 printf(
174 "%s loaded.\n",
175 ModuleName
176 );
177 #ifdef DISPLAY_VERSION
178 DisplayVersion(dll,ModuleName);
179 #endif
180 if (argc > 2)
181 {
182 int CurrentSymbol;
183
184 for ( CurrentSymbol = 2;
185 (CurrentSymbol < argc);
186 ++CurrentSymbol
187 )
188 {
189 DisplayEntryPoint( dll, argv[CurrentSymbol] );
190 }
191 }
192 FreeLibrary(dll);
193 printf(
194 "%s unloaded.\n",
195 ModuleName
196 );
197 return EXIT_SUCCESS;
198 }
199
200 /* EOF */