Issue in convert project from vc6 to vc9 - visual-c++

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>

Related

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!!

<iostream> and #define __STDC_WANT_SECURE_LIB__ 0 results in error C2039: 'sprintf_s'

When building this very simple test program
#include <iostream>
int main() {
std::cout << "x";
}
with visual studio 2019 and /Wall I'm getting a
warning C4668: '__STDC_WANT_SECURE_LIB__' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
Trying to
#define __STDC_WANT_SECURE_LIB__ 0
before including iostream results in
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\xlocnum(1388,69): error C2039: 'sprintf_s': is not a member of '`global namespace''
at least for my VS. Godbolt doesn't complain.
#define __STDC_WANT_SECURE_LIB__ 1
is fine and doesn't let the compiler complain about sprintf_s which one would expect.
Microsoft doesn't show me any results when searching for it.. SO does here but overall i can't find many resources on if and how to use that define.
Is there a way to disable the secure extensions and include <iostream> ? Am i using the wrong define or approach for this?

__attribute__ and VisualC++

Hi I am trying to write a routine in VC ++ was originally compiled in GCC. When I make the following definition:
typedef float v4sf __attribute__ (vector_size(16));
The compiler throws me the following error:
C2146: syntax error: missing ';' before identifier '__attribute__'
As I can replace this line?
Thank you!

C++/CLI include problems

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.

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

Resources