C++ compiler reading data from .db file stored in .lib - c++

I have a decent understanding of C#. I've been asked to make a SDK along with our program so that a customer can make his own UI using our functions. In C#, I did this by adding a DLL. I had to use a database file (.db) to hold commands, and it went successfully. Now I've been asked to do the same in C++. I'm very new to C++. But here's what I read from MSDN and did:
I created a library project.
Added database as a resource file, sqlite3 header file and library file(I got from giving lib command on command prompt).
Created a header file with functions and wrote in a .cpp file with all function definitions.
Built it and got the library file from lib command.
So far, so good. Now when I try to use this library file and header, I'm getting the following errors during build time.
error C2059: syntax error : '<'
error C2018: unknown character '0x7'
error C2018: unknown character '0x60'
error C2018: unknown character '0x7'
error C2018: unknown character '0x2'
error C2018: unknown character '0x1e'
error C2018: unknown character '0x18'
I struggled with this for sometime when I remembered that these errors were the same I got a few days ago. I actually asked the question in SE and got the answer (Error while including database file in C++ project).
So I inferred that the compiler is trying to read the database file saved in the library file and hence I got these errors.
Now I have three questions:
Am I right? Is the compiler trying to read the .db file stored in .lib file?
If so, can anyone please give any suggestions
Also, if you think I'm wrong, I would appreciate any other explanations.
I'm using Visual Express C++ 2010. I used command prompt that comes with Visual Studio to create .lib file. My reference for creating .lib file was https://msdn.microsoft.com/en-us/library/ms235627.aspx#BKMK_CreateAppToRefTheLib.

A database file cannot be stored in a static library file to be deployed. Because the compiler ALWAYS reads through the contents of the library. It shows that its reading this when you are building the program.
So what to do if you have to issue a database with your SDK? I have two solutions:
Add database file with your .lib file and .h file and just flat out give a glossary of commands with the SDK. (I however do not advise this)
Change the extension of database file and write methods in .lib file calling database using sqlite3 functions. Give the user a glossary of functions that you wrote with function names masked so that they dont know its a database file in play. The database file need not have .db extension for sqlite to recognize it. Just give sqlite_open and include database name as database.bhjbkhj (where bhjbkhj is a random extension you wrote). Sqlite is very good in this regard at recognising databases.
So there you go. Problem cannot be solved. But two alternatives.

Related

Import .tlb, Generated .tlh Gives: forward declaration of enum type is nonstandard

I'm reusing a code I wrote couple years ago on a different version of Visual Studio, now Im trying to do it in VS 2017. The code aims to connect different applications using server-client arrangement.I'm accessing the .tlb of one application but I cannot establish the connection (either error of non-accessible .tlh or just no identification of different application methods/properties) , among 254 others.
The question is similar to this one: Import .TLB file gives "cannot open source file x.tlh"
I have tried adding the .tlb file in additional library directories but even when the error disappears, the code still doesnot recognize many methods that were fine before. #import statement shows no errors, yet the generated .tlh file has the following error:
forward declaration of enum type is nonstandard
Hence, It doesnot compile
Other issues also appeared, such as this:
no instance of function template "IID_PPV_ARGS_Helper" matches the argument list
for this line:
HRESULT hr = hyStream->QueryInterface(IID_PPV_ARGS(&Strm));
Now, the whole project was running seamlessly back then. I copied three classes with their headers to a new project, so maybe dependencies are the source of errors? Should I add .tlb file in library dependencies of the project?
Any comment is highly appreciated..

Are these files incorrect or am I behaving incorrectly?

