M
M
Michael.2011-08-07 17:39:07
C++ / C#
Michael., 2011-08-07 17:39:07

Connecting a dll to a Visual Studio 2010 project (C++)

There is a library (*.dll) in which the functions are implemented. There is no lib file for this library, but there is a header file (*.h) with function declarations. You need to access these features.

I tried to make a lib file using the program: Implib.exe, but it writes an error (IM2603 - invalid .DLL file).

How can I access the functions of this library?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
K
kostik450, 2011-08-07
@kostik450

You do this:
lib.exe /DEF:test.def /OUT:test.lib /MACHINE:IX86
In the test.def file you need to write:
LIBRARY TEST
EXPORTS
[email protected] @1
Find out what numbers are there instead of @32, the easiest way is through errors links (the number in the function name is usually equal to the number of its parameters multiplied by 4), and what is there instead of @1 can be found through the dumpbin.exe utility from the list of functions exported from the DLL.
There are DLLs without @32 - it depends on how it was compiled via __cdecl or via __stdcall
(this is also easy to install experimentally)

M
MikhailEdoshin, 2011-08-07
@MikhailEdoshin

You need to make .libthe file yourself. See if the bundled .dllfile contains a .def. If so, you can get it .libwith

lib.exe /DEF:mylib.def mylib.dll

or
lib.exe /DEF:mylib.def /OUT:mylibname.lib mylib.dll

if you need another name. In this form ( dll+ def), it is distributed, for example, sqlite3.
If .defthere is no -file, see what symbols you have in the library through
dumpbin /exports mylib.dll

If these are practically the same names as in the header file, then the library is exporting C-style symbols; this is good. List all the names you want on the command line:
lib.exe /EXPORT:mylib_func1 /EXPORT:mylib_func2 mylib.dll
( -file .defbasically does the same thing.) The only thing I don't remember now is that underscores might be added to the names in front. I'm not sure if the names should be given with or without underscores.
If there are no names there, then they are cut off, functions can only be determined by their ordinal number. If there is any dregs around them, this is C ++, and dregs mean the encoded type of the parameters. This is all not very good, of course, because the correspondence of numbers to functions cannot be determined (unless experimentally), and there is no standard for coding. But it is technically possible to create a .lib file, the /EXPORT option has a full signature like this:
/EXPORT: entryname[= internalname][,@ ordinal[, NONAME]][, DATA]

That is, you can rename the function, and select it by number, and export the data. But this is for the last resort.
lib.exeusually not in PATH, you won't find it from the normal command line, but in the Visual Studio tools group there should be something like "Command Prompt" - it opens the console and adds the necessary paths to PATH so that the command line tools become available.
Links: dumpbin , lib .

Z
zed91, 2011-08-07
@zed91

You declare a pointer to a function (such as in the h-nick), and a variable of that type. Load the library (LoadLibrary) Then get the address of the function from the library using the "GetProcAddress" function, and assign this address to a variable of the function pointer type. Now the function can be called. The mechanism is called dynamic library loading. Like this:
typedef int (__stdcall somefuncptr*) (int, int); //not sure about this line
somefuncptr somefunc;
somefunc = GetProcAddress("dllfuncname");
intsomeval = somefunc(5, 10);

M
Michael., 2011-08-07
@kulinich

Thanks to those who have already replied! Now I will experiment. I'll post the results.

X
xanep, 2011-08-08
@xanep

Do you want to dynamically load the library? As zed91 wrote.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question