How to include a .h file correctly in VC++? - visual-studio-2010

I have a very simple C++/CLI window form program which is 100% working alright.
Since I want to add call internet explorer when I click a button on my window form, I add "ONE LINE of code" for testing purpose.
I add #include "Shellapi.h" under #pragma once. After that, VS gives me 500 lines of an error message.
My question is that I am only adding a .h file into my program. Why there will cause any problem? Do I miss something?
===========The first few lines of the error message===============
1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\Shellapi.h(56): error C2065: 'HDROP' : undeclared identifier
1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\Shellapi.h(56): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\Shellapi.h(59): error C2146: syntax error : missing ';' before identifier 'DECLSPEC_IMPORT'
1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\Shellapi.h(59): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\Shellapi.h(59): error C2146: syntax error : missing ';' before identifier 'UINT'
1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\Shellapi.h(59): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\Shellapi.h(59): error C2146: syntax error : missing ';' before identifier 'STDAPICALLTYPE'
1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\Shellapi.h(59): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

Several things:
You should #include <windows.h> in any windows program
You should include any system file - like shellapi.h - using brackets (<>) instead of quotes (""), e.g. #include <shellapi.h>
If you're compiling from the command line, it's a good idea to run "vcvars32.bat" (or equivalent) to set your command-line environment for Visual Studio.

I believe you forgot to #include <windows.h> before #include <shellapi.h>
Generally, (or atleast in my personal experiences), when you are bombarded with a wall of errors after including a header, your missing <windows.h> or some other header.

Related

Matlab mex command for building armaMex_demo.cpp in Armadillo in Windows

I am having troubles mex-ing armaMex_demo_cpp in Armadillo (armadillo-8.500.1) in Windows with Matlab (2018a).
So far I am trying the command:
>> mex -LC:\Users\Test\Documents\Armadillo\armadillo-8.500.1-mod_for_windows\include\armadillo -LC:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin\gfortran -IC:\Users\Test\Documents\Armadillo\armadillo-8.500.1-mod_for_windows\include armaMex_demo.cpp
and get the error messages (truncated):
Building with 'Microsoft Visual C++ 2017'.
Error using mex
armaMex_demo.cpp
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\random(31): error C4430: missing type specifier - int
assumed. Note: C++ does not support default-int
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\random(31): error C2146: syntax error: missing ';' before
identifier 'ARMA_USE_BLAS'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\random(31): error C2143: syntax error: missing ';' before
'{'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\random(31): error C2447: '{': missing function header
(old-style formal list?)
c:\users\test\documents\armadillo\armadillo-8.500.1-mod_for_windows\include\armadillo_bits/arma_rng_cxx11.hpp(28): error C2039: 'mt19937_64': is not a
member of 'std'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\atomic(42): note: see declaration of 'std'
c:\users\test\documents\armadillo\armadillo-8.500.1-mod_for_windows\include\armadillo_bits/arma_rng_cxx11.hpp(28): error C3083: 'mt19937_64': the symbol
to the left of a '::' must be a type
c:\users\test\documents\armadillo\armadillo-8.500.1-mod_for_windows\include\armadillo_bits/arma_rng_cxx11.hpp(28): error C2039: 'result_type': is not a
member of 'std'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\atomic(42): note: see declaration of 'std'
c:\users\test\documents\armadillo\armadillo-8.500.1-mod_for_windows\include\armadillo_bits/arma_rng_cxx11.hpp(28): error C3646: 'seed_type': unknown
override specifier
Does any one have any ideas of what I may be doing wrong here?
Anybody have a working mex command for building the mex file for armaMex_demo.cpp in Windows?
Seems to have something to do with how I am including/referencing to BLAS. I used to have the line '#define ARMA_USE_BLAS' uncommented in config.hpp. By leaving it commented I, with this mex command:
mex -LC:\Users\Test\Documents\Armadillo\armadillo-8.500.1-mod_for_windows\include\armadillo -LC:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin\gfortran -IC:\Users\Test\Documents\Armadillo\armadillo-8.500.1-mod_for_windows\include armaMex_demo.cpp
I only get this error:
Building with 'Microsoft Visual C++ 2017'.
Error using mex
armaMex_demo.cpp
C:\Users\Test\Documents\Armadillo\armadillo-8.500.1-mod_for_windows\mex_interface\armaMex_demo.cpp(44): error C2668: 'arma::size': ambiguous call to
overloaded function
c:\users\test\documents\armadillo\armadillo-8.500.1-mod_for_windows\include\armadillo_bits/fn_size.hpp(38): note: could be 'const
arma::SizeMat
arma::size(const T1 &)'
with
[
T1=arma::mat
]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\xutility(1654): note: or 'arma::uword
std::size(const _Container &)'
with
[
_Container=arma::mat
]
C:\Users\Test\Documents\Armadillo\armadillo-8.500.1-mod_for_windows\mex_interface\armaMex_demo.cpp(44): note: while trying to match the argument list
'(arma::mat)'
And by changing the line
if ( size(X) != size(Y) )
to
if ( X.size() != Y.size() )
in armaMex_demo.cpp
the mexing (and the mex call) works in Windows from Matlab.