I am trying to use c++ files I downloaded from the internet in my visual studio 2015 project.
From here: https://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=26203 if you scroll down the files about 85% there is a zip file called galsource.zip. Underneath the zip it shows the file that is contained in the zip. I extract that to the cpp project in file explorer and try this include statement:
#include "GeneticLibrary/source/StopCriterias.h"
As far as I known, just using an include statement should not stop a project from being able to be built but when I try to run a simple hello world project with that (or any other file in that GeneticLibrary folder) import it does not build and throws dozens of errors, such as;
Severity Code Description Project File Line Suppression State
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int GeneticTesting c:\users\richard\documents\visual studio 2015\projects\genetictesting\genetictesting\geneticlibrary\source\algorithmoperations.h 73
Severity Code Description Project File Line Suppression State
Error C3646 '_valueType': unknown override specifier GeneticTesting c:\users\richard\documents\visual studio 2015\projects\genetictesting\genetictesting\geneticlibrary\source\stopcriterias.h 160
Severity Code Description Project File Line Suppression State
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int GeneticTesting c:\users\richard\documents\visual studio 2015\projects\genetictesting\genetictesting\geneticlibrary\source\stopcriterias.h 160
I can't image the files I downloaded just don't work so I assume I'm doing something wrong. Any help would be really appreciated.
As far as I known, just using an include statement should not stop a project from being able to be built
That is where the problem is. If you are working with a package (or a library) you can't (generally) just pick one include file. There are usually more dependencies between include files. For instance if you try to build a Windows application and just use the single windows.h file with no other supporting files - you'll get tons of errors. However I'd imagine the first errors you'd get would be about missing include files.
Instead of "viewing" the files in the browser you should download the whole library and work with the complete source code.
You can get the full source code from the same site, just a different link: https://www.codeproject.com/KB/recipes/geneticlibrary/galsource.zip

error C4335 when compile C++ project VS2012

I have a C project that i am able to compile and run successfully, however when i add another include like #include <vector> even without actually using the vector type i am getting the following annoying errors:
1>c:\program files (x86)\microsoft visual studio11.0\vc\include\wchar.h : error C4335: Mac file format detected: please convert the source file to either DOS or UNIX format
and around 30 more errors related to the same wchar.h file.
I have search for a solution and i have done the suggestion to save my project files with the windows end-of-line but that didn't help.
My goal in including the vector lib is to uses vectors in my current project.
EDIT:
I tried to open the wchar.h file using text editor but all i get is a blob of data nothing like an header file, maybe it is corrupted somehow?
Thanks.
Or open wchar.h in Notepad++ -> Edit -> EOL Conversion -> Windows format.
Here you can get Notepad++: http://notepad-plus-plus.org/
If you don't have it, get it. It is a must have application on every programmers PC.
After repairing the VS 2012 install it works as it should, i assume that the wchar.h file got corrupted.
The file wchar.h is not in the right encoding, probably it is Unicode or UTF8.
Open wchar.h from visual studio, select all and copy, create a new h file and past and save to replace the exsiting wchar.h

.obj : fatal error LNK1107: invalid or corrupt file: cannot read at 0x6592

I am trying to load an .obj model into my c++ opengl 3 code but for some reason it gives me this error :
1>Linking...
1>.\bunny.obj : fatal error LNK1107: invalid or corrupt file: cannot read at 0x6592
I tried to search for similar errors, but there were about .dll's or .lib's.
Can you please help me out with this issue. I have also tried with different obj models but it always gives me this error.
You are trying to load your object model with a C++ linker (probably you have just added it to the project, and now it tries to be compiled).
The linker can process .obj files, but it waits them to be 'object-code' files (which also often have .obj extension), which are just compiled modules (e.g. written in C++ language) ready to be linked into a single executable or DLL.
Neither part of a C++ compiler is able to read graphical object model. You should remove the .obj file from your IDE project. And make sure you have a code that reads the file when the program runs.
If you want the object model to be embedded into your .EXE (so the program would not require the file in its directory), then you can put it into resources and link them with the executable.
I had the same problem and resolved it by excluding the .obj file from the build. In other words:
Right click your .obj file.
Click 'Properties
Set 'Exclude from Build' to 'Yes'

Header file throwing errors in one project, but not in another

I'm trying to integrate two projects, and to that end am including header files from one into the other. I'm using visual studio 2008 express.
The line
int E4407B_PPM(int &);
is throwing errors in the new project, but the original project compiles just fine.
The error I'm getting:
error C2143: syntax error : missing ')' before '&'
Any ideas?
Edit: I ended up removing the lines that took parameters in by reference, and just insured that all functions were declared before they were used in the actual source file. I guess it was a C++/C thing.
You are probably building the second project (or at least the source file) as straight C. Make sure the file has a .cpp extension or that you are forcing a C++ compile (you can use the /TP compile option to do that).
Edit You can specify it for a single file: Right click on the file in the solution explorer and select Properties. Click on the Advanced option under C/C++. Choose "Compile as C++ Code (/TP)" (second option in the page in my version of Visual Studio).