Visual Studio C++ NPAPI plugin with Twain support - c++

I want to make a Google Chrome plugin that use Twain to remote control a Digital Camera.
I want this to run on Windows and I'm using Visual Studio Express 2012 C++.
I have this sample for NPAPI and this sample of CppWrapper for Twain which has 3 interesting files (TwainCpp.cpp TwainCpp.h twain.h)
Before doing anything, I want to merge these two projects.
First step: putting twain.h in the npsimple project which failed, twain.h errors caught.
Second step: putting CppTwain in npsimple, which also failed because twain.h "contains" errors.
Problem is that when I create an empty project, and put twain.h in it, there is no error! So I tried to put npsimple files in that empty project, and this time I get error from npsimple files..
Error type :
I have this code in twain.h :
#ifdef _MSWIN_
typedef HANDLE TW_HANDLE;
typedef LPVOID TW_MEMREF;
and I get plenty of errors like :
error C2146: syntax error : missing ';' before identifier 'TW_HANDLE'
How can I merge these projects?

HANDLE is an unspecified type because you don't include anything that is specificing it. You'll want to include windows.h.
Obviously there is no error when you add only the twain.h header file to the empty project - you haven't added any sources to compile, hence there can be no compilation errors.

Related

What's the cause of a D8049 error in visual studio?

I'm creating a project with openframeworks (the full source is here: https://github.com/morphogencc/ofxAsio/tree/master/example-udpreceiver), and the empty project seems to compile fine.
I added the ASIO library, and a few header classes, and now the project seems to be give me the following error:
1>------ Build started: Project: example-udpreceiver, Configuration: Debug x64 ------
1> main.cpp
1>cl : Command line error D8049: cannot execute 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\c1xx.dll': command line is too long to fit in debug record
1>cl : Command line error D8040: error creating or communicating with child process
I couldn't find any examples of error D8049 on stackoverflow or even on Microsoft's pages, and google turned up painfully few results. The only remotely useful one was this github issue:
https://github.com/deplinenoise/tundra/issues/270
But I'm still not sure what's causing the problem. Is anyone familiar with this error, and can recommend a method for troubleshooting what's causing it?
thanks in advance!
For me, working with UE4, this was an intermittent error.
I added "bLegacyPublicIncludePaths = false;" to the innermost block of project.Build.cs and recompiled without errors.
Then I removed that line and compiled again w/o errors.
The error message suggested adding "DefaultBuildSettings = BuildSettingsVersion.V2;" to project.Target.cs which worked.
This is a bit of a weird sounding error, as it is from essentially internally generated data. However, you do have control over that. Taking the error message at face value, you probably have many/lots of defined symbols passed in on the command line (or the the ones you do have have lengthy definitions), or you may have some lengthy file paths.
If you look under the project properties, one of the selections under the C++ section is "Command Line", which will show you exactly what gets passed to the compiler. When you view that you can see where you have many or lengthy parameters, and then make changes to shorten them.
Too many defines? Put them in a header (possibly stdafx.h) and include them that way.
Long file paths? Shorten the paths, put the files somewhere else, or set up file system aliases to your real directories that use shorter paths.

"wchar.h" gives syntax errors when imported in an .idl file (COM server)

I created a new C++ (ATL) project in my visual studio and set off on creating a nice little COM server dll. There is, of course an IDL file that defines interface outwards for the world to use. Since I'm using another library in this project I have the need to use wchar_t type. But when I put:
import "wchar.h";
on the top of my .idl file all hell breaks loose. Ok, I exaggerate. A little error pops up:
error MIDL2025: syntax error : expecting ; near "{" d:\programs\tools\dotnet\Microsoft Visual Studio 10.0\VC\include\wchar.h 994
Since this is an error with a system header file I have no idea how to rectify this problem.
Any ideas?

error PRJ0019: A tool returned an error code from "moc'ing qt/gui/QFloatSlider.h

I'm building a big C++ project on Visual Studio 2008 I'm getting this error message and I don't understand it. Is it a failure to include the .h file?
I know this thread is dated, but I had the exact same problem with a C++ project on Visual Studio 2008, here was my resolution...
One of the things the VS2008 compile told me was that it generated a log on:
"file://C:\Documents and Settings\adam\My Documents\Visual Studio 2008\Projects\MyProject\Debug\BuildLog.htm"
This log demystified the problem for me.
In my case, it had the following explicit error message:
c:\Documents and Settings\adam\My Documents\Visual Studio 2008\Projects\MyProject\MyProject\UnitTests.h(36): Error: Meta object features not supported for nested classes
The problem had been that INSIDE the class I defined here, I defined yet another internal (nested) class, that included the QT macro (so I could define signals and slots):
Q_OBJECT
Obviously QT wasn't happy that this class was nested/internal in another class. So I simply moved the class definition outside (IE made it non-internal).
No, it is not.
Did you look up the error code error PRJ0019.

Custom attributes are not consistent?

i have converted a C++ library to managed and get the following error on this code line:
std::ifstream fin(filename, std::ifstream::in);
Errors:
Error 30 error LNK2022: metadata operation failed (80131195) : Custom attributes are not consistent: (0x0c0003b5). C:\Users\Freeman\Documents\Visual Studio 2010\Projects\testsharp1\cpp1\MSVCMRTD.lib(locale0_implib.obj)
Error 32 error LNK2034: metadata inconsistent with COFF symbol table: symbol '??0_Container_base12#std##$$FQAE#XZ' (06000493) has inconsistent metadata with (0A000075) in MSVCMRTD.lib(locale0_implib.obj) C:\Users\Freeman\Documents\Visual Studio 2010\Projects\testsharp1\cpp1\LINK
Error 59 error LNK2034: metadata inconsistent with COFF symbol table: symbol '?memcpy##$$J0YAPAXPAXPBXI#Z' (060004DD) has inconsistent metadata with (0A0003E3) in MSVCMRTD.lib(locale0_implib.obj) C:\Users\Freeman\Documents\Visual Studio 2010\Projects\testsharp1\cpp1\LINK
Error 60 error LNK1255: link failed because of metadata errors C:\Users\Freeman\Documents\Visual Studio 2010\Projects\testsharp1\cpp1\LINK
How to fix that or how to change that code line without having to change the rest of the code?
Essentially, you're compiling your managed code which includes the <fstream> header. That means that all declarations from <fstream> are compiled as if they're managed, too. Yet the CRT DLL contains unmanaged versions of <fstream>.
At link time, this is detected when the import lib MSVCMRTD.lib contains the unmanaged std::_Container_base class, but your .obj files need a managed std::_Container_base.
(The _C tells us it's an implementation helper class).
I know this question is old, but after 1 week struggling to solve this I feel committed to post the solution I found to whoever could be fighting with a similar error.
In my case I'd two projects, one unmanaged with std's all over the place (list, vectors and queues, this is a project which should work on linux too so I cannot use .net collections), and pure standard C++ code, on the second project I create a managed project to wrap this classes to be used in .net projects, I was using Visual Studio 2010, trying to use framework 2.0, unfortunatelly VS 2010 does not have a nice support to VC++, and I tried everything to force it to use 2.0, without success, everytime I compiled I got the same annoying message "Inconsistent blah".
I installed VS 2008, ported the projects to 2008 and voila! everything worked in 10 mins, I spend 1 week trying to solve this in VS 2010 and 2008 did the trick.
I hope this might save a lot of hours trying to solve something that appears to be unsolvable on VS 2010.

iphlpapi / ifdef.h

I'm trying to use iphlpapi (GetAdapterInfo) and am having trouble compiling the code. I have iphlpapi.h from SDK 7 and have added the appropriate path to the include files in visual studio.
I get the following error...
c:\program files\microsoft sdks\windows\v7.0\include\ifdef.h(154) : error C2146: syntax error : missing ';' before identifier 'NET_IFTYPE'
The lines in ifdef where this occurs are shown below.
typedef NET_LUID IF_LUID, *PIF_LUID;
typedef ULONG NET_IFINDEX, *PNET_IFINDEX; // Interface Index (ifIndex)
typedef UINT16 NET_IFTYPE, *PNET_IFTYPE; // Interface Type (IANA ifType)
I finally figured out how to get this to work so I'm putting this here for others who might stumble upon it.
First, I'm using visual c++ version 6.0 with the 2003 sdk. I added the sdk as the first choice using TOOLS->OPTIONS->DIRECTORIES. Adding the include winsock2.h caused about 60 redefinition errors. I found several sources telling me that the winsock2 include had to precede the windows.h include. My windows.h include was generated for me by VC++ in the precompiled header stdafx.h so I moved the winsock2.h include there. I now can compile and run my program!
According to this page, it looks as though you might need to make sure winsock2.h is included first. I'm guessing that it defines some of those types.
Also, the MSDN page for NET_LUID says it requires Vista at a minimum. Make sure that's true.