My problem is as follows:
I got a Microsoft Visual C++ 2008 project and the order to organize all classes in it in nested namespaces. Now I get System::Resources::MissingManifestResourceException on runtime, because the custom System::Windows::Forms has a assembly ressource and with the new namespace, the old Resx-file does not fit anymore. My problem is now, that I have no idea how to reconnect it to the Form-class.
The old code of the Form was like:
namespace OldNamespace{
ref class MainForm : public System::Windows::Forms::Form{
...
};
}
The new code looks like:
namespace NewNamespace{
namespace GUI{
namespace MainWindow{
ref class MainForm : public System::Windows::Forms::Form{
...
};
}
}
}
I tried to adjust the filename of the created resource-file from the resx-file from
$(IntDir)\$(RootNamespace).$(InputName).resources
to
$(IntDir)\NewNamespace.GUI.MainWindow.MainForm.resources
But I am still getting System::Resources::MissingManifestResourceException on runtime.
What is my mistake?
Related
I have a tough time wording this question but here's my code to start:
namespace UserInterface
{
class UiClass
{
};
}
namespace Project
{
namespace UserInterface
{
}
}
namespace Project
{
UserInterface::UiClass uiClass;
}
So that code won't work because a UserInterface is a global namespace but it's also inside Project so when I instaniate UiClass inside Project it tries to look inside Project->UserInterface instead of just UserInterface. Is there a some way to be specific that I want to use the global UserInterface and not the one inside Project or do I need to change my design?
You can force the name lookup to begin at the global scope using a leading ::.
::UserInterface::UiClass uiClass;
I am trying to make a managed .dll in c++ that requires the support for multithreading. I am developing in visual Studio 2013, using platform toolset version v120. the reason I need this to be a managed assembly is because it is required to integrate the assembly in LabView.
following the steps in Creating and Using a Managed Assembly in VC++ 2010 gives good results. but I obviously need to implement something more complicated and when I include threading and write the following code:
#pragma once
#include <thread>
using namespace System;
using namespace std;
namespace MultiThread_module {
public ref class multiThreadingTest
{
public:
String^ GetVersion();
int someNumber;
private:
thread testThread;
};
}
I get following errors:
"thread" is not supported when compiling with /clr or /clr:pure.
a member of a managed class cannot be of a non-managed class type
error directive: ERROR: Concurrency Runtime is not supported when
compiling /clr.
error directive: is not supported when compiling with /clr or
/clr:pure.
A friend of mine says it is impossible to write multi-threaded code in Visual Studio without using external packages like boost. It kind of seemed unlikely since Multithreading has already been already there for C# and VB for a long time!
So, I would be happy if you could let me know what I am doing wrong OR if it is really hard to have a managed multithreaded .dll developed in c++?
You can use the managed thread library: System.Threading.Thread.
#pragma once
using namespace System;
using namespace std;
using namespace System::Threading;
namespace MultiThread_module {
public ref class multiThreadingTest
{
public:
String^ GetVersion();
int someNumber;
private:
Thread^ testThread;
};
}
If it's purely CLR then I suggest you use the example provided before. If you want to have the threading completely native and just use CLR to wrap it, I'd like to refer you to my answer at : using clr and std::thread
Might be an old question, but I looked into this same problem before. Since CLR does not allow you to include std::thead at
compile time, you could try to use it only at linking time. Normally
you could resolve this be forward declaring the class in your header
and including them only in your cpp files. However you can forward
declare your own classes in header files, but you can't for
classes in namespace std. According to the C++11 standard, 17.6.4.2.1:
The behavior of a C++ program is undefined if it adds declarations or
definitions to namespace std or to a namespace within namespace std
unless otherwise specified.
A workaround for this problem is to create a threading class that
inherits from std::thread that you can forward declare. The header
file for this class would look like:
#pragma once
#include <thread>
#include <utility>
namespace Threading
{
class Thread : std::thread
{
public:
template<class _Fn, class... _Args> Thread(_Fn fn, _Args... args) : std::thread(fn, std::forward<_Args...>(args...))
{
}
private:
};
}
In the header file that you would like to use the thread you can do
forward declare it like:
#pragma once
// Forward declare the thread class
namespace Threading { class Thread; }
class ExampleClass
{
public:
ExampleClass();
void ThreadMethod();
private:
Threading::Thread * _thread;
};
In your source file you can then use the theading class like:
#include "ExampleClass.h"
#include "Thread.h"
ExampleClass::ExampleClass() :
{
_thread = new Threading::Thread(&ExampleClass::ThreadMethod, this);
}
void ExampleClass::ThreadMethod()
{
}
Hope it might help anyone.
I have a rather decent sized project and I am trying to split it up in multiple files. I am using MSVC++ 2010 as a Windows Form's application. I am trying to be able to access the form controls from the namespace and class from a user defined class in a separate file. The main autogenerated class is defined as so:
main.cpp:
namespace MyMainForm {
...
...
...
public ref class Form1: public System::Windows::Forms::Form
{
...
...
};
}
Than I have a class I created that I want to be able to access the GUI components that are in the Form1 class although they are "private" So I tried inherting as MyMainForm::Form1 but does not seem to work.
mynewclass.cpp:
class MyNewClass {
...
...
};
Any thoughts? Thanks for your help!
Edit:
When inherting like so:
class MyNewClass : MyMainForm::Form1 {
I get an error like this:
error C2654: 'MyMainForm' : is not a class or namespace name
error C2504: 'Form1' : base class undefined
The name of MyMainForm IS a namespace though defined in the main.cpp
I'm working on a project in c++ and I stuck with no idea what is wrong. I've writen 4 classes and everything looked fine during work (under visual studio 2010). VS 'saw' all the definition, i could use auto-fill and sudgestions, but when I tried to compile the project it sudennly went blind. It's like I didnt include headers or something (which I did). The strange thing is there is no problem with working with those classes on VS (i can ctrl+space for hint, list of attributes and methods and all that stuff) but when i try to compile it says "ClassName" is not a type.
Quick sample of problem below:
ProButton.cpp:
#include "ProButton.h"
using namespace pGUI;
ProButton::ProButton( ... )
: ProControl( ... )
{
...
}
ProButton.h:
#ifndef __PRO_BUTTON__
#define __PRO_BUTTON__
#include <string>
#include "ProControl.h"
namespace pGUI
{
class ProButton :
public pGUI::ProControl
{
public:
//attributes
...
public:
//methods
...
};
}
#endif
but compiler says:
Error 291 error C2653: 'ProButton' : is not a class or namespace name
for this line in ProButton.cpp: ProButton::ProButton( ... )
It also says:
Error 23 error C2039: 'ProControl' : is not a member of 'pGUI'
Error 24 error C2504: 'ProControl' : base class undefined
and all similar errors for whole project. I have no idea what is wrong. Looks like my VS broke :D
Of course those (...) means there is code there, just not that important for now. I can upload all solution somewhere fi it will help.
edit//
About namespaces, all header files (classes declaration) are defined in namespace with:
namespace pGUI{
class ProClass
{
};
}
all definitions for these classes (in ProClass.cpp) are using:
using namespace pGUI;
at the beginning.
I think the problem is with order of including files.
Im not sure how this is supposed to be done. So far i have 4 classes that:
class ProGUI:
has a pointer to ProContainer
includes: ProContainer and ProControl
class ProContainer:
has pointers to: ProGUI and ProControl
class ProControl:
has a pointer to ProContainer
includes ProButton
is a base class for ProButton
class ProButton:
is a sub-class of ProControl
Those classes also uses irrlicht library and I'm not sure where to include it.
I had it included in my main file just before #include "ProGUI.h". This is also the only include in main. ProGUI.h .
//EDIT 2 -> solved
It was a problem with includes. I needed to rethink my inclusion order and add some forward declarations. Anyway that all seemed strange and took me a lot of time to figure i out. Thx for help. :)
It seems that you are using following statement:
using namespace pGUI;
Just before the class declaration:
class ProControl
{
};
Instead of using following approach:
namespace pGUI
{
class ProControl
{
};
}
The using namespace, as it says uses a namespace. You need to explicitly put something a namespace using namespace keyword followed by braces!
using namespace pGUI informs the compiler that it should look in the pGUI namespace to resolve existing names.
To declare or implement something in a namespace you need to be more specific. with either:
namespace pGUI
{
ProButton::ProButton( ... ) : ProControl( ... )
{
...
}
}
or:
pGUI::ProButton::ProButton( ... ) : ProControl( ... )
{
....
}
Personally, I consider any use of using namespace to be a lazy programmer hack that completely defeats the point of namespaces. But I digress. :)
I need to make a new object of a cli class in plain C++ code.
I am new to cli, please help
my cli class:
using namespace System;
using namespace System::Windows::Forms;
using namespace CrystalDecisions::Shared;
using namespace CrystalDecisions::CrystalReports::Engine;
using namespace CrystalDecisions::Windows::Forms;
namespace CrystalRapport {
// This is the main form that will hold the viewer control.
ref class ViewForm : public System::Windows::Forms::Form
{
private:
//Declare the Viewer Control, Report Document, and other
//objects needed to set the connection information.
public:
ViewForm()..
void InitForm()..
//This function initializes the form and adds the viewer to the form.
void ViewForm_Load(System::Object^ sender, System::EventArgs^ e)..
};
}
You need to use gcnew if you want to create .NET object in CLI C++.
ref class Student
{
...
};
...
Student^ student = gcnew Student();
student->SelectSubject("Math", 97);
Ref:
http://www.codeproject.com/Articles/17787/C-CLI-in-Action-Instantiating-CLI-classes
I found an example. Use .NET Assemblies in Native C++ Applications
http://msdn.microsoft.com/en-us/vstudio/bb892742.aspx
If you create a C# Crystal Reports project you can use this example.
(with some changes)