Read configuration file using only unmanaged C++ - c++

I have an unmanaged Visual C++ project. I need to use a section defined in app configuration file without using any managed assembly.
Is there a library that comes with Visual Studio 2010 installation that can be used for this purpose?
If no such library comes with Visual Studio 2010, I suppose I will have to use a library that supports reading of XML files into memory and performing an XPath query. Which stable libraries support XML and XPath operations?

See C++ library for storing settings in XML for libraries which can read settings in XML files.
If you want something which comes with MSVC, I think the closest you get is using MSXML via a COM interface. But you will need to install the msxml redist on the target machine if it is not already installed. Maybe take a look at these 6 posts.

Do you mean the conventional windows config file (ini)? Libconfig might be helpful, http://gnuwin32.sourceforge.net/packages/libconfig.htm

Related

Precompiled SQLite x64 without .net

I needed SQLite for Win x64 to use in the C++ project in MS VS 2010. And I found this post with the link to x64 build, but it needs .net framework. Can I use in the my project? Also, I am about to use automated building on server side in this project, so it can be a problem to meet additional requirements (does it?).
So, does anyone have a link to precompiled SQLite DLL for x64 or I need to build it from sources? Also, if I am wrong about .net version and it is the one I need, let me know, please.
There is no official precompiled 64-bit Windows DLL of SQLite.
However, compiling it yourself is trivial: just download the amalgamation and add the .c file to your project; there are no additional configuration steps or requirements.
If you do not wish to link the library statically (or compile it directly into your application as suggested in the only answer available here so far), you can use the short tutorial I created recently. The binaries are available there as well if you need them. It uses MS VS 2015. A long time passed since your original question, but maybe someone else can find this useful.
Edit: As somebody stated below, simply providing the link is not enough, so just briefly the basics of the tutorial: You have to download the amalgamation source code from the original SQLite page and you can compile dll from it in your visual studio, but crucial is to set proper pre-processor directives for the compiler:
SQLITE_ENABLE_FTS4=1
SQLITE_ENABLE_RTREE=1
SQLITE_ENABLE_COLUMN_METADATA=1
SQLITE_API=__declspec(dllexport)
Especially last one is the one which makes your library usable. This information is not mentioned in the original instructions for building the library from the sources using the Microsoft toolchain.

Linking to and using libpq with Visual C++ Express 2010

