Strange errors in Microsoft SDK using Shobjidl.h - c++

I want to retrieve the folder of the current user document folder in cpp, so I use SHGetFolderPath and include Shobjidl.h.
As the result my code does not compile and the following output is generated:
1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\shobjidl.h(8994): error C2143: syntax error : missing ')' before 'constant'
1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\shobjidl.h(8994): error C2143: syntax error : missing ';' before 'constant'
1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\shobjidl.h(8994): error C2059: syntax error : ')'
1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\shobjidl.h(8994): error C2238: unexpected token(s) preceding ';'
The code behind these errors is:
virtual HRESULT STDMETHODCALLTYPE GetInt32(
/* [in] */ __RPC__in REFPROPERTYKEY key,
/* [out] */ __RPC__out int *pi) = 0; // <- this line produces compile error
What's wrong? Thanks in advance.
I am using Win 7, VS2010 Express.

The header file you need to include for that function is Shlobj.h, according to the documentation, not Shobjidl.h. I'd guess that Shobjidl.h is likely an internal header file and not meant to be included directly -- it probably depends on other header files already being included before it, which would fix the errors you're seeing.

Related

OpenSSL - rsa.h error C2143: syntax error : missing ')' before 'constant'

I need to add SSL capability to an existing C++ socket client application. I've downloaded and installed OpenSSL, and the appropriate libs and includes are in my Visual Studio folder. Forgive the age of the dev environment (VC++ 6.0) but it's a legacy project, and only runs on Windows XP.
After adding this line:
// OpenSSL implementation for secure socket
#include <openssl/ssl.h>
To one of my header files, I now get this compile error:
c:\program files\microsoft visual studio\vc98\include\openssl\rsa.h(410) : error C2143: syntax error : missing ')' before 'constant'
c:\program files\microsoft visual studio\vc98\include\openssl\rsa.h(410) : error C2143: syntax error : missing ';' before 'constant'
c:\program files\microsoft visual studio\vc98\include\openssl\rsa.h(410) : fatal error C1004: unexpected end of file found
The line of the file causing the error is in rsa.h
int RSA_verify_PKCS1_PSS(RSA *rsa, const unsigned char *mHash,
const EVP_MD *Hash, const unsigned char *EM, int sLen);
Any ideas what could be causing this error?
Thanks

Winbase.h doesn't support in creating DLL file

I would like to create a project use to call c++ method using c#. So, I need to create a dll file for all of my c++ function. But when i get an error in y sqlite source code such as "AreFileApisASNSI undeclared identifier". So, i import winbase.h which is part of the mingw-w64 runtime package to my visual studio 2012 express DLL project. After import the file, I get many errors such as below:-
error c4430: missing type specifier - int assumed. Note: C++ does not support default - int
error C2143: syntax error : missing ';' before '_stdcall'
error c1003 error count exceeds 100; stopping compilation
error c2061: syntax error: identifier ' WINBOOL'
error c2086: 'int_CRT_INLINE' : redefinition
error c2143: syntax error: missing ';' before ''
error C2146: syntax error : missing ';' before identifier 'LONGLONG'
error C2146: syntax error : missing ';' before identifier 'PVOID'
any solution for those error? please help!!
The documentation for the function has this header requirement:
WinBase.h (include Windows.h)
This is telling you that the function is declared in WinBase.h, but that you should include Windows.h which in turn will include WinBase.h. So, you need to change your include to
#include <Windows.h>
I also wonder why you are talking about mingw considering that your compiler is MSVC. That compiler ships with a comprehensive Windows SDK. Why would you be using an SDK from mingw?

syntax error : missing ';' before identifier 'PVOID64' when compiling winnt.h

