Seeing source code from a .dll or .lib file using dumpbin - c++

I have no prior experience with .dll or .lib files and I need to see the code of a function in these files. I don't know which one to look at, searching around in stackoverflow led me to dumpbin, and I can use dumpbin /EXPORTS to see the headers and the functions are there. But how can I see the actual code? Can I do it just via the console or do I have to download a separate program?
P.S: I use Visual Studio and these are C++ functions.
Any help would be appreciated.

Seeing the source code from a compiled file such as a .lib or .dll is nearly impossible since it is basically a compiled file.
By compilated the source code you will lose some information as comments and most code structure. So your library file don't have those informations anymore. However a few options are still possible.
Obvious first, if your library come from an open-source project you may find the source code by asking our dearest friend.
Depending of what you really want to do with this library, tools such as dumpbin, objdump or else can give you more information on your existing file by reading and decoding some part of the file (headers, table name).
Eventually, you can try to transform your binary into something more readable like assembly or pseudo source code using something like a disassembler or a decompiler although its result will not be the original code source.

Related

unable to build .dll after following the instructions

I guess this is a simple question since I don't have much information about creating dll's
I wanted to use the deprecated Qt PieMenu in a project, I found the source code here.
After I did the necessary changes to the source code, I needed to build a dll from the source file (because it's licensed under LGPL).
The INSTALL.TXT file explains the steps.However, I'm always getting a .lib file instead of the dll.
I have no idea what I'm missing because I'm following the instructions without much understanding the whole idea.
Any help is appreciated.

VS C++ Header files in production build output

I'm relearning C++ after many years of higher-level languages. I've been googling around in circles for a while now on this. One issue with googling for answers in C++... "how do I include .h in my build output" just returns a bunch of results on how the #include statement works (not quite what I was looking for google... thanks...).
In visual studio, when I run a build, the output folder contains
mydll.dll
mydll.tlb
mydll.xml
I know header files are required to import the DLL into another application, but I'm not sure on the process.
Do I just copy/paste the .h files into the output folder? What's the canonical way to automate this process in VS?
Is there some step I should be taking that adds them to the output?
Should I really be shipping it with multiple .h files, or is there some way I'm supposed to combine them into one large mydll.h file?
Am I correct in my understanding that .lib is only generated if something in my library is static?
Is there a good guide for creating a production build somewhere out there?
I appreciate the advice!

Error in finding the body of a function in VC++

I am new to programming with C++. So I am trying to inspect other's code to learn. I started inspecting a new prototype which has a function named myFcn. Its comment lines describe it requires mk.h, mk.lib and mk.dll files to be compiled. The project was successfully built. But when I go over the calling line of myFcn and press F12 (go to definition), the declaration prototype of myFcn appears and hitting again F12 does not bring me the body of the myFcn. I guess the function definition is in the mk.lib or mk.dll files. How can I find the body of the function?
EDIT 1:
If I had several dll and lib files, could I recognize the file that myFcn was compiled in?
It seems that the function you are trying to use is compiled in the library which you use.
The purpose of this system is to let people use your functions without the need for them to edit them or understand their source code. This means that the author of the library has written the function, and compiled it into a library (.dll, .lib and .h).
By including the .h file in your project, and linking the .lib at compilation and the .dll at runtime, you can use this function without the need to ever see more than the header file.
If you wish to understand the code of this function, go to their website, and see if they provide the full source code.
Edit based on edit of question: As far as I know there is no direct way to see which header file links to which library. It is possible to view which functions are in a certain library. On Linux this is the 'nm' command for .a files (gcc libraries). For Windows some methods are described here: How to view DLL functions?.
The function body is likely to be compiled, if then you can't see the source code of it.

VS 2012 C++: Can I use source instead of symbols to debug?

I'm currently writing a native extension for NodeJS. This is basically a dll that NodeJS will load when you ask for it.
I have VS2012 attached to the Node process. I want to debug into Node's code that does the loading.
I have the .cc and .h files for node, but there are no .pdb files that I can find. How can I set a breakpoint in the Node source?
UPDATE: I DO have a node.lib file. Can that be a replacement for a pdb?
UPDATE 2: Tangential, but for anyone specifically debugging NodeJS, Node actually DOES ship a pdb, available at http://nodejs.org/dist/v0.8.22/node.pdb (replace the version number with whatever version you're looking for).
Without a way to relate actual source code to assembly code, you cannot debug from source code. You need a pdb file.
Think of it that way: any compiler could have generated the code, and even if VS2012 compiler generated the code, there is no way VS could reverse engineer all the code generation phase to know to which source line a specific assembly command belongs. And with inlining and such, it even adds more difficulty to the task.
So any debugger cannot debug without debug symbols, it is just impossible to reverse assembly semantics into a higher level language semantics (you lose structural information during the compilation process). Otherwise, static analysis tools would be so easy to write.
Edit: .lib file does not include debug information either, just the necessary information to link against it. So you're out of luck too.

Add curses library to Visual Studio C++?

I'm trying to use the curses library on Microsoft's Visual Studio C++. I downloaded ncurses-5.9.tar.gz from http://www.gnu.org/software/ncurses/, and I unzipped the file. However, I can't find a .lib or a .dll file in the package. Without the .lib file, I don't know how to link my code in Visual Studio to the header files in the ncurses package. Do I need to move the header files to somewhere in my project?
Thanks for the help!
In a nutshell: you want Bill Gray's PDCurses. That fork is quite active. The "original" implementation is in
Bill McBrine's repo, with some activity going on. The two projects seem sadly to have diverged, though. The former has implemented a native Win32a GDI terminal window, while the latter only supports the native Windows console.
What you did is not how to use curses at all. What you have downloaded is source code, there are no binaries there at all - no .lib nor .dll files for any architecture. Not only that, but the source code can't be directly compiled either -- if you'd have added it to a C/C++ project, even on a Unix box, it wouldn't compile.
In order to compile, curses needs to have a configure script run, that generates some files, probably config.h, perhaps other source files, and makefiles.
Alas, all that is a moot point because curses is AFAIK a Unix library that really depends on Unix APIs being present. Any Windows ports are completely separate efforts.
See also Is ncurses available for windows?.