How can I extract a .tlb from a .exe - c++

I have a COM application that I want to use, but I only have the .exe from that app. Is there a way to extract the .tlb from that .exe?
I tried with tlbexp filename.exe from Visual Studio Command Prompt, but I get an error and I don't know why: TlbExp : error TX0000 : Exception of type 'System.OutOfMemoryException' was thrown.
I am using Visual Studio 2012 with C++.
Edit:
The .exe is in C++, later I saw that tlbexp is for .NET. This is why it didn't work, sorry for the confusion.
I still need to find a way to extract the .tlb from C++ .exe.

I have used this utility https://www.nirsoft.net/utils/resources_extract.html Just check the type libraries option.
It does now work on all cases but it works for many dlls and exe

Related

Having a C++ program build a Visual C++ project, without using system?

Basically, I have a program that generates a couple of .cpp files, which are included in a Visual Studio project. What I want is to have my program then tell Visual Studio to build that project, now that the .cpp files have been generated.
I can use system() to call MSBuild or devenv to do it. Those are both misbehaving at the moment but I can make them work. But ultimately, what I really want is to interface with Visual Studio/MSBuild directly in my C++ code, so I could do things like have it return the path to the output to me directly, or what have you.
Is there any way to do that? Every time I do a search on "building a Visual Studio project within C++" or similar, of course, I just get basic tutorials on setting up a project and building it through the IDE (or, at best, through the command line).
Use CreateProcess and use redirection of the stdout to pipe the output to a file. You can then programmatically read and evaluate this file.
MS example: http://support.microsoft.com/kb/190351
Maybe this helps: How do I redirect output to a file with CreateProcess?
you can run the generator from studio as a pre-build-event. that is the way MS think we should do it. additionally within a solution you can chain projects via dependency. again the MS style. alternativly you can do a real make system like CMake.
You can launch any command line from within .NET by using System.Diagnostics.Process.
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-1

How to use ActiveX dll in win32 C++ project visual studio 2010

Background: Vendor has provided me ActiveX Dll, no header files or .tlb file or anything such.
I am using Visual Stdio 2010 and using win32 C++.
The problem I am facing is how to load or reference dll?
I cannot reference the dll through solution explorer because it is unmanaged project.
When I try to use #import, it give me compile error saying XXX.tlb file not found. But I don't have .tlb type file.
The other option I tried was to open the dll with OLE viewer and copy the dll definitions and then paste in .idl extension file I created with Visual Studio. Then I executed midl on the idl file to create .h file but that did not help either. When I try use the classes, its gives me "abstract classes cannot be used or referenced" error.
There are other questions asked on the matter but not straight forward and the answers are not marked as answered or upvoted.
I want to know what are the different methods available to load the ActiveX dll in win32 C++ project in visual studio 2010 and which one should be preferred when? If there is a thread that actually addresses my issue please point me to that.
Thanks
If you are able to see the interface definitions using OLE View it means that the type library is embedded into the dll resources. So if you use #import "YourActiveX.dll" it should work.
You need
Register the COM (Active X) component in windows using regsvr32 : regsvr32 my_dll.dll
Then use COM to interact with the component. This is a good tutorial.

C++ parsing a text file that is located online

Information about what I want to do:
-read in a few integer variables from a text file that will be located on a dropbox public folder.
-the variables will be used to trigger some if statements thus controlling my application remotely if I need to have it do something ( I would just save the variable I need to that text file and my program with would read from it every 5 seconds would see it and perform the required actions).
-this is a console application which is being built and compiled in visual studio 2010 on windows 7. The software will also be running on a win7 computer.
I need help with:
I already have read on using a library called libcurl. The problem is that I do not know how to link this library with my project in vs2010. Detailed instructions on how to do this on vs 2010 would be very helpful.
OR
if you can think of a better and easier way to accomplish what I need done, offer some advice and direction
It sounds like you're a novice, is that correct? If not then apologies for stating the obvious.
To use your compiled DLL in your application you need to 'add a reference' to it. You can do this by adding what is called a binary reference, where you simply tell visual studio where to find the dll. Or you can add a project reference if the project which is producing the dll is within the same solution. The best approach is to use something called nuget. It's a visual studio extension which automates the adding of binary references available from a public repository.
I have just done a search for libcurl on nuget.org and drew a blank. As I am unfamiliar with this library you may have better luck finding a nuget package as you will be a le to search using better terms that I did (curl and libcurl)
Whatever approach you take, just right-click on the project in which you want to use libcurl within the solution explorer and you should find an add reference option in the menu.