I've recently got the source-code on a application. When im trying to build the solution, I get an error in all parts where winnt.h is included. The error codes differs a bit, but they always point to these lines in winnt.h:
typedef void *PVOID;
typedef void * POINTER_64 PVOID64;
and
struct {
DWORD crc;
BYTE rgbReserved[14];
} CRC;
So, what could be the cause of this? winnt.h is a standard header and has not been modified. Does it has something to do with me using VS 2010, or me using 64-bit windows? or is it some sort of configuration which is needed?
EDIT:
Here's the exact error-codes:
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(290): error C2146: syntax error : missing ';' before identifier 'PVOID64'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(290): 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\winnt.h(8992): error C2146: syntax error : missing ';' before identifier 'Buffer'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(8992): 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\winnt.h(8992): 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\winnt.h(11525): error C2059: syntax error : 'constant'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(11525): error C2238: unexpected token(s) preceding ';'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(11556): error C2059: syntax error : 'constant'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(11556): error C2238: unexpected token(s) preceding ';'
You need to include windows.h rather than winnt.h. When you include windows.h it will, in turn, include winnt.h. You need to do it this way for the necessary macros to be in place that are needed to compile winnt.h.
In this case, POINTER_64 is defined in BaseTsd.h like this:
#define POINTER_64 __ptr64
But if you include winnt.h before including windows.h then POINTER_64 is not defined.
If you are using DirectX SDK, try changing the VC++ Directories for include and lib to be searched last.
It looks like your configuration of the Windows SDK is invalid.
This error is caused by the fact that the compiler is unable to recognize the 'POINTER_64' statement.
You may workaround this problem by replacing 'POINTER_64' with '__ptr64'.
I had the same issue recently. Then I've reinstalled the latest version of the Windows SDK and this fixed the problem.
UPDATE
#David Heffernan, correctly points to the fact that one should include windows.h instead of winnt.h
Try to remove DirectX SDK if you have one.
Here bug is accepted:
http://connect.microsoft.com/VisualStudio/feedback/details/508204/vc10-0-errors-while-compiling-winnt-h
Corrected manually syntax in winnt.h :
typedef void * POINTER_64 PVOID64; => typedef void * POINTER_64, * PVOID64;
If you are using librdkafka, you will get this error whenever "Windows.h" included.
I fixed it by rename "librdkafka/include/basetsd.h" to a different name, or access
this library header via sub path!
I think the author of this library made this file to deal with OS platform compatibility. But with the same file name "basetsd.h" as Windows Core, it just confusing Visual Studio.

Why do I get errors when I #include curl.h?

I'm trying to get libcurl to work with my C++ project.
I've added libcurl to my project.
I've also added the header files, preprocessor and linker configuration.
When adding #include to my project I get a lot of winnt.h errors:
c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(1084): error C2988: unrecognizable template declaration/definition
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(1084): error C2059: syntax error : '('
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(1084): error C2090: function returns array
...
What is the reason to this problem?
Thanks.

Compile errors in mshtml.h compiling with VS2008

I'm in the process of moving one of our projects from VS6 to VS2008 and I've hit the following compile error with mshtml.h:
1>c:\program files\microsoft sdks\windows\v6.0a\include\mshtml.h(5272) : error C2143: syntax error : missing '}' before 'constant'
1>c:\program files\microsoft sdks\windows\v6.0a\include\mshtml.h(5275) : error C2143: syntax error : missing ';' before '}'
1>c:\program files\microsoft sdks\windows\v6.0a\include\mshtml.h(5275) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft sdks\windows\v6.0a\include\mshtml.h(28523) : error C2059: syntax error : '}'
1>c:\program files\microsoft sdks\windows\v6.0a\include\mshtml.h(28523) : error C2143: syntax error : missing ';' before '}'
1>c:\program files\microsoft sdks\windows\v6.0a\include\mshtml.h(28523) : error C2059: syntax error : '}'
Following the first error statement drops into this part of the mshtml.h code, pointing at the "True = 1" line:
EXTERN_C const GUID CLSID_CDocument;
EXTERN_C const GUID CLSID_CScriptlet;
typedef
enum _BoolValue
{ True = 1,
False = 0,
BoolValue_Max = 2147483647L
} BoolValue;
EXTERN_C const GUID CLSID_CPluginSite;
It looks like someone on expert-sexchange also came across this error but I'd rather not dignify that site with a "7 day free trial".
Any suggestions would be most welcome.
you might already have the symbols True & False defined, try
#undef True
#undef False
before including that file.
There is probably a #define changing something. Try running just the preprocessor on your .cpp and generating a .i file. The setting is in the project property pages.
EDIT: Also, you can get the answer from that other expert site by scrolling to the bottom of the page. They have to do that or Google will take them out of their indexes.
What other incodes do ou have in the currently compiling file? It may be that True has been defined by a macro already as 1. That would explain the error.
Thanks Guys. I found the right spot for those #undef's. I dropped them into the classes header file just before a #include <atlctl.h> that seemed to do the trick.
And thanks for the tip about that other expert site, I'll have to keep that in mind.