I am trying to access from Visual C++ 2010 Express a Postgres database. I have both on my machine but the SQL calls do not work at all. I have searched many sites. I think that this version of Express does not have any default database connections like the non-express version (especially Visual C++ 2008).
The only thing I could find was the following link and I have following the modifications to the Project Properties area of Visual C++ Express.
http://www.askyb.com/cpp/c-postgresql-example/
When I try to run the C++ code in that website I get errors indicating that it cannot find the functions.
Do you have any ideas of what I am doing wrong? Would it be better for me to use something other than Visual C++ Express 2010 to connect to a postgres db? One of the other Express versions? The regular (non-express) Visual C++?
Thanks
You may also be interested in libpqtypes and libpqxx if you're working with PostgreSQL and libpq. The first provides greatly simplified access to data values from libpq, and the latter provides a more C++-friendly interface.
As for the errors, most likely:
Your include path or link library path is wrong if it's failing at compile-time or link time; or
Your PATH doesn't include libpq, if it's failing at runtime.
Most likely (you didn't provide any actual error messages) the problem is your setup. You need to add the correct header ("include") directory and library directory; if you just copied them from some tutorial, make sure they actually point to the real place where these files (.h and .lib files, respectively) are.
You need do recompile the libpq with MSVC (nmake /f win32.mak all), after that, you need to set your project to use that library, and change the Common Language Runtime Support to (/clr) and not to clr/pure.

How to build C++ project embed all dynamic link library in exe file?

everybody, I am getting started develop a C++ project and in this project I must use some opensource project have several dll file. Then I have a question "How to build C++ project embed all dynamic link library in exe file?"
Thank for help!
Note: Sorry, I forgot that I'm using visual studio compiler on x86
There is no general answer to your question. It depends whether you need it to be cross platform or not.
However, since you're mentioning "visual studio compiler on x86", I bet you're targeting Windows. In such a case you have two options:
the official and recommended way: embed your dlls as resources in your executable; then when your program starts you extracts these dlls somewhere on the disk as temporary files (beware file permissions) then you use LoadLibrary + GetProcAddress
the hackish way: you write a PE executable loader in order to circumvent the fact that the Windows API only offers a way to LoadLibrary from a file on disk. By writing your own PE loader you'll be able to load a dll directly from a memory stream. Then again, I'm just mentioning it for reference but it's by no means something one should do
Finally, you need to comply to the license chosen by those opensource projects you're using. My answers gives technical directions about how to achieve your goal; it doesn't mean the license of the project you're using allows you to do so.

Read multiple files

I'm new to c++ and am trying to alter the console app code posted below to read multiple files, ideally using a wildcard extension. Can some please give me some pointers..?
http://msdn.microsoft.com/en-us/library/ms916815#odc_wssusageeventlogging_examiningtheusagelogfileformat
-----------Edit-------
What I need is how to change the code above instead of pointing it to a specific [filename.log] point it to a directory name and let it process all the log files in that directory.
--------------Tools-----
Win32 Console Application project in Visual Studio 2010 in C++
[To be run on win 32 bit platform]
Using Win32 APIs you can list the files in a directory by following this example. From there it should be relatively trivial for you to incorporate that code into your application to allow you to process multiple files as requested.
Specifically the FindFirstFile API allows for wildcard when search for files.
If you're willing to use the boost library check out
this post. If you're using something like C++/CLI then there is support in .NET for this as well (I'm assuming for now you're not using C++/CLI). If you specify the tools at your disposal maybe you can get a more directed answer.

How do I zip a directory of files using C++?

I'm working on a project using C++, Boost, and Qt. I understand how to compress single files and bytestreams using, for example, the qCompress() function in Qt.
How do I zip a directory of multiple files, including subdirectories? I am looking for a cross-platform (Mac, Win, Linux) solution; I'd prefer not to fire off a bunch of new processes.
Is there a standard way to combine bytestreams from multiple files into a zipped archive, or maybe there is a convenience function or method that would be available in the Boost iostream library?
Many thanks for the assistance.
Update: The QuaZip library looks really great. There is an example in the download package (in the "tests" dir) that shows very clearly how to zip up a directory of files.
Update 2: After completing this task on my Linux build environment, I discovered that QuaZip doesn't work at all with the Visual Studio compiler. It may be possible to tackle all those compiler errors, but a word of caution to anyone looking down this path.
I have found the following two libraries:
ZipIOS++. Seems to be "pure" C++. They don't list Windows explicitly as a supported platform. So i think you should try your luck yourself.
QuaZIP. Based on Qt4. Actually looks nice. They list Windows explicitly (Using mingw). Apparently, it is a C++ wrapper for [this] library.
Ah, and of course, i have ripped those sites from this Qt Mailinglist question about Zipping/Unzipping of directories :)
Just for the record...
Today, I needed to do something very similar in Visual C++. (Though wanted to maintain the possibility to compile the project on other platforms; however preferred not to adopt Qt just for this purpose.)
Ended up using the Minizip library. It is written in plain C, but devising a simple C++ wrapper around it was a breeze, and the end result works great, at least for my purposes.
I have built a wrapper around minizip adding some features that I needed and making it nicer to use it. Is does use the latest c++11 and is developed using Visual Studio 2013, so it should work out-of-the-box for you.
There's a full description here: https://github.com/sebastiandev/zipper
you can zip entire folders, streams, vectors, etc. Also a nice feature is doing everything entirely in memory.
Poco::Zip is also a choice, it has clearly documentation and some code for demo.
Poco::Zip Document
system("zip myarchive.zip *");
I tried QuaZIP 0.4.3 on Windows with VisualStudio 2010 -- there are still issues but can be resolved easily.
To build with VS:
Use CMake to configure and generate VS solution for QuaZIP.
Open soltion with VS and build -- you'll first notice that it can't find 'zlib.h'.
Open preferences for quazip project and add path to Qt's copy of Zlib to C/C++->General->Additional Include Directories: $(QTDIR)/src/3rdparty/zlib.
Rebuild again and you'll get lots of warnings and one error C2491: dllimport static issue on QuaZipFile::staticMetaObject.
This is because QuaZipFile is declared like "class QUAZIP_EXPORT QuaZipFile" and QUAZIP_EXPORT needs to resolve to Q_DECL_EXPORT for dll and to Q_DECL_IMPORT for application, based on whether QUAZIP_BUILD is defined or not. When building QuaZIP QUAZIP_BUILD should be defined but isn't -- configuration process defines in error completely useless "quazip_EXPORTS" instead.
To fix, just remove "quazip_EXPORTS" from all build configurations and add QUAZIP_BUILD instead -- QuaZIP will now build fine.