C++/CLI include problems - visual-c++

doing some C++/CLI coding again, and running into issues. Working in VS2008 if it matters at all.
Here's a mock up of what I am trying to do. In reality ClassA is the GUI and ClassB is the backend that the gui needs to interact with. I am trying to give them access to eachother by passing them to eachother, but I cannot properly get them in scope to create a reference to the other one.
http://pastie.org/private/tnyxazwtyzv3luddz7seq
If you have any input I would greatly appreciate it. I have spent much of today looking online and this solution I currently have has gotten me quite close but I am still getting compile errors. Here's what I am now getting:
Error 1 error C2653: 'NameSpaceB' : is not a class or namespace name c:\users\andy\documents\visual studio 2008\projects\myhello\myhello\A.h 12 myhello
Error 2 error C2143: syntax error : missing ';' before '^' c:\users\andy\documents\visual studio 2008\projects\myhello\myhello\A.h 12 myhello
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\andy\documents\visual studio 2008\projects\myhello\myhello\A.h 12 myhello
Error 4 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\andy\documents\visual studio 2008\projects\myhello\myhello\A.h 12 myhello
Error 5 error C2653: 'NameSpaceA' : is not a class or namespace name c:\users\andy\documents\visual studio 2008\projects\myhello\myhello\B.h 12 myhello
Error 6 error C2143: syntax error : missing ';' before '^' c:\users\andy\documents\visual studio 2008\projects\myhello\myhello\B.h 12 myhello
Error 7 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\andy\documents\visual studio 2008\projects\myhello\myhello\B.h 12 myhello
Error 8 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\andy\documents\visual studio 2008\projects\myhello\myhello\B.h 12 myhello
This is the same error I am getting in my actual project, so I know it's something funky with my configuration.

/*B.h File Contents*/
#ifndef CLASSB_H
#define CLASSB_H
#include "A.h"
Remove the #include "A.h" part and you're golden. Since class B doesn't use A (at least in the definition), there's no need for the include.

Related

timespec redefinition error occurs after applying all known solutions

so I'm using visual studio 2019 and I installed pthread package but whenever I run my code the following error pops up "'timespec': 'struct' type redefinition "
the most common solution I found is to put #define HAVE_STRUCT_TIMESPEC before including pthread.h but whenever I do so two errors occur:
1- LNK2019 unresolved external symbol __imp__pthread_create referenced in function _main
2- 1 unroslved externals
I know this problem is common but I didn't find any solution to the two new errors specified.

Latest Visual Studio 2019 v 16.10.0 and _DEPRECATE_TR1_NAMESPACE