C++ shift from Unix to Visual Studio in Windows

I am a professional working for a software firm.In my past company basically i was working on C & C++ on unix.Now i suddenly shifted to C++ on Windows and i feel like i am in a completely different world.Basically i am working on a very big application which was totally written in C++.To keep it simple ,i dont have the source code .I have the exe of the application and several other dependent files.it is a GUI application(several windows,reports,graphs and huge mathematical calculations are done by this application).Now i finally have the source code of the application which includes some headers,some vcproj files,some dsw files and several other which i dont even understand why the hell are they present.
Now as i C++ programmer my responsibility is to make all the BUGS that the clients identify replicate and fix them.
If its a bug on unix i can simply use the binary and source code and run gdb/dbx and find out the issue in some or other way like adding adding some printf statements.
But given the files i mentioned above.how could istart debugging an application in VC++ in VISUAL STUDIO.
Is it very difficult for a C++ programmer to shift from Unix to Windows.
Is ther any good resource which i could refer for this kind of change where i could grasp things quickly?
given the exe and the source code of the application how can i start debugging a program by running the application in VS C++-(BTW i am using VS 2005)
The main difference is that on Unix, you'll have Makefiles, which you won't find on Windows. Visual Studio organizes your code in projects and solutions, and those project files contain all the information VS needs to compile&link your projects.
If you have a *.sln file, just double click it to open it in VS. Then build the source (usually by pressing F6) and run in debug mode (usually F5).
More details:
A project is a collection of source files that result in 'something', usually a LIB, a DLL or an EXE.
A solution is a collection of projects. Useful when e.g. one project creates a LIB that is used by another project. When you set dependencies between projects, VS will build the projects in the right order.
Extensions used:
*.vcproj : Project file for C/C++ sources
*.vcproj..user : contains which windows are open in the GUI.
Can safely be deleted.
*.sln : Solution file
*.ncb : Intellisense database for a solution. Can safely be deleted.
*.suo : contains which windows are open in the GUI. Can safely be deleted.
*.dsw : Visual Studio 6.0 related file - not used in VS2005. (Replaced by *.sln IIRC)
./Debug/* : folder with all
intermediate files for a Debug build
(can be changed)
./Release/* : folder with all
intermediate files for a Release
build (can be changed)
That's all I can think of at the moment.
If you only have a .DSW file and not a .SLN file, then it means that the project was probably last worked on with VC6 and not one of the later Visual Studio versions.
That's a shame, because there have been lots of changes to the C++ compiler since VC6, and you're probably going to find the project doesn't compile with VS2005 without needing some minor changes to source code.
Do you have a .SLN file - if so, what's the version number at the top of the file (it's a text file)? If you don't have a .SLN file, can you get hold of VC6?
I would always try to get stuff going on an unfamiliar platform with the best matching tools, before I tried to bring it forward to later versions.
I understand your pain; I took the same path a few months ago.
You probably figured it out, but Visual Studio is not the exact alternative of gcc/g++. It embeds a text editor, a debugger, and so on.
Usually, you have two compilation "modes", debug and release. (you can add your own)
When in debug mode, all optimization are disabled and you can execute your program in the debugger, use step by step, add breakpoints, ...
Just start it using the F5 key.
More notes on the additional files:
In the Visual Studio world, .vcproj files represents "projects": a bunch of file that belongs to the same project (source files, headers, resources, ...).
A .dsw (old name for current .sln files I believe) is a "solution" file: a group of one or several projects which can have internal dependencies. Example: you can have in the same solution, a library and a software that depends on it. So that when you compile the whole solution, things are built in the correct order.
First thing you should try is to attach to the process while it's running (Ctr-Alt-P and select the process) if you have the .pdb (debug information) files you should be able to debug the process without re-building it.
If that fails try to un-check the "Require source files to exactly match the original version" option in Tools -> Options -> Debugging.
If that too fails you'll have to build the application again (by opening the .sln file and performing a build) so that the binary matches your source files.
Good luck.
Compile the code with debug info and press f5 (Start Debugging). I don't see where is the problem. On linux is sort of the same.
VS2005 can convert the dsw file for you to a sln file, but you need all of the original VC6 files in order for the conversion to be successful. For debugging please check out following msdn link, I hope this will help you.
http://msdn.microsoft.com/en-us/library/sc65sadd.aspx
Please select hyperlink "Debugging Native Code" for C++ specific.

Converting a Windows Dll to .lib for C++ Visual Studio 2008

I know there is a tool called Dll to lib but the developer is asking $1000.
I only need to convert one library, once, so its not easy to justify that price.
I tried IMPLIB32.EXE, but I just get empty .lib files.
How can I accomplish this?
Perhaps I can write a simple conversion app?
Added1:
The Dll's are typically stdcall not cdecl and written in older C like languages NOT C# or .NET or C++. I now need to call them from C++ apps. An example would be the SQLite.dll or zlib.dll.
I do not have access to the .lib files for these dll's.
Added2:
I re-wrote this code for VS2008
http://floodyberry.wordpress.com/2008/09/08/generating-dll-wrappers/
and included the example Dll etc downloadable here:
http://www.transferbigfiles.com/Get.aspx?id=7d86fa0b-6ddc-4f6f-8d31-2c20824aae9a
This in turn makes a project that creates a Dll. When I try to compile the Dll I get the linker error:
AddShow.dll : fatal error LNK1107: invalid or corrupt file: cannot read at 0x300
Described here:
http://list.isis.vanderbilt.edu/pipermail/udm-users/2006-March/000664.html
Not sure how to proceed. So close yet so far
Next we move to this method
http://www.coderetard.com/2009/01/21/generate-a-lib-from-a-dll-with-visual-studio/
Running dumpbin with the argument /exports C:\path\to\AddShow.dll
does absolutly nothing
After some research
http://msdn.microsoft.com/en-us/library/aa446532.aspx
it seems that mspdb71.dll (now mspdb80.dll) is needed from the common/ide folder
dumpbin.exe now runs with error:
fatal error LNK1106: invalid file or disk full: cannot seek to 0x6179A
These threads suggests the version of dumpbin.exe might be the issue
I have Microsoft (R) COFF/PE Dumper Version 9.00.30729.01
So I tried
Microsoft (R) COFF Binary File Dumper Version 5.12.8078
with no success.
After much reading I am no closer
http://support.microsoft.com/kb/815645
http://support.microsoft.com/kb/839286
http://markmail.org/message/p5vwzyfyv3bs6z34
http://fixunix.com/programmer/94825-fatal-error-lnk1106-invalid-file-disk-full.html
When I run ProcMon I see the first occurance of queryopen and sqlite3.dll when svchost.exe tries to open it and fails with the error PATH NOT FOUND. the path is C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\SQLITE3.DLL and is correct. If I put it at the root of the C drive then I get NAME NOT FOUND errors:
C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\link.exe.Local
C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\dumpbin.exe.Local
from link.exe and dumpbin.exe respectivly. Im using XPSP3 not Vista and this is about the limit of my knowledge of sysinternals. what are these .local files?
(csrss.exe is also not able to find a few manifest files.)
So no success yet, just more mystery
Added 3:
I tried to run dumpbin.exe from its installed location, \Program Files\Microsoft Visual Studio 8\VC\bin, but the OS said it couldn't find mspdb80.dll. I copied mspdb80.dll from \Program Files\Microsoft Visual Studio 8\Common7\IDE to try to get dumpbin.exe to run.
now I get the error:
"c1902 program database manager mismatch please check your installation"
If I remove mspdb80.dll from \Program Files\Microsoft Visual Studio 8\VC\bin the error goes away! but I can't run dumpbin.exe.
Added 4:
I was finally able to get dumpbin to run by copying the following files to a folder:
dumpbin.exe
link.exe
lib.exe
mspdb80.dll
I did get the error:
fatal error LNK1248: image size (FFFFFXXX) exceeds maximum allowable size
(80000000)
once, but replacing the dll fixed that. Presumably it got corrupted?
I then moved onto the next step in the instructions:
http://www.coderetard.com/2009/01/21/generate-a-lib-from-a-dll-with-visual-studio/
http://support.microsoft.com/kb/131313
and got the error:
warning lnk4017 statement not supported for the target platform ignored
This turns out to be because I specified the .dll instead of the .def file.
The resulting .Lib and .exp files are then added to the VS2008 project and compile and run. The debugger then reported an error:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call...
As mentioned here
"Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call" after successful C# callback from the C++ code of GameSpy lib
this is because I used stdcall in my dll and declared __cdecl in my app.
extern "C" { // put Dll C function prototypes here
int __cdecl AddTwoNum(int n, double f); // __stdcall
}
So changing this to __stdcall should fix it you would think.. but alas no.
now I get a linking error:
error LNK2001: unresolved external symbol _AddTwoNum#12
This is a decorated function name for some reason. Why?
Added n:
Well this turned out to be because the .lib file was made using a dll that with STDCALL functions. STDCALL requiers the caller to clean up the stack so the number of bytes of the arguments is appended to the function name with an # sign. IN this case I had three 4Byte iintegers for a total of 12 bytes.
Once I remade the .lib file from a dll created with the CDECL calling convention then all was good.
You can try using my .dll wrapper generator to create the stub .dll iain suggested.
I also found: this thread. Are you linking against the .dll instead of the .lib?
I am assuming you want to call some function/methods in a dll in C/C++ without having access to the lib file to link with it.
If you know the signatures of the functions you require, you can:
create your own stub version of the dll
create a dll project, with the same name as the dll you want to use
add stub implementations of the functions you want to call
the signatures are very important use depends.exe or dumpbin.exe to check they match.
then write/build your program to link to the stub dll
to run the program replace the stub dll with the real one
You could also go the dynamic way, using LoadLibrary() and GetProcAddress().
(See second link for an example).
In cases like zlib or sqlite you can download the source directly and compile your own lib file. In fact, I just did this the other day for zlib, I downloaded the source from www.zlib.net (direct zlib 1.2.3 download) opened the provided visual studio project file and compiled both a debug and release version of the lib. I haven't tried sqlite but seeing that they have the sources, it shouldn't be difficult to do.
If it's a proprietary dll, you could try asking the original developer or company for a lib file, or write your own stub dll that iain suggested or go the dynamic route that RaphaelSP.
If they are exported in C (no C++ name mangling) I would go the dynamic route myself.
I found this example rather quickly: http://www.coderetard.com/2009/01/21/generate-a-lib-from-a-dll-with-visual-studio/
This is supposedly a free tool that makes the conversion. I'm not sure if it's "free" as in "limited trial version" or not, the information is not very clear. If you've already tested this, edit your question and I'll delete this answer.
If you contact the developer of the Dll to lib tool they might be willing to give you a discount.
I've been in these situations before (where I needed an expensive tool just one time), and sometimes I have had success in getting a large discount.
It never hurts to try.
Good luck.
I have had success in getting a lib from DLL using details in http://wyw.dcweb.cn/dllfaq.htm. Your mileage might vary. I have used this to get a lib from python DLL to build some python extensions that are written in 'C'.
Open source edll has its own internal COFF loader. edll is written for quite different purposes, but since it has independent COFF loader within, maybe it's possible to incorporate your .dll into binary stream or resource inside your .exe, then in run-time use edll's COFF loader to load built-in dll.