Answer the question
In order to leave comments, you need to log in
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
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)
You need to make .lib
the file yourself. See if the bundled .dll
file contains a .def
. If so, you can get it .lib
with
lib.exe /DEF:mylib.def mylib.dll
lib.exe /DEF:mylib.def /OUT:mylibname.lib mylib.dll
dll
+ def
), it is distributed, for example, sqlite3
. .def
there is no -file, see what symbols you have in the library throughdumpbin /exports mylib.dll
.def
basically 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./EXPORT: entryname[= internalname][,@ ordinal[, NONAME]][, DATA]
lib.exe
usually 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. 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);
Thanks to those who have already replied! Now I will experiment. I'll post the results.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question