I am trying to program a C++ Wrapper for TWAIN with Visual Studio 2012, Windows 7.
I have installed Twain SDK and have all DLL like Twain_32.dll in C:/Windows
I have twain.h : https://svn.apache.org/repos/asf/incubator/ooo/trunk/main/twain/inc/twain.h
And I have my main :
#include <windows.h>
#include "twain.h"
int main()
{
return 0;
}
And I get 200 errors like for this line
#ifdef _MSWIN_
typedef HANDLE TW_HANDLE;
typedef LPVOID TW_MEMREF;
error C2146: syntax error : missing ';' before identifier 'TW_HANDLE'
How can I resolve that ?
Related
I'm trying to test Windows Bcrypt. I have a test program:
#include <bcrypt.h>
#include <iostream>
#include <string>
#pragma comment (lib, "bcrypt.lib")
int main(int argc, char* argv[])
{
return 0;
}
Attempting to compile it:
>cl.exe /DWINVER=0x0600 /TP /GR /EHsc bcrypt-test.cpp /link /out:bcrypt-test.exe
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24210 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
bcrypt-test.cpp
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\bcrypt.h(39):
error C2059: syntax error: 'return'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\bcrypt.h(40):
error C2143: syntax error: missing ';' before '*'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\bcrypt.h(40):
error C4430: missing type specifier - int assumed. Note: C++ does not support d
efault-int
...
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\bcrypt.h(681)
: error C3646: 'cbKeyLength': unknown override specifier
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\bcrypt.h(681)
: fatal error C1003: error count exceeds 100; stopping compilation
I am using a Visual C++ x64 Build Tools command prompt. As I understand things, Bcrypt needs to target Vista or above. WINVER=0x0600 should satisfy the requirement. I found a similar question on the MSDN forums at bcrypt.h build error?, and it says to use a modern SDK. I believe the Windows Kit SDK should satisfy the requirement.
Why am I experiencing compile errors, and how do I fix it?
Line 39 in bcrypt.h is the first typedef below. The preamble, like copyright and header guards, were skipped for brevity.
#ifndef WINAPI
#define WINAPI __stdcall
#endif
#ifndef _NTDEF_
typedef _Return_type_success_(return >= 0) LONG NTSTATUS;
typedef NTSTATUS *PNTSTATUS;
#endif
#ifndef BCRYPT_SUCCESS
#define BCRYPT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0)
#endif
You are missing an include.
#include <Windows.h> // <- Added this
#include <bcrypt.h>
#include <iostream>
#include <string>
#pragma comment (lib, "bcrypt.lib")
int main()
{
return 0;
}
I have the following code:
#include "wx\wx.h"
class BClient : public wxApp
{
virtual bool OnInit();
virtual int OnQuit();
};
IMPLEMENT_APP(BClient)
bool BClient::OnInit()
{
return true;
}
int BClient::OnQuit()
{
return 0;
}
As soon I try to add the line
#include <thread>
I receive this errors:
Error 10 error C2347: '__w64' : can not be used with type '__w64
unsigned __int64'
Error 12 error C2143: syntax error : missing ';' before ','
Error 13 error C2059: syntax error : ','
The errors refer to this file: c:\program files (x86)\microsoft visual studio 12.0\vc\include\concrt.h
So, for some reason, wxwidgets and std::thread doesn't mix together.
Can someone explain to me why this is happening and is there a workaround for this issue ?
Thanks.
Something is wrong with your MSVS installation. Here, adding #include <thread> line either before or after #include <wx/wx.h> one works without any problems.
Also, on a completely unrelated note, there is no OnQuit() in the base class, only OnExit().
I need to refactor a .dll for a Zinc based Flash application.
After copy&paste a class from the master to the branch, I'm getting some strange compiling errors:
GameInfo.h(15): error C2146: syntax error : missing ';' before identifier 'm_wsVersion'
GameInfo.h(15): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
GameInfo.h(15): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
The addressed code:
// removed the comments
#include "stdafx.h"
#include <string.h>
class GameInfo {
public:
UINT m_uiGameId;
wstring m_wsVersion; // Line 15
UINT m_uiCheckSum;
wstring m_wsFilePath; // Same error report as on line 15
public:
static BOOL createFromFile(wstring path, GameInfo &target); // error "error C2061: syntax error : identifier 'wstring'" thrown
};
I use Visual Studio 2010 and in the IDE itself everything is okay, no syntactical errors or something like that. And as said I did not touch the code, headers seem fine.
Has anyone a clue what about this error?
Try using the string header, and qualifying the namespace:
#include <string>
class GameInfo {
....
std::wstring m_wsVersion;
};
#include <string> is the right standard include in C++ for string classes and use std::wstring.
I strongly recommend AGAINST using a using namespace std; inside one of your headers, as you would force anybody using the header to pull in the std stuff into the global namespace.
I have a problem: My codes work well in CentOS g++, but when I compile them in visual studio 2008, the visual studio tells me errors like below:
1.c:\program files (x86)\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(19) : error C2144: syntax error : '__w64 unsigned int' should be preceded by '}'
2.error C2143: syntax error : missing '}' before 'namespace'.
My file coding is UTF-8. Should I change them in Unicode all, I change some error file in Unicode,it still has errors like above.
below are some sourecode:
#ifndef ENRC_CODE_DEFS_H
#define ENRC_CODE_DEFS_H
enum ENReturnCode
{
ENRC_SUCCESS = 0,
ENRC_FAILED,
ENRC_NODATA,
ENRC_CONFIG_NOT_AVAILABLE,
ENRC_INVALID_SUBSCRIBE_ID,
ENRC_INVALID_SUBSCRIBE_CONDITION,
ENRC_INVALID_SUBSCRIBER,
ENRC_INVALID_PARAMETER,
ENRC_THREAD_RUNNING,
ENRC_SUBSCRIBE_LIST_EMPTY,
ENRC_OUT_OF_MEMORY // 10
}
e:\my_code\cppcommon\include\errordefs.h(5) : error C2143: syntax error : missing ';' before 'enum [tag]'
next:
#ifndef EN_SMS_SRC_TAO2CPP_H_
#define EN_SMS_SRC_TAO2CPP_H_
#include "SystemMonitorMasterServiceC.h"
#include "SystemMonitorSlaveServiceC.h"
#include "CommonDefs.h"
#include "SystemMonitorServiceDataDefs.h"
namespace EN
{
namespace SMS
{
template < typename _Ty, typename _Cy>
inline
void Tao2Cpp_Enum(_Ty taoValue, _Cy &cppValue)
{
cppValue = (_Cy)taoValue;
}
error C2143: syntax error : missing '}' before 'namespace'
A lot of errors like above.
Thanks. I waste some time to make it easy to read.
You need a semi-colon in the enum declaration:
enum ENReturnCode
{
...
};
I'm reading this article on the Boost Unit Testing Framework.
However I'm having a bit of trouble with the first example, my guess is that they left something out (something that would be obvious to hardcore C++ coders) as IBM often does in their articles. Another possibility is that my Visual Studio 2005 C++ compiler is just too old for the example.
#include "stdafx.h"
#define BOOST_TEST_MODULE stringtest
#include <boost/test/unit_test.hpp>
//#include "mystring.h"
BOOST_AUTO_TEST_SUITE(stringtest) // name of the test suite is stringtest
BOOST_AUTO_TEST_CASE(test1)
{
/*
mystring s;
BOOST_CHECK(s.size() == 0);
*/
BOOST_CHECK(0 == 0);
}
BOOST_AUTO_TEST_CASE(test2)
{
/*
mystring s;
s.setbuffer("hello world");
BOOST_REQUIRE_EQUAL('h', s[0]); // basic test
*/
BOOST_CHECK(0 == 0);
}
BOOST_AUTO_TEST_SUITE_END()
To me the BOOST_AUTO_TEST_SUITE and BOOST_AUTO_TEST_CASE lines look a little suspect (especially since they don't have quotes around the arguments, and they are undeclared identifiers...but this probably means they are macros and I'm not certain I understand the concept or if that is available in VC++ 8.0)...
#ifdef _MYSTRING
#define _MYSTRING
class mystring {
char* buffer;
int length;
public:
void setbuffer(char* s) { buffer s = s; length = strlen(s); }
char& operator[ ] (const int index) { return buffer[index]; }
int size() {return length; }
}
#endif
Is there any reason why this code won't work?
1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(7) : error C2065: 'stringtest' : undeclared identifier
1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(9) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(9) : error C2146: syntax error : missing ';' before identifier 'BOOST_AUTO_TEST_CASE'
1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(9) : error C2065: 'test1' : undeclared identifier
1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(10) : error C2448: 'BOOST_AUTO_TEST_CASE' : function-style initializer appears to be a function definition
1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(18) : error C2065: 'test2' : undeclared identifier
1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(19) : error C2448: 'BOOST_AUTO_TEST_CASE' : function-style initializer appears to be a function definition
1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(29) : fatal error C1004: unexpected end-of-file found
Looks correct to me. My Boost.Test code looks the same way. I'm running VS2008, but I know it works in 2005 as well.
Seems like your problem lies elsewhere.
If you use precompiled headers (and why do you do that in such a small test program?), shouldn't stdafx.h be included as the very first thing in the file?
And what is the first line for? You don't seem to use it, and _MYSTRING is a reserved name in C++ (everything that begins with underscore followed by a capital letter is off limits)