Saving a webpage to disk using C++ - c++

I've managed to download a "file" from the internet with the help of wininet library, but I can't seem to save a "webpage" i.e. something I can edit later on with a text editor or with ifstream.
In this case, what are the tools I should resort to? Can wininet save a webpage to disk? Should I consider cURL (though I haven't managed to download regular files due to lack of documentation of cURL)? Do I need to learn what's called socket programming?
NB: I'm on Windows, using MinGW but can switch to MSVC if necessary, I'm looking for source code in the webpage, eventually I'm after the text in a webpage.
Also, I am not familiar with any of the functions in wininet, curl, or sockets. What do I need to learn of these?
Any help is greatly appreciated!

If your program is going to run both on windows and unix, then use cURL. Otherwise, stick with MSVC and WinINet functions http://msdn.microsoft.com/en-us/library/windows/desktop/aa385473(v=vs.85).aspx It's much easier to use in terms of the efforts required to get your program running and distributed (esp. if you're not linking your program against cUrl statically. Otherwise, you'll need to take libcurl.dll everywhere your program runs on Windows). With WinINet, you simply need to include a header and a library to use the functions.
If you're going to use WinINet, refer to this code snippet: http://www.programmershelp.co.uk/showcode.php?e=57
Use the same code except for the while loop. Instead of reading one byte at a time, read them by chunks and write them to the output file handle.
If you're going to use cURL, refer to this post: Download file using libcurl in C/C++

Related

Trouble with reading JSON files in C++

I want to read data from a JSON file in C++, and I know there are several different libraries I can use. The problem is, I need to send the code to someone once it's done, and I need this person to be able to run the code in their IDE without installing anything.
All the JSON libraries in C++ require installation, so I don't know how to proceed. Any ideas?
Thank you

Raw Images, and DCRaw in C++

I want to be able to work with RAW images in C++ so I downloaded an already compiled DCRaw executable. I tried compiling it myself but I kept getting errors. So I want to be able to read in raw images to C++ and work with them. What would be the best way to do this? Should I find a way to include dcraw.c in my projects and call functions in that, or should I access the EXE file using the system(...) function?
If you don't want to manipulate the raw data directly in your application then yes you should use an already existing implementation of a raw image decoder (such as dcraw, like you said).
Here is what I would do in order of preference:
I would first try to find another raw image decoder that is available as a static or dynamic library version and link to that (dcraw only has an executable).
If #1 is not possible, I would extract the relevant parts of dcraw into a static library and link to that.
If not possible, I would include the .c file in my code like you have proposed.
I would only execute the EXE from within my program as a last resort.
That being said, if your application is for experimentation purposes only I don't see anything wrong in using the dcraw EXE from within your program. Otherwise I would not do this in a professional application.

Using cmd to transfer files via ftp

I was reading about this and found out most people use libcurl as the c++ library to use ftp, but I know windows has a built-in ftp client, isn't it possible to use that instead? I mean, it would also save a lot of space, even if you are just sending commands to the cmd, it could be done, but why does nobody do this? Is it like lazy programming or something? like akin to using goto?
If you need to up/download lots of files, handle errors, do progress etc then it's easier to use a library. If you simply need to pull a file from a remote server then the commandline tool is easier.
The windows ftp client can run a sequence of commands after logging in, but if you need this extra level of complexity it might be easier to use a library.

How to add a new row to Excel file using unmanaged C++?

How can I add a new row (with contents) to an existing Excel .xls file using unmanaged C++ running on Windows?
I don't mind using OLE, COM, or any external free library, whatever is the easiest way.
There is a COM interface which is well documented.
I'd suggest you start with the Workbooks.Open method to open an existing excel file.
If you only need basic features (no formatting, formula's, ...), you can also use BasicExcel: A c++ library which doesn't have any dependencies (it reads and writes the excel file as a compound file) and is much easier to use than the COM interface (at least from c++).
I've used SQL to do this. I don't have sample code handy, but a quick google search brought this up: Link
Hope its helpful.
If you have no restrictions to use managed libraries you can check NPOI, a managed library to handle Excel file format.
Since it is managed it should be possible to register it as a COM server. If, for any reason, it proves hard/impossible to register it as a COM server you can write a thin COM server (either in C++ or C# or whatever you prefer) to expose just the functionality you need to your unmanaged C++ code.
I've used this one: ExcelFormatLib, it's great and simple to use, C++, well maintained, compiles and works without any trouble.

Generating a C++ classes from IDL file using MICO (CORBA)

I wan to generate a C++ classes from a IDL file using MICO in the contxet of CORBA. I download the mico-2.3.13.zip but iI don't know how to use it. Please if someone can help me and thanks all.
The answer would probably be longer that would comfortably fit in a short reply, but here are some pages with helpful starter info.
This class webpage has a mini tutorial using mico
http://www.cs.wichita.edu/~chang/lecture/cs843/program/mico-idl.html
Here's another fairly simple tutorial page
http://people.inf.ethz.ch/roemer/micodoc/node16.html
You first need to compile MICO from the sources. Depending on your operating system and environment this will require different steps. In linux/mac os x they are basically calling the ./configure script and then make if it did not fail. Under windows I think that you can call nmake directly (with some options, read the README files).
After compilation completes (this may take a few minutes) and if everything goes fine, you should have the executables and can use them to create your own CORBA interfaces and services.