compile errors w/wininet & winhttp in MFC application - c++

Strangely I had this working before but I reinstalled my system, upgraded to w7 and now I can't seem to get this code to compile.
The problem is that I'm using winhttp.h in most of my application, but I have a simple FTP client object that I wrote using wininet.h functionality. I can't seem to get the application to compile now, no matter how/where I include which headers.
Currently I have in my stdafx.h:
#include <winhttp.h>
And in my ftp client .c
#include <wininet.h>
This compiles all objects successfully except for the FTP client object which fails with:
c:\Program Files\Microsoft Platform SDK\Include\WinInet.h(52) : warning C4005: 'BOOLAPI' : macro redefinition
c:\Program Files\Microsoft Platform SDK\Include\winhttp.h(45) : see previous definition of 'BOOLAPI'
c:\Program Files\Microsoft Platform SDK\Include\WinInet.h(270) : error C2143: syntax error : missing '}' before '('
c:\Program Files\Microsoft Platform SDK\Include\WinInet.h(270) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Any advice?

Ah got it, finally by moving the winhttp include into the cpp files and putting wininet into the ftp client header.

Most likely a clash between winhttp.h and wininet.h.

Related

std::filesystem doesn't work in DLL project

I feel sorta silly asking this question, but I just cannot find a solution anywhere on the internet.
Notes:
I am using VS2019
C++17 is enabled
My problem is the following:
I want to iterate files in a directory with std::filesystem. To do so, I need to use the directory_iterator. However, when I include the filesystem library, it doesn't find the directory_iterator, so I checked the filesystem header file. It threw me a bunch of errors. I also cannot use experimental/filesystem because for some reason the path class also has errors which make the string functions unusable.
However, when I create a fresh console application, it works fine for me. No errors, directory_iterator has been found, I can iterate without issues.
Here is a small snippet of what the errors I'm being given when trying to compile:
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\experimental\filesystem(917,28): warning C4003: not enough arguments for function-like macro invocation 'concat'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\experimental\filesystem(921,1): error C2365: '_InIt': redefinition; previous definition was 'template parameter'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\experimental\filesystem(921): message : see declaration of '_InIt'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\experimental\filesystem(921,1): error C2061: syntax error: identifier '_First_InIt'

defining _WINSOCKAPI_ causes error in visual studio 2012 migration

So I'm trying to update a windows build of a project and encountered this error,
1>C:\Program Files (x86)\Windows Kits\8.0\Include\shared\ws2def.h(452): error C2059: syntax error : 'constant'
1>C:\Program Files (x86)\Windows Kits\8.0\Include\shared\ws2def.h(452): error C3805: 'constant': unexpected token, expected either '}' or a ','
I determined that winsock.h must have been included earlier than Winsock2.h which was included in the error'd file so I defined
_WINSOCKAPI_
in the project properties to make sure that didn't happen.
However now I get like 8 other errors from files that include afxsock.h saying "error : MFC requires use of Winsock2.h". So is
_WINSOCKAPI_
preventing afxsock.h from including winsock? Because it seems like I have this circular error and only one set of files can build properly.

Errors building Freetype application with Visual Studio