NodeJS Windows node-gyp build fails

Anything I try to npm install on windows that requires node-gyp explodes in errors. I tried reinstalling all the windows stuff suggested on the node-gyp github page.
Why am I getting these errors? This is an attempt to install mongodb
PS C:\Users\Farzher\Documents\Dev\nodejs\abc> npm install mongodb
npm WARN package.json prelude-ls-extended#0.0.0 No description
npm http GET https://registry.npmjs.org/mongodb
npm http 304 https://registry.npmjs.org/mongodb
npm http GET https://registry.npmjs.org/bson/0.2.5
npm http GET https://registry.npmjs.org/kerberos/0.0.3
npm http 304 https://registry.npmjs.org/bson/0.2.5
npm http 304 https://registry.npmjs.org/kerberos/0.0.3
> kerberos#0.0.3 install C:\Users\Farzher\node_modules\mongodb\node_modules\kerberos
> (node-gyp rebuild 2> builderror.log) || (exit 0)
C:\Users\Farzher\node_modules\mongodb\node_modules\kerberos>node "c:\Program Files\nodejs\node_modules\npm\bin\node-gyp-
bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
kerberos.cc
worker.cc
security_credentials.cc
security_buffer.cc
security_buffer_descriptor.cc
security_context.cc
c:\users\farzher\node_modules\mongodb\node_modules\kerberos\lib\win32\worker.h(17): error C2146: syntax error : missing
';' before identifier 'request' [C:\Users\Farzher\node_modules\mongodb\node_modules\kerberos\build\kerberos.vcxproj]
c:\users\farzher\node_modules\mongodb\node_modules\kerberos\lib\win32\worker.h(17): error C4430: missing type specifier
- int assumed. Note: C++ does not support default-int [C:\Users\Farzher\node_modules\mongodb\node_modules\kerberos\bui
ld\kerberos.vcxproj]
c:\users\farzher\node_modules\mongodb\node_modules\kerberos\lib\win32\worker.h(17): error C4430: missing type specifier
- int assumed. Note: C++ does not support default-int [C:\Users\Farzher\node_modules\mongodb\node_modules\kerberos\bui
ld\kerberos.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xlocale(323): warning C4530: C++ exception handler used,
but unwind semantics are not enabled. Specify /EHsc [C:\Users\Farzher\node_modules\mongodb\node_modules\kerberos\build
\kerberos.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xlocale(323): warning C4530: C++ exception handler used,
but unwind semantics are not enabled. Specify /EHsc [C:\Users\Farzher\node_modules\mongodb\node_modules\kerberos\build
\kerberos.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xlocale(323): warning C4530: C++ exception handler used,
but unwind semantics are not enabled. Specify /EHsc [C:\Users\Farzher\node_modules\mongodb\node_modules\kerberos\build
\kerberos.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xlocale(323): warning C4530: C++ exception handler used,
but unwind semantics are not enabled. Specify /EHsc [C:\Users\Farzher\node_modules\mongodb\node_modules\kerberos\build
\kerberos.vcxproj]
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\sspi.h(82): error C2146: syntax error : missing ';' before
identifier 'SEC_WCHAR' [C:\Users\Farzher\node_modules\mongodb\node_modules\kerberos\build\kerberos.vcxproj]
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\sspi.h(82): error C4430: missing type specifier - int assum
ed. Note: C++ does not support default-int [C:\Users\Farzher\node_modules\mongodb\node_modules\kerberos\build\kerberos.
vcxproj]
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\sspi.h(82): error C4430: missing type specifier - int assum
ed. Note: C++ does not support default-int [C:\Users\Farzher\node_modules\mongodb\node_modules\kerberos\build\kerberos.
vcxproj]
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\sspi.h(83): error C2146: syntax error : missing ';' before
identifier 'SEC_CHAR' [C:\Users\Farzher\node_modules\mongodb\node_modules\kerberos\build\kerberos.vcxproj]
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\sspi.h(83): error C4430: missing type specifier - int assum
ed. Note: C++ does not support default-int [C:\Users\Farzher\node_modules\mongodb\node_modules\kerberos\build\kerberos.
vcxproj]
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\sspi.h(83): error C4430: missing type specifier - int assum
ed. Note: C++ does not support default-int [C:\Users\Farzher\node_modules\mongodb\node_modules\kerberos\build\kerberos.
vcxproj]
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\sspi.h(86): error C2146: syntax error : missing ';' before
identifier 'SECURITY_STATUS' [C:\Users\Farzher\node_modules\mongodb\node_modules\kerberos\build\kerberos.vcxproj]
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\sspi.h(86): error C4430: missing type specifier - int assum
ed. Note: C++ does not support default-int [C:\Users\Farzher\node_modules\mongodb\node_modules\kerberos\build\kerberos.
vcxproj]
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\sspi.h(86): error C4430: missing type specifier - int assum
ed. Note: C++ does not support default-int [C:\Users\Farzher\node_modules\mongodb\node_modules\kerberos\build\kerberos.
vcxproj]
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\sspi.h(105): error C2143: syntax error : missing ';' before
'*' [C:\Users\Farzher\node_modules\mongodb\node_modules\kerberos\build\kerberos.vcxproj]
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\sspi.h(105): error C4430: missing type specifier - int assu
med. Note: C++ does not support default-int [C:\Users\Farzher\node_modules\mongodb\node_modules\kerberos\build\kerberos
.vcxproj]
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\sspi.h(105): error C2378: 'SEC_CHAR' : redefinition; symbol
cannot be overloaded with a typedef [C:\Users\Farzher\node_modules\mongodb\node_modules\kerberos\build\kerberos.vcxpro
You need Python on your machine for gyp to work, AFAIK.

Connecting DB2 from Node.js on Windows-platform

I am currently mirroring the DB2 to local MySQL-db with some jdbc-code. I would like to connect DB2 directly from Node.js app without having to query the mirror. I am running on Windows and I cannot change to Linux. It seems that work on DB2 with Node.js is yet very marginal or node-odbc is used (unixODBC bindings for node).
I found this project https://github.com/herzi/db2.js which provides DB2-bindings for Node but I cannot install it as the install fails. The package requires Node-gyp (installed this successfully) and .NET framework SDK. I set the vcbuild.exe into my PATH. After these the msbuild.exe complained about missing header files (sqlcli1.h, sqlsystm.h, sqlca.h), which I found out are part of PRO*C.
I took the header files above from here: http://files.edin.dk/php/win32/dev/php_build/include/db2/ and put them into my Node's src/ directory. Now the compiler shows multiple errors.
Are there any other options when working with Windows to connect DB2 from Node.js app than try to get the above module to work?
Anyone able to help me out here? What are the steps to get the above module installed?
Thanks!
Errors shown:
C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\sqlext.h(30): error C2146 : syntax error : missing ';' before identifier 'SQLSTATE' [C:\IS\node\node_modules\db2\build\db2.vcxproj]
C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\sqlext.h(30): error C2146: syntax error : missing ';' before identifier 'SQLSTATE' [C:\IS\node\node_modules\db2\build\db2.vcxproj]
C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\sqlext.h(30): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [C:\IS\node\node_modules\db2\build\db2.vcxproj]
C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\sqlext.h(30): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [C:\IS\node\node_modules\db2\build\db2.vcxproj]
C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\sqlext.h(30): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [C:\IS\node\node_modules\db2\build\db2.vcxproj]
C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\sqlext.h(30): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [C:\IS\node\node_modules\db2\build\db2.vcxproj]
C:\Documents and Settings\tpaleniu\.node-gyp\0.8.12\src\sqlcli1.h(1501): error C2371: 'SQLTCHAR' : redefinition; different basic types [C:\IS\node\node_modules\db2\build\db2.vcxproj]
C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\sqlext.h(30) : see declaration of 'SQLTCHAR'
..\src\connection.cc(77): error C3861: 'snprintf': identifier not found
[C:\IS\node\node_modules\db2\build\db2.vcxproj]..\src\connection.cc(80): error C3861: 'snprintf': identifier not found [C:\IS\node\node_modules\db2\build\db2.vcxproj]
..\src\connection.cc(111): error C3861: 'bzero': identifier not found [C:\IS\node\node_modules\db2\build\db2.vcxproj]
..\src\connection.cc(208): error C3861: 'bzero': identifier not found [C:\IS\node\node_modules\db2\build\db2.vcxproj]
..\src\connection.cc(547): error C2057: expected constant expression [C:\IS\node\node_modules\db2\build\db2.vcxproj]
..\src\connection.cc(547): error C2466: cannot allocate an array of constant size 0 [C:\IS\node\node_modules\db2\build\db2.vcxproj]
..\src\connection.cc(547): error C2133: 'argv' : unknown size [C:\IS\node\node_modules\db2\build\db2.vcxproj]
It is true that node-odbc currently is currently meant only for use with unixODBC. But Daniel VerWeire is currently working on supporting node-odbc on Windows. I guess you need to wait a little while.
Praveen will have a post on it here as soon as it is available

Cannot compile 3D point viewer in Visual Studio 2008

Can someone help me ?I am trying to run the 3d point cloud viewer .However it shows me the following errors
Error 1 error C2144: syntax error : 'void' should be preceded by ';' c:\program files\microsoft sdks\windows\v6.0a\include\gl\gl.h 1152 Viewer
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\program files\microsoft sdks\windows\v6.0a\include\gl\gl.h 1152 Viewer
Error 3 error C2146: syntax error : missing ';' before identifier 'glAccum' c:\program files\microsoft sdks\windows\v6.0a\include\gl\gl.h 1152 Viewer
Error 4 error C2182: 'APIENTRY' : illegal use of type 'void' c:\program files\microsoft sdks\windows\v6.0a\include\gl\gl.h 1152 Viewer
Error 5 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\program files\microsoft sdks\windows\v6.0a\include\gl\gl.h 1152 Viewer
Error 6 error C2144: syntax error : 'void' should be preceded by ';' c:\program files\microsoft sdks\windows\v6.0a\include\gl\gl.h 1153 Viewer
Error 7 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\program files\microsoft sdks\windows\v6.0a\include\gl\gl.h 1153 Viewer
and so on ...
Beginning of my code is :
#include <cstdlib>
#include <GL/glut.h>
#include <cmath>
#include "arcball.h"
#include <vector>
#include <iostream>
#include <fstream>
using namespace std;
Can someone please tell me what is going wrong?
Well, the first reported error is on the first line that declares a function with the WINGDIAPI modifier. Apparently, this is declared in wingdi.h. However, I'm not sure if you're meant to #include that directly, or whether there's a more formal recommendation for compiling opengl code in the windows environment. I'll have a hunt around.
The page on MSDN discussing the necessary headers for OpenGL work are a bit vague, but I take:
The Windows functions that support Microsoft's implementation of OpenGL in Windows must include the header file Windows.h.
To mean that you ought to include windows.h first.
Really? If I create a blank C++ project in VS2008, create an empty cpp file, copy and paste your includes in, and hit compile, I get exactly the errors you described. If I change my includes to:
#include <cstdlib>
#include <windows.h>
#include <GL/gl.h>
#include <cmath>
#include "arcball.h"
#include <vector>
#include <iostream>
#include <fstream>
Then the first reported error I get is that it can't find "arcball.h" (hardly unexpected). Are you still getting the same errors once windows.h is included?

VS2010 Lots of errors when including standard libraries

When I include a standard library into my VS2010 project, I get a TON of errors like these (these errors were from adding in shellapi.h). I get similar errors when adding in something like Windows.h or Wininet.h or anything like that.
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(56): error C2065: 'HDROP' : undeclared identifier
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(56): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(59): error C2144: syntax error : 'int' should be preceded by ';'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(59): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(59): error C2146: syntax error : missing ';' before identifier 'STDAPICALLTYPE'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(59): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(59): error C2146: syntax error : missing ';' before identifier 'DragQueryFileA'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(59): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(59): error C2065: 'HDROP' : undeclared identifier
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(59): error C2146: syntax error : missing ')' before identifier 'hDrop'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(59): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(59): error C2059: syntax error : ')'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(61): error C2144: syntax error : 'int' should be preceded by ';'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(61): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ShellAPI.h(61): error C2086: 'int EXTERN_C' : redefinition
I'm sure this is just something to do with a project setting, but I have no idea what setting I need to change. Where should I begin?
UPDATE
The solution was to make sure that windows.h was loaded first. I did not know it was dependent on that. For future reference, where should I have looked to see that dependency?
I got these exact same errors when adding
#include <shellapi.h>
to one of my files. I solved the problem by adding
#include <windows.h>
directly before it.
(You've got to love - or rather, hate - Windows headers that don't #include the headers that they themselves require. If I did that in my own code I'd get yelled at by my superiors!)
This happens when one of your includes is broken, then you include a standard header, because your syntax error directly carries on. For example, if you forget a semi, then include another header, that header will report syntax errors. For this reason, you should always include "clean" headers like system headers first, then own-defined headers.

Resources