compilation error while #import tlb file in COM automation - c++

I am trying to #include an application tlb file in VC++ project.
Getting following compilation errors, after #import "CANoe.tlb" in my project source file. -
unknown character '0x1'
syntax error : missing ';' before identifier 'A'
missing type specifier
int assumed. Note: C++ does not support default-int
'{' : missing function header (old-style formal list?)
Please suggest, if I am doing some wrong.
Also, is there a way to verify the .tlb file contents and resolve these errors. Is it possible to make corrections in tlb file ? If so, how do I create a updated tlb
Thanks in advance

My first thought is that you are dealing with a file that is not a TLB. Or at least, is corrupted.
I would try and bring up the TLB in OleView. This should give you a quick sanity check that the TLB is or is not valid.

If the type library file is intact the next step is to try find the generated .tlh and .tli files - they will be located in some temporary folder and have the same name as type library file and ".tlh"/".tli" extensions. If they exist examining them might help a lot.
import directive does two things - it builds the ".tlh" and ".tli" files and then includes them - the error messages correspond to the second stage - when the C++ compiler just refuses to compile them. Examining the files will likely help identify the reason.

Related

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

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

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.

How to fix header file error?

So, my question is how to fix some error in header file, to run program normally? For example I use c++ builder 2010 and when winuser.h file is included, the program always get error like this
Checking project dependencies...
Compiling Project7.cbproj (Debug
configuration) [BCC32 Error]
winuser.h(47): E2257 , expected Full
parser context
File6.cpp(4): #include c:\program files (x86)\embarcadero\rad
studio\7.0\include\winuser.h [BCC32
Error] winuser.h(48): E2257 , expected
Full parser context
i try to replace that file with original from default installation, but that still get same error, how to fix that?
The error is almost certainly caused by whatever code appears before line 4 of File6.cpp. Most likely that is another header file, in which case it is likely that the code therein is malformed - a missing semicolon or brace for example.
The quickest way to verify that winuser.h is not the issue is to change the order of inclusion so that winuser.h is included first.
Another possibility is that something in winuser.h is dependent on some other header not previously included or directly included in winuser.h. Most Win32 API headers are included by windows.h, and it is generally advisable to include windows,h rather than either of its children.
The message is hard to read but the actual error is "E2257 , expected" (coma expected)
From the RAD studio documentation:
A comma was expected in a list of declarations, initializations, or parameters.
This problem is often caused by a missing syntax element earlier in the file
or one of its included headers.
The error message give you the line where it happened and you should probably look before that. There is probably some '}', ')' or ';' or other syntaxic closer missing in your code just before the error (likely before inclusion of the header file in your code). Full error message (you truncated it) or actual code would make it easier to spot.
It is also possible, even if unlikely, that the error is in one of the headers included in winuser.h.

Visual Studio 2008, error c2039: 'set_new_handler' : is not a member of 'std'

So the other day I went to compile a VC++ project I am working on and all of a sudden I get errors in almost all of my files saying:
new.h: error C2039: 'set_new_handler' : is not a member of 'std
new.h: error C2039: 'set_new_handelr' : symbol cannot be used in a using-declaration
"new.h" and 'set_new_handler' are not being used in any of my files, so I have no idea how or why these errors are suddenly appearing since they relate to a windows/VS library file.
Would anyone know what I can do to clear this error and compile my code again?
UPDATE After examining the files being included upon compilation, some files are including and some are . The problem is that is being included in afxwin.h and is being included in a third-party library. I honestly have no idea what to do with this problem...no other developers that have played with this code are running into this problem, may it be a settings problem? I am not using precompiled headers.
If I were to hazard a guess, I would say that <new.h> declares set_new_handler in the global namespace and <new> declares it within the std namespace. Some code is including <new.h> and expecting it to act as if it had included <new>. I would suspect either some 3rd party library/header or a precompiled header as suggested by Evan.
You can narrow down the culprit using either /showIncludes or pre-processing a source code file (using /E) and examining the output. I usually use the latter and look at the #line directives in the output file to figure out the include chain.
Good luck.

Error C2011: 'MSXML2::IXMLDOMImplementation' : 'struct' type redefinition

I am changing my C++ project, which was earlier in VC6 and now being migrated to VS 2008, to use MSXML 6 instead of the earlier MSXML 3.
When the code was in VC6 we were using MSXML3 by importing it
# import "msxml3.dll"
This was replaced with
# import "msxml6.dll"
After this when I compile the project I get this and several other similar errors
Error C2011: 'MSXML2::IXMLDOMImplementation' : 'struct' type redefinition
The above error is in the msxml3.tlh file.
1) Why is msxml3 still being used?
2) I narrowed down the problem to MSXML.h which is somehow automatically being included in my project. Why is this?
3) Which version of MSXML is being referenced in MSXML.h?
4) Why in the world does VC++ automatically include so many header files? What if I dont want some header files to be included?
5) What is the right way of using MSXML6 in a c++ project? #import, header file?????
6) How do I fix this problem?
Give me .net any time. Much cleaner. A VC++ project is a mess.
Check the syntax of the #import directive. You can rename imported elements using rename attribute on import directive (or rename_namespace). It will resolve conflicts with duplicated elements.
See here: in MSDN
Sometimes change of the inclusion order (yes - try different order of the include and import statements by commenting them out)
Don't fight with the MS mistakes, just cross them ;)
Have a look at the MS docoumentation on MSXML.
They suggest that importing the .dll as you have will create a couple of .thl and .tli files. Make sure you've deleted those.
Make sure any include directories point to the right place.
Make absolutely certain that you're not importing msxml3 somewhere else in your project.
To find the msxml.h do CTRL + SHIFT + F and search you entire solution for 'msxml' <- note the lack of the .h because if you'd been importing it properly, it ought to be done as follows:
#include <msxml6.dll>
Try some of that...
I'd try renaming msxml.h and doing a build. That should show you what file is including msxml.h.