I've been going bonkers the last week on this problem.
Microsoft Visual Studio Community 2013
Freetype 2.5.5
Windows 8.1
Building as C++ application
I've been trying to build against a static library for Freetype, I've tried after building the lib using the included VC2010 project and also downloading a pre-built library with no luck. I always get the same errors below. I've tried with multiple examples and the same. I'm able to successfully compile and link against the lib using gcc (after building a .a library), this problem seems to be isolated to Visual Studio..
1>f:\audio\libs\header\freetype\fterrdef.h(35): error C2143: syntax error : missing '}' before '('
1>f:\audio\libs\header\freetype\fterrdef.h(35): error C2143: syntax error : missing ';' before '<L_TYPE_raw>'
1>f:\audio\libs\header\freetype\fterrdef.h(35): error C2059: syntax error : '<L_TYPE_raw>'
1>f:\audio\libs\header\freetype\fterrors.h(164): error C2143: syntax error : missing ';' before '}'
1>f:\audio\libs\header\freetype\fterrors.h(177): error C2059: syntax error : '}'
1>f:\audio\libs\header\freetype\fterrors.h(177): error C2143: syntax error : missing ';' before '}'
1>f:\audio\libs\header\freetype\freetype.h(38): error C2143: syntax error : missing ';' before '{'
1>f:\audio\libs\header\freetype\freetype.h(38): error C2447: '{' : missing function header (old-style formal list?)
Example code that can cause this error:
#include <windows.h>
#include <ft2build.h>
#include FT_FREETYPE_H
int main(int argc, char **argv)
{
return 0;
}
I had the same issue while building FreeType2 in VS2013 with VS2013 toolset (SDK). No Google results seem to have answer to this so far so I thought I'd share even though the thread is bit old (but the problem is still recent! FreeType ver. 2.6 still suffers from the same problem).
For reference, this can be reproduced by minimal example:
#include <ft2build.h>
#include FT_FREETYPE_H
FT_Library library;
So the problem and solution is quite simple but was unfortunately buried in output log and wasn't that obvious at first glimpse so it needed some investigation.
There is a clash with header names between FreeType2 library and Windows SDK, namely with the fttypes.h file which gets dragged in from:
C:\Program Files (x86)\Windows Kits\8.1\Include\shared\fttypes.h
Instead, VS should include FT2 header that is located in:
your_FT2_root\include\fttypes.h
This is easy to workaround - in your Project Properties (Alt+F7) rearrange header search paths so FreeType2 path is first (for me bringing FT2 at the top worked like a charm).
Hope this helps!
Cheers,
Henryk

C++/CX and Amazon Product Advertising API

Language: C++/CX & XAML
Environment: Visual Studio 2013 on Windows 8.1
I am trying to use the Amazon Product Advertising API in my Windows Store app. I have an Associates account so I am allowed to use this however I'm having problems implementing the .wsdl file after using wsutil.exe to create a .c and .h file for my project.
The .c and .h files both have errors pointing to identifiers that reside inside WebServices.h.
Since the .c and .h files have a combined length of more than 13k lines of code I'll write out steps to reproduce my problem.
-Navigate to http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl
-Save the file either in a project fold or on the desktop
-Open up a VS2013 command prompt and navigate to where the file resides
-Type "wsutil /wsdl:AWSECommerceService.wsdl"
This produces the .c and .h files that can be used in the project
-Add the .c and .h files to a VC++ Windows Store app project
since the environment language is C++/CX and wsutil gave us a .c file we need to tell the compiler to treat this file as a C++ file otherwise if you try to build like it is it throws an error saying:
Command line error D8048: cannot compile C file '....\New folder\AWSECommerceService.wsdl.c' with the /ZW option
My first attempt at trying to fix this was to remove the /ZW option.
This can be done by right clicking the .c file, click properties, under "General" you will will see "yes(/ZW)" which you can change to "no".
after doing this and trying to build it gives this error:
...\awsecommerceservice.wsdl.c : fatal error C1853: 'Debug\SimpleShop.pch' precompiled header file is from a previous version of the compiler, or the precompiled header is C++ and you are using it from C (or vice versa)
That wasn't the correct fix so I went back and added the /ZW option.
Next I decided to tell the compiler to treat the .c file as a .cpp file by adding the /TP option. You can find this by right clicking the .c file, clicking properties, click Advanced, click the drop down box next to "Compile as" and selected /TP.
Now when trying to build the project errors appear in both the .c and .h files for identifiers that reside in the WebServices.h file.
This is where I'm stuck at. I tried to #include "WebServices.h" into the .h file (which is oddly missing it whereas the .c file is not) and this does nothing to remove any of the errors.
I can find nothing about using the Amazon Product Advertising API inside a windows store app on the internet so all of the attempted fixes came from Win7 or WCF forums. The steps I'm trying to follow are from Amazon on they can be found here (focus on step 4):
http://docs.aws.amazon.com/AWSECommerceService/latest/GSG/GettingSetUp.html
these are the errors:
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(1037): error C2371: '_RelatedItems::RelatedItemCount' : redefinition; different basic types
1> c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(1034) : see declaration of '_RelatedItems::RelatedItemCount'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(1576): error C2061: syntax error : identifier 'WS_SERVICE_SECURITY_CALLBACK'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(1604): error C2061: syntax error : identifier 'WS_SERVICE_SECURITY_CALLBACK'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(1632): error C2061: syntax error : identifier 'WS_SERVICE_SECURITY_CALLBACK'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(1660): error C2061: syntax error : identifier 'WS_SERVICE_SECURITY_CALLBACK'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(1688): error C2061: syntax error : identifier 'WS_SERVICE_SECURITY_CALLBACK'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(1716): error C2061: syntax error : identifier 'WS_SERVICE_SECURITY_CALLBACK'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(1744): error C2061: syntax error : identifier 'WS_SERVICE_SECURITY_CALLBACK'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(1772): error C2061: syntax error : identifier 'WS_SERVICE_SECURITY_CALLBACK'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(1800): error C2061: syntax error : identifier 'WS_SERVICE_SECURITY_CALLBACK'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(1828): error C2061: syntax error : identifier 'WS_SERVICE_SECURITY_CALLBACK'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(1856): error C2061: syntax error : identifier 'WS_SERVICE_SECURITY_CALLBACK'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(2709): error C2146: syntax error : missing ';' before identifier 'AWSECommerceServiceBinding'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.h(2709): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.c(1159): error C2146: syntax error : missing ';' before identifier 'contractDesc'
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.c(1159): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\scott\desktop\new folder\awsecommerceservice.wsdl.c(6674): fatal error C1903: unable to recover from previous error(s); stopping compilation
There are several things going on here:
You need to include the header pch.h at the top of the generated .c file
This sounds like a genuine error in the generated header. Notice a member defined twice.
typedef struct _RelatedItems
{
enum _Relationship Relationship;
WCHAR* RelationshipType;
unsigned __int64 RelatedItemCount;
unsigned __int64 RelatedItemPageCount;
unsigned __int64 RelatedItemPage;
unsigned int RelatedItemCount;
_Field_size_(RelatedItemCount)struct _RelatedItem* RelatedItem;
} _RelatedItems;
The other errors are because the missing identifiers are actually not available for Windows Store apps. Both WS_SERVICE_SECURITY_CALLBACK and WS_CONTRACT_DESCRIPTION are conditionally defined in the SDK header WebServices.h only for Desktop apps
"if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)"

error C2065: 'errno' : undeclared identifier in <string> in Visual Studio 2012

I had a project running in Visual Studio 2010. Now I am using Visual Studio 2012.
Now I am getting below error while building the project.
I have looked into Google and SO as well. But no where I got any solution.
c:\program files\microsoft visual studio 11.0\vc\include\string(557): error C2065: 'errno' : undeclared identifier
2>c:\program files\microsoft visual studio 11.0\vc\include\string(557): error C2065: 'errno' : undeclared identifier
2>c:\program files\microsoft visual studio 11.0\vc\include\string(562): error C2065: 'errno' : undeclared identifier
2>c:\program files\microsoft visual studio 11.0\vc\include\string(574): error C2065: 'errno' : undeclared identifier
2>c:\program files\microsoft visual studio 11.0\vc\include\string(579): error C2065: 'errno' : undeclared identifier
I have tried with including stdlib.h into the sting header file but still I am getting this same error.
Any help appreciated.
There could be several possible reasons for this problem. The
first thing you should do is to create a one line source:
#include <string>
and nothing else, and try to compile it. If this doesn't
compile, there is a problem with your installation, and you
should reinstall it. Then, just to be sure, delete everything
in your source tree except the actual sources, project files and
solution, and rebuild. There may be some old files laying
around which are somehow causing the problem. I doubt it, but
this is something you should do anyway, any time you upgrade
a compiler, or even just install a patch. (If you've got
everything under source code control, which you should, the
simplest solution is just to delete everything, and do a new,
clean checkout.)
If these measures don't solve the problem (and somehow,
I suspect they won't), there's a problem in your code base
somewhere. errno is required to be a macro by the standard;
to get the error message you cite, the macro must be undefined.
<string> includes (indirectly) a file which defines it. Given
this, the only cause I can think of is that an earlier include
file has already included a file which defines errno, and then
#undefed it. To verify this, put your #include <string> as
the very first include of your source, and see if this solves
the problem. If it does, then you have to find the file which
does the #undef, and fix it.
I had the same issue. Strangely enough, the problem was not including "using namespace std;" under the header file includes. Apparently, program would recognize "string" unless I did this, even though "char", "float", etc were recognized.