I am programming with /std:c++latest in VS2019 v16.10.0. Everything compiled fine with previous version of VS2019. Now I get many errors in header related to _DEPRECATE_TR1_NAMESPACE.
How can I compile around this deprecation?
An example of an error follows:
error C2146: syntax error: missing ';' before identifier 'subtract_with_carry_01'
where the code referenced is:
template <class _Ty, size_t _Wx, size_t _Sx, size_t _Rx>
class _DEPRECATE_TR1_NAMESPACE subtract_with_carry_01
: public _Swc_base<_Ty, _Sx, _Rx, _Swc_01_traits<_Ty, _Wx, _Rx>> { // subtract_with_carry_01 generator
The workaround I found was to
#define _HAS_TR1_NAMESPACE 0
before all header files.
Or to add _HAS_TR1_NAMESPACE=0; in the preprocessor definitions...
This allows me to use latest C++ language!!

Issue in convert project from vc6 to vc9

I have a project that was build in vc6,Now I have to convert it into vc9.
In the code there is line
CMapStringToOb cLogPathMap;
ofstream tlogFile;
But when I build the project the following error occur.
error C2146: syntax error : missing ';' before identifier 'tlogFile'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
When I go to definition of ofstream the file iosfwd is opened where ofstream defined as
typedef basic_ofstream<char, char_traits<char> > ofstream;
The following microsoft suggests to include fstream:
http://msdn.microsoft.com/en-us/library/e9cabcax%28v=vs.90%29.aspx
So put the following line in your header includes for that c++ file:
#include <fstream>

WDK (Windows Driver Kit) and VC++ headers problem

I'm trying to read from an USB HID device, I know how to do it in C# using DLLImport hid.dll, but I want to do it from C++, this way I don't have to declare all the structures, etc, and just include the headers files.
So I downloaded the WDK and then when including the headers files and linking the libraries I'm getting a lot of errors:
#include <windows.h>
extern "C" {
#include <hidsdi.h>
}
int main(){
}
Errors (6 out of 163):
Error 1 error C2065: 'PASSIVE_LEVEL' : undeclared identifier c:\winddk\7600.16385.1\inc\api\hidpi.h 302 driver
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\winddk\7600.16385.1\inc\api\hidpi.h 303 driver
Error 3 error C2146: syntax error : missing ';' before identifier 'NTSTATUS' c:\winddk\7600.16385.1\inc\api\hidpi.h 303 driver
Error 4 error C2143: syntax error : missing ';' before '__stdcall' c:\winddk\7600.16385.1\inc\api\hidpi.h 303 driver
Error 5 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\winddk\7600.16385.1\inc\api\hidpi.h 303 driver
Error 6 error C2377: 'NTSTATUS' : redefinition; typedef cannot be overloaded with any other symbol c:\winddk\7600.16385.1\inc\api\hidpi.h 303 driver
OK so I read somewhere that I have to upgrade the Windows SDK too, I had the Microsoft Windows SDK v6.0A, I downloaded and installed the windows SDK v7.0. But then looks like I have two SDK now? How I properly do the SDK upgrade in visual studio?
I very much appreciate your help,
Thanks,
Carlos
I found a solution, don't know why this is working, but it is!:
In Visual Studio go to:
Tools->Options->Projects->VC++ Directories and then Show directories for: include files.
Add this folders:
C:\WinDDK\7600.16385.1\inc\ddk and C:\WinDDK\7600.16385.1\inc\api
Now here is the trick that solved the problem for me and I don't know why, because seems odd but here it is:
C:\WinDDK\7600.16385.1\inc\ddk -> This directory have to be the first directory in the list!
C:\WinDDK\7600.16385.1\inc\api -> This directory have to be ABOVE "$(WindowsSdkDir)\include" BUT BELOW "$(VCInstallDir)include"
Example:
C:\WinDDK\7600.16385.1\inc\ddk
$(VCInstallDir)include
$(VCInstallDir)atlmfc\include
C:\WinDDK\7600.16385.1\inc\api
$(WindowsSdkDir)\include
$(FrameworkSDKDir)include
Carlos

Problems during Migration from VS 2003 to VS 2008

I have converted one of my Visual studio 2003 projects into VS2008 and when trying to build the project in VS2008 I get the below mentioned error.
In oledb.h, I have
typedef LONG DBROWCOUNT;
and in sybdb.h, I have
#define DBROWCOUNT 16
When I compile, I get the following errors:
c:\program files\microsoft sdks\windows\v6.0a\include\oledb.h(633) : error C2143: syntax error : missing ';' before 'constant'
c:\program files\microsoft sdks\windows\v6.0a\include\oledb.h(633) : error C2059: syntax error : 'constant'
c:\program files\microsoft sdks\windows\v6.0a\include\oledb.h(3005) : error C2059: syntax error : 'constant'
If I comment the //#define DBROWCOUNT 16, then these errors are solved,but I am not supposed to make changes in code, so please help me to come over this error,thanks in advance.
The problem seems to be that DBROWCOUNT is defined as 16 so it is replaced by preprocessor which results in the line
typedef LONG DBROWCOUNT;
being converted to
typedef LONG 16;
after preprocessing, which is clearly an error. But without looking at the code I can't say why this wasn't happening in vs2003.
While I can't speak to how this was not a problem with VC 2003, the main issues here is that you've defined DBROWCOUNT as both a type and a macro constant (which isn't allowed, as you know.) You're going to have to make a change somewhere, or else you won't be able to fix the compiler error. If oledb.h is a system header, then the change will have to be to your constant:
#define DBROWCOUNT 16
Can you change that define macro to read something like:
#define dbRowCount_k 16
And then replace DBROWCOUNT with dbRowCount_k in the places in your code where you are using that value as an integer (as opposed to a type)?

Resources