MFC-C Code merge issue - c++

I am writing MFC-GUI on the top of C Code, after taking lib & include files from the c code i am getting redefinition error for many variable mentioned below-
error C2011: 'fd_set' : 'struct' type redefinition
error C2011: 'timeval' : 'struct' type redefinition
error C2011: 'hostent' : 'struct' type redefinition
error C2011: 'netent' : 'struct' type redefinition
error C2011: 'servent' : 'struct' type redefinition
error C2011: 'protoent' : 'struct' type redefinition
and many more....
it has nothing do with code as independently it is working fine so i need some help in merge configuration.
How i did-
I created one new MFC project + solution, added one dialog in it, build it- worked fine; Now i added one existing C project in above solution, configured MFC project for added C project. in configuration i have given all the required Lib & include path.
Now from MFC code i am trying to include C code file & it is giving me above said error.
Did i missed something or i added something wrongly ?
Please help me to solve this.
Thank you.

Make sure to add #pragma once at the top of all your .h files.
Check for multiple inclusion of .h files.
Eg. if your main.cpp includes head1.h and head2.h and both the head1.h and head2.h includes a common header say utils.h , it can cause such redefinition issues.
Check and null out such occurrences if any.

Related

Getting errors when include <WinSock2> on Visual Studio 2015

I'm trying to compile my project where I've just added the use of 'WinSock2.h'.I'm getting these errors :
c:\program files (x86)\windows kits\8.1\include\um\wingdi.h(2898): error C2208: '_POINTL' : no members defined using this type
c:\program files (x86)\windows kits\8.1\include\um\winuser.h(14564): error C2208: 'unsigned int' : no members defined using this type
more
I have searched solutions to my issue, I've added _WINSOCKAPI_ on preprocesseur rules and only the two errors up there are remaining. I have also tried adding WIN32_LEAN_AND_MEAN and still the same.
My project uses ALLEGRO library and "windows.h" file.
Have you a explanation of my problem ?
The compilator errors point to files winuser, wingdi, propild, oaidl.
These files has been added from the use of network library, on windows.h I guess.
The offending lines deal of following field definitions : unit, date, position.
All these name was already used on preprocessor definition on my project, leading to a conflict of definition.

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.

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)"

MS VisC++ 2010 express: Suddenly Project no longer sees header files

This may be hard to explain. I have been developing a program for about a month now in MS VisC++ 2010 express. I have had no strange problems and was ready to build my project for the 100th time when suddenly, many of the .cpp files seemed to loose contact with the .h files. For instance, in the main function, objects that I had created and used weeks ago, suddenly got the red line under them and the syntax error "theClass is undefined". This applies to iostream, so suddenly cout is undefined. I have no idea what happened. One second to another all external header files and libraries suddenly disappeared in the eyes of the IDE. In the .cpp files, when I declare the class constructor
//initializes a poker game
aPokerGame::aPokerGame(void)
{
stopPlaying = 'n';
}
I get the line under the class name aPokerGame and this error is "must be a class or a namespace name". Isn't this what would be happen if the .h files disappeared? In fact, not all .cpp files are having this problem, only some. Others have really weird errors in them like "no default constructor exists for class"std::basic_ostream<wchar...". All these errors appeared at once.
The header files seem fine. Though one of them has "Error: expected a declaration" under the "Private:" heading for the private members.
Please help!
Here is a sample of the compile errors:
1>------ Build started: Project: firstProj, Configuration: Debug Win32
------ 1> userPlayer.cpp 1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.h(9):
error C2504: 'Player' : base class undefined 1>c:\program files
(x86)\microsoft visual studio 10.0\vc\include\iostream(10): error
C2059: syntax error : 'namespace' 1>c:\program files (x86)\microsoft
visual studio 10.0\vc\include\iostream(10): error C2334: unexpected
token(s) preceding '{'; skipping apparent function body
1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(8):
error C3254: 'Player' : class contains explicit override '{ctor}' but
does not derive from an interface that contains the function
declaration
1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(8):
error C2838: '{ctor}' : illegal qualified name in member declaration
1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(8):
error C2535: 'Player::Player(void)' : member function already defined
or declared 1>
c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\player.h(18)
: see declaration of 'Player::Player'
1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(13):
error C3254: 'Player' : class contains explicit override '{dtor}' but
does not derive from an interface that contains the function
declaration
1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(13):
error C2838: '{dtor}' : illegal qualified name in member declaration
1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(13):
error C2535: 'Player::~Player(void)' : member function already defined
or declared 1>
c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\player.h(19)
: see declaration of 'Player::~Player'
1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(18):
error C3254: 'Player' : class contains explicit override 'userBets'
but does not derive from an interface that contains the function
declaration
1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(18):
error C2838: 'userBets' : illegal qualified name in member declaration
1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(38):
fatal error C1075: end of file found before the left brace '{' at
'c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\player.h(12)'
was matched 1> pokerRound.cpp
1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\npcplayer.h(9):
error C2504: 'Player' : base class undefined
1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.h(9):
error C2504: 'Player' : base class undefined 1>c:\program files
(x86)\microsoft visual studio 10.0\vc\include\iostream(10): error
C2059: syntax error : 'namespace' 1>c:\program files (x86)\microsoft
visual studio 10.0\vc\include\iostream(10): error C2334: unexpected
token(s) preceding '{'; skipping apparent function body 1>c:\program
files (x86)\microsoft visual studio 10.0\vc\include\time.h(35): error
C2059: syntax error : 'string' 1>c:\program files (x86)\microsoft
visual studio 10.0\vc\include\time.h(35): error C2334: unexpected
token(s) preceding '{'; skipping apparent function body
1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\pokerround.cpp(16):
error C2059: syntax error : 'namespace'
Probably you are missing a semicolon after a class definition or something like that in a header file which you #include into a bunch of other files above some standard header files, which makes everything mess up and the compiler report things as errors that are only errors because you forgot one little thing way up the line.
Double check the syntax of each of your header files meticulously, looking for mismatching parentheses or braces, and making sure you have semicolons where they are needed.

DbgPrint from WDK sample

I need to call DbgPrint or KdPrint function from WDK sample src\print\monitors\localmon
Please help with instructions
I've just added
#include <ntddk.h> in localmon.c file
and
DbgPrint("Some message"); in same file
and at compiling I've get next errors:
1>errors in directory c:\winddk\7600.16385.1\src\print\new2\monitors\localmon
1>c:\winddk\7600.16385.1\inc\api\ntdef.h(149) : error C2220: warning treated as
error - no 'object' file generated
1>c:\winddk\7600.16385.1\inc\api\ntdef.h(614) : error C2011: '_PROCESSOR_NUMBER'
: 'struct' type redefinition
1>c:\winddk\7600.16385.1\inc\api\ntdef.h(625) : error C2011: '_GROUP_AFFINITY' :
'struct' type redefinition
1>c:\winddk\7600.16385.1\inc\api\ntdef.h(882) : error C2011: '_FLOAT128' : 'stru
ct' type redefinition
1>c:\winddk\7600.16385.1\inc\api\ntdef.h(933) : error C2011: '_LARGE_INTEGER' :
'union' type redefinition
1>c:\winddk\7600.16385.1\inc\api\ntdef.h(951) : error C2011: '_ULARGE_INTEGER' :
'union' type redefinition
1>c:\winddk\7600.16385.1\inc\api\ntdef.h(973) : error C2011: '_LUID' : 'struct'
type redefinition
What i'm doing wrong?
Thanks
This is user-mode code. Use OutputDebugString instead and don't include ntddk.h at all. If you need to, write a little function as adapter to OutputDebugString as it does not take a formatting string etc. like its counterpart DbgPrint.
If you absolutely must use DbgPrint, it is also available from ntdll.dll, of course. So you could reach into that and import it from there (prototype can be found in wdm.h in the WDK). But I would prefer OutputDebugString in user-mode code.