I have a Windows C++ project which compiles with the /clr switch.
To use the Form object I had to write
#using <System.Windows.Forms.dll>
using namespace System::Windows::Forms;
and then I could declare and use the Form object.
now I'd like to use Some DevExpress components. So I went into the properties of the project and added a reference to DevExpress.XtraEditors library
then in my code wrote
#using <DevExpress.XtraEditors.v14.1.dll>
but it tells me it cannot find such a lib, so I wrote
#using <C:\Program Files (x86)\DevExpress 14.1\Components\Bin\Framework\DevExpress.XtraEditors.v14.1.dll>
for which I don't get an error, but I don't like to write full path.
Anyhow, after this I added
using namespace DevExpress::XtraEditors;
but when trying to declare a variable of type XtraForm
extern gcroot<XtraForm^> form;;
it tells me it doesn't know about such data type.
What am I doing wrong here?
What is the correct way to reference a 3rd party library to a mixed C++ project?
Any good articles are highly appreciated.
thx
Related
I'm modifying an existing project in Visual Studio, which has a lot of files with using namespace std and using namespace eigen defined. Problem is that I'm using a library which is in conflict with eigen, throwing an error about ambiguous class definition.
This way, I want to delete all using namespace and autocomplete the type name of the functions. I saw an old post but (there was no conclusion) I don't understand how to extrapolate it to my project.
Does anyone know the solution?
Thank you!
Alberto
I've been trying to follow lazy foo's productions tutorial on sdl2 and I keep on running into the same issue. I made a template that links to the correct files and all and it worked for a while. But now when I create a project and include iostream for example, it tells me #using need c++/cli mode enabled.
So I then tried enabling it in the project settings but then it gave another error : "Cannot open metadata file iostream"
I tried :
Rebuilding the project and solution
Cleaning the project and solution
I read this question and its answers : Visual studio - getting error "Metadata file 'XYZ' could not be found" after edit continue
Tried this too : IntelliSense: "#using" requires C++/CLI to be enabled
All of the above did not work
Don't confuse #include, using and #using.
#using is used to import class libraries in C++/CLI, which is something you won't ever need unless you work with .NET libraries (but then usually you are better off just using C#, unless you are writing interop code).
#include is for including header files, which is what you normally do in "regular" C++. <iostream> is a regular standard library header, so you need #include (as in #include <iostream>).
using instead is used to bring names in the current scope (either the whole content of a namespace - as in the dreaded using namespace std;) or single names (as in using std::cout;). From C++11 it's also used to enable constructors inheritance and to create type aliases, but for the moment I don't think you need to worry about these uses.
But most importantly: please take the time to first learn the basics of the language from reputable sources before trying random stuff. All this #using mess wouldn't have arisen if you even just looked first at the classic hello would example you can find everywhere on the Internet.
My previous questions concerning the same project: one and two. It's not necessary to read them; just know that I am trying to use a native C++ SDK in a Visual C++ project. This is much trickier than I had initially thought, but this website about Extending a native C++ project with managed code has helped me a lot further already.
As per that last link's instructions, I have added a Form to my native C++ project, which has automatically converted the project to a CLR one. Only MainForm.cpp and Interface.cpp (the file that allows native C++ code to create and show a MainForm) are compiled with the /clr flag though; the other files remain native.
The problem I have now, is that Visual Studio doesn't seem to recognise any of the CLR stuff that's being used in MainForm.h. As such, in the following lines:
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
the word System is always underlined in red, with according errors:
error C2653: 'System' is not a class or a namespace name
for each of those lines.
It also does not recognise the word gcnew and other things that should work effortlessly inside CLR.
Can anybody tell me what I might be doing wrong? My guess is that it's something very small; some flag I have forgotten to change, a missing reference or something similar, but I just can't figure out what it is.
Where do you include MainForm.h - directly and indirectly?
If you include MainForm.h in Interface.h, you include it indirectly anywhere where you include Interface.h as well. That means, if you then include Interface.h in any translation unit (i.e. *.cpp) that is not compiled with /clr, then the compiler will of course complain about it, because namespace System and gcnew are not part of standard C++.
Therefore you should include MainForm.h only in Interface.cpp and use forward declarations in Interface.h.
I have been trying to add MobileSynth to my application for some time now and I am only running into errors.
I have followed the steps here which explain how to add a project into another one.
When I compile, both projects are compiled correctly without errors, but the moment I try import the code into my objective C source code I get a large number of errors.
This is a screenshot of the errors.
Im sure there are more errors than these as there seems to be something wrong with the dependencies.
I also approved Xcodes recommendation to convert the project 2 (containing the objective C viewcontrollers with .mm extensions and the .cpp files) from an old 3.something version to the version 4 project type, and made the snapshot. Didnt seem to change anything.
I am not sure how to solve these issues. I would really appreciate any help.
Use using namespace instead of namespace.
You're aware that files that use C++ need the .mm extension. You also need to consider import dependencies. Since this header contains C++, any other file that imports it will also need to have the .mm extension. I'm almost positive that's what's happening to you.
I generally try to keep C++ quarantined to the implementation files for this very reason.
Also, for clarification on previous advice:
// Correct
namespace synth { class something; }
// Incorrect
using namespace synth { class something; }
// Optional
namespace synth { class something; }
using namespace synth;
I've got a program which shipped with a .tlb file to access some functions/objects (read variables etc.) with my own C++ program. I did a search and imported the .tlb file with:
#import "MyLib.tlb" named_guids no_namespace
I can also import it by using the libid from oleview.exe (ProgId does not work).
Even if I get some warnings (as follows), my program still runs:
C4278 ['TextOut', 'CreateEvent', 'DeleteFile'] is already a macro; use the 'rename' qualifier
But.. how can I gain access of the functions/objects now?
Sorry I'm a beginner so please be patient.
Does it work somehow with IDispatch? Do I need to import some more dll's or do I need more #include directives?
I'm using Visual C++ 2008 Express.
--
Edit: Ok sorry, I already have access to the header of the objects (I see "Application" in auto completion) but I have no idea how to get the objects.
Object Overview
And I think I found the related wikipedia article.
Importing type library gives you description of all the interfaces and identifiers of that library. Normally you should not include additionally any header files. You should just normally create these interfaces using COM smart pointer and call their methods:
CComPtr pInterface;
pInterface.CoCreateInstance(__uuidof("ClassNameFromTLB"));
pInterface->CallMethod();