Namespace with 2 forms - winforms

I have namespace "Client" with form MainWindow and form MyForm
MainWindow creates MyForm.
MainWindow.h
#pragma once
namespace Client {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public ref class MainWindow : public System::Windows::Forms::Form
{
public:
MainWindow(void)
{
InitializeComponent();
}
....
....
....
}
in MyForm.h i write this:
#pragma once
namespace Client {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public ref class MyForm : public System::Windows::Forms::Form
{
private:
MainWindow ^f; //this is my problem
public:
MyForm(void)
{
InitializeComponent();
}
......
......
......
}
After compile, i have this error in line MainWindow ^f;:
1>c:\users\user\desktop\testlist\client\MyForm.h(17): error C2143: syntax error : missing ';' before '^'
1>c:\users\user\desktop\testlist\client\MyForm.h(17): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1> MyForm.cpp
If i write this Client::MainWindow ^f;:
1>c:\users\user\desktop\testlist\client\MyForm.h(17): error C2039: 'MainWindow' : is not a member of 'Client'
1>c:\users\user\desktop\testlist\client\MyForm.h(17): error C2143: syntax error : missing ';' before '^'
1>c:\users\user\desktop\testlist\client\MyForm.h(17): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1> MainWindow.cpp
1 errror - The form is a member of Client, why?
if add #include "MainWindow.h", errors are on MainWindow ^f;:
1>c:\users\user\desktop\testlist\client\MyForm.h(19): error C2143: syntax error : missing ';' before '^'
1>c:\users\user\desktop\testlist\client\MyForm.h(19): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1> MainWindow.cpp
How can i fix this problem?
______________________________Update for ArnonZilca
Myform - its a ref class, so i use ref struct and instead of mreoer myvar; i write mreoer ^myvar;
Errors in mreoer ^myvar; :
1>c:\users\user\desktop\testlist\client\MyForm.h(20): error C2143: syntax error : missing ';' before '^'
1>c:\users\user\desktop\testlist\client\MyForm.h(20): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\user\desktop\client\client\MyForm.h(155): error C2227: left of '->Print' must point to class/struct/union/generic type
1> MainWindow.cpp
_________________________________UPDATE
So in Myform.h i write this:
#pragma once
namespace Client {
ref class MainWindow;
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public ref class MyForm : public System::Windows::Forms::Form
{
private:
MainWindow ^f; //this is my problem
public:
MyForm(void)
{
InitializeComponent();
}
......
......
......
}
and if i use this variable (^f) in MyForm.h i have this errors on line where i using it:
\users\user\desktop\client\client\MyForm.h(155): error C2027: use of undefined type 'Client::MainWindow'
1> c:\users\user\desktop\client\client\MyForm.h(8) : see declaration of 'Client::MainWindow'
MainWindow have public method void Print () { cout << "HEY" << endl; }
In MyForm.h i do this: f->Print();

This tends to be a bit rough on programmers that are used to more recent languages. But this is normal kind of problem to have, C++/CLI inherits the compilation model of the C++ language. It is a single-pass compiler, all definitions must be known before you can use them. A model that dates from the previous century, back when 64KB of RAM fit in shoebox and cost an arm and three legs.
Technically it isn't quite that bad, C++ is more like a 1.5 pass compiler. You can refer ahead to class members inside inline function definitions. Which doesn't exactly help to diagnose this kind of problem :)
But you must do the C++ dance here, your MyForm.h file can contain a forward declaration, ref class MainWindow; gets that done. But any code that dereferences members of f must only appear in MyForm.cpp file. That .cpp file can #include both MyForm.h and MainWindow.h so all type definitions are available. And yes, that does mean that you may well have to move methods that were added by the designer from the .h file to the .cpp file. Do not panic, it's normal.

It seems you forgot to include the header where Client::MainWindow is defined

Related

"variable namespace is undeclared" error in Polymer

I am trying to create a new helper file in a Polymer project.
helper.html looks like this:
<script src="helper.ts"></script>
Helper looks like this:
namespace my_namespace {
export function foo(){}
}
I get several errors including "variable namespace is undeclared", "Parse error. Semi-colon expected", "variable missing_expression is undeclared", "Parse error. primary expression expected".
Check for these things:
Your namespace must match the name field in your tf_web_library declaration in your BUILD file
Add both your helper.html and helper.js files to your BUILD file.
In helper.html, the src field should be helper**.js** not helper**.ts**

'Application': is not a class or namespace name

I'm trying to utilize Cryptopp AES Library on C++ Form App. by using the Visual Studio 2015 with Update 2.
The thing is that I have to use "No common Runtime Support". However when I do this, It gives me some errors, like:
Severity Code Description Project File Line Suppression State
Error C2653 'Application': is not a class or namespace name SON c:\Users\Win\documents\visual studio 2015\Projects\SON\SON\MyForm.cpp 18
Severity Code Description Project File Line Suppression State
Error C2871 'Data': a namespace with this name does not exist SON c:\users\win\documents\visual studio 2015\projects\son\son\MyForm.h 9
Severity Code Description Project File Line Suppression State
Error C2871 'Drawing': a namespace with this name does not exist SON c:\users\win\documents\visual studio 2015\projects\son\son\MyForm.h 10
Severity Code Description Project File Line Suppression State
Error C3861 'EnableVisualStyles': identifier not found SON c:\Users\Win\documents\visual studio 2015\Projects\SON\SON\MyForm.cpp 18
But, when I build the code with Common Language Runtime Support, it doesn't give any error, but this time I couldn't create a UI for Form App.
Here are my CPP code, I didn't make any changes on it
#include "MyForm.h"
#include <iostream>
#include <string>
using namespace System;
using namespace System::Windows::Forms;
#include "C:\Users\Win\Desktop\cryptopp562\osrng.h"
using CryptoPP::AutoSeededRandomPool;
[STAThread]
void Main(array<std::string^>^ args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
MyForm form;
Application::Run(%form);
}
Thanks in advance.
You need to change MyForm form to [Application name]::MyForm form

How to use XmlnsDefinition in VB.net

I have a solution with two projects: a WPF sample application called "WPFSample" and a class library project called "ReferencedAssembly". "WPFSample" references "ReferencedAssembly".
The project "ReferencedAssembly" contains a couple of classes. Every class has its own namespace, i.e. "MyClassLibrary" or "MyClassLibrary.MyOtherTypes". A sample class with the namespace "MyClassLibrary" is called "Movie".
Now I want to map the .NET namespace to the XAML namespace using the URL "http://schemas.emmbee.de/". For this purpose I added the following lines to AssemblyInfo.vb in the "WPFSample" project and build it afterwards:
Imports System.Windows.Markup
<Assembly: XmlnsPrefix("http://schemas.emmbee.de/", "ra")>
<Assembly: XmlnsDefinition("http://schemas.emmbee.de/", "ReferencedAssembly.MyClassLibrary")>
<Assembly: XmlnsDefinition("http://schemas.emmbee.de/", "ReferencedAssembly.MyClassLibrary.MyOtherTypes")>
In XAML I add the namespace definition like this:
<xmlns:ra="http://schemas.emmbee.de">
If I want to use the "Movie" class with
<ra:Movie/>
I receive the error, that the class "Movie" doesn't exists in namespace "http://schemas.emmbee.de".
If I instead add a namespace definition in this way:
<xmlns:ra="clr-namespace:ReferencedAssembly.MyClassLibrary;assembly=ReferencedAssembly">
all works fine.
What is wrong with the XmlnsDefinition?
I found it out.The Namespace mappings
Imports System.Windows.Markup
<Assembly: XmlnsPrefix("http://schemas.emmbee.de/", "ra")>
<Assembly: XmlnsDefinition("http://schemas.emmbee.de/", "ReferencedAssembly.MyClassLibrary")>
<Assembly: XmlnsDefinition("http://schemas.emmbee.de/", "ReferencedAssembly.MyClassLibrary.MyOtherTypes")>
must be included in the "AssemblyInfo.vb" in the assembly "ReferencedAssembly", not in the assembly "WPFSample".

Angular basic tutorial do not work with Windows?

I want to learn Angular so I started with there tutorial here, its really basic but that does not stop me from get ALOT of exception.
I installed latest and stable of every compinent Git, Node and python but when running
npm install
I got some exceptions, I then reinstalled components to a older specific version(no backward compability here). This got my a couple of steps but yet again other exceptions was thrown like this :
C:\Program Files
(x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Platform.t
argets(44,5): error MSB8020: The builds tools for v120 (Platform
Toolset = 'v12 0') cannot be found. To build using the v120 build
tools, either click the Proj ect menu or right-click the solution, and
then select "Update VC++ Projects..."
Why would it need MSBuild? Anyway, I changed the config like this
npm config set msvs_version 2012
And now I get even more exceptions!?, like these :
C:\Users\bob\angular-phonecat\node_modules\karma\node_modules\socket.io\node_modules\socket.io-client\node_modules\ws>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node rebuild )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
bufferutil.cc
C:\Users\bob\.node-gyp\4.2.3\include\node\v8.h(336): error C2988: unrecognizable template declaration/definition [C:\Users\bob\angular-phonecat\node_modules\karma\node_modules\socket.io\node_modules\socket.io-client\node_modules\ws\build\bufferutil.vcxproj]
C:\Users\bob\.node-gyp\4.2.3\include\node\v8.h(336): error C2059: syntax error : 'using' [C:\Users\bob\angular-phonecat\node_modules\karma\node_modules\socket.io\node_modules\socket.io-client\node_modules\ws\build\bufferutil.vcxproj]
C:\Users\bob\.node-gyp\4.2.3\include\node\v8.h(469): error C2988: unrecognizable template declaration/definition [C:\Users\bob\angular-phonecat\node_modules\karma\node_modules\socket.io\node_modules\socket.io-client\node_modules\ws\build\bufferutil.vcxproj]
C:\Users\bob\.node-gyp\4.2.3\include\node\v8.h(469): error C2059: syntax error : 'using' [C:\Users\bob\angular-phonecat\node_modules\karma\node_modules\socket.io\node_modules\socket.io-client\node_modules\ws\build\bufferutil.vcxproj]
C:\Users\bob\.node-gyp\4.2.3\include\node\v8.h(576): error C2061: syntax error : identifier 'WeakCallbackType' [C:\Users\bob\angular-phonecat\node_modules\karma\node_modules\socket.io\node_modules\socket.io-client\node_modules\ws\build\bufferutil.vcxproj]
C:\Users\bob\.node-gyp\4.2.3\include\node\v8.h(642) : see reference to class template instantiation 'v8::PersistentBase<T>' being compiled
C:\Users\bob\.node-gyp\4.2.3\include\node\v8.h(637): error C2253: 'PersistentBase<T>' : pure specifier or abstract override specifier only allowed on virtual function [C:\Users\bob\angular-phonecat\node_modules\karma\node_modules\socket.io\node_modules\socket.io-client\node_modules\ws\build\bufferutil.vcxproj]
C:\Users\bob\.node-gyp\4.2.3\include\node\v8.h(844): error C2253: 'Global<T>' : pure specifier or abstract override specifier only allowed on virtual function [C:\Users\bob\angular-phonecat\node_modules\karma\node_modules\socket.io\node_modules\socket.io-client\node_modules\ws\build\bufferutil.vcxproj]
C:\Users\bob\.node-gyp\4.2.3\include\node\v8.h(847) : see reference to class template instantiation 'v8::Global<T>' being compiled
C:\Users\bob\.node-gyp\4.2.3\include\node\v8.h(852): error C2988: unrecognizable template declaration/definition [C:\Users\bob\angular-phonecat\node_modules\karma\node_modules\socket.io\node_modules\socket.io-client\node_modules\ws\build\bufferutil.vcxproj]
C:\Users\bob\.node-gyp\4.2.3\include\node\v8.h(852): error C2059: syntax error : 'using' [C:\Users\bob\angular-phonecat\node_modules\karma\node_modules\socket.io\node_modules\socket.io-client\node_modules\ws\build\bufferutil.vcxproj]
C:\Users\bob\.node-gyp\4.2.3\include\node\v8.h(915): error C2989: 'v8::HandleScope' : class template has already been declared as a non-class template [C:\Users\bob\angular-phonecat\node_modules\karma\node_modules\socket.io\node_modules\socket.io-client\node_modules\ws\build\bufferutil.vcxproj]
C:\Users\bob\.node-gyp\4.2.3\include\node\v8.h(319) : see declaration of 'v8::HandleScope'
C:\Users\bob\.node-gyp\4.2.3\include\node\v8.h(949): error C2989: 'v8::EscapableHandleScope' : class template has already been declared as a non-class template [C:\Users\bob\angular-phonecat\node_modules\karma\node_modules\socket.io\node_modules\socket.io-client\node_modules\ws\build\bufferutil.vcxproj]
C:\Users\bob\.node-gyp\4.2.3\include\node\v8.h(135) : see declaration of 'v8::EscapableHandleScope'
C:\Users\bob\.node-gyp\4.2.3\include\node\v8.h(979): error C2989: 'v8::Data' : class template has already been declared as a non-class template [C:\Users\bob\angular-phonecat\node_modules\karma\node_modules\socket.io\node_modules\socket.io-client\node_modules\ws\build\bufferutil.vcxproj]
C:\Users\bob\.node-gyp\4.2.3\include\node\v8.h(74) : see declaration of 'v8::Data'
C:\Users\bob\.node-gyp\4.2.3\include\node\v8.h(1118): error C2989: 'v8::Script' : class template has already been declared as a non-class template [C:\Users\bob\angular-phonecat\node_modules\karma\node_modules\socket.io\node_modules\socket.io-client\node_modules\ws\build\bufferutil.vcxproj]
C:\Users\bob\.node-gyp\4.2.3\include\node\v8.h(96) : see declaration of 'v8::Script'
C:\Users\bob\.node-gyp\4.2.3\include\node\v8.h(1559): error C2989: 'v8::StackTrace' : class template has already been declared as a non-class template [C:\Users\bob\angular-phonecat\node_modules\karma\node_modules\socket.io\node_modules\socket.io-client\node_modules\ws\build\bufferutil.vcxproj]
C:\Users\bob\.node-gyp\4.2.3\include\node\v8.h(101) : see declaration of 'v8::StackTrace'
C:\Users\bob\.node-gyp\4.2.3\include\node\v8.h(1622): error C2989: 'v8::StackFrame' : class template has already been declared as a non-class template [C:\Users\bob\angular-phonecat\node_modules\karma\node_modules\socket.io\node_modules\socket.io-client\node_modules\ws\build\bufferutil.vcxproj]
C:\Users\bob\.node-gyp\4.2.3\include\node\v8.h(100) : see declaration of 'v8::StackFrame'
C:\Users\bob\.node-gyp\4.2.3\include\node\v8.h(2031): error C2989: 'v8::Value' : class template has already been declared as a non-class template [C:\Users\bob\angular-phonecat\node_modules\karma\node_modules\socket.io\node_modules\socket.io-client\node_modules\ws\build\bufferutil.vcxproj]
C:\Users\bob\.node-gyp\4.2.3\include\node\v8.h(108) : see declaration of 'v8::Value'
Is it really supose to be this hard to install Angular on a Windows 8.1 computer? Or are my environment faulted in any way?
How do I solve this problem? Have search alot but no help.
I've installed Node/NPM/Angular on 4 differents machines of mine. This is what I've done to make it all work:
Visual C++ 2005
Visual C++ 2008
Visual c++ 2010
Python 2.7
I don't know why, I've just followed the console erros and all worked.
Yes, it is hard. The reason for this is that (dependend on the node modules you install) node-gyp rebuilds things to make them run on the platform, in your case Windows 8.
There are lots and lots of questions how to solve these kind of errors. Prepare yourself to install Python and Visual Studio like explained here.
Good luck! Working with node.js on Linux or OSX is much easier....

Managed array issue in C++/CLI

compilng with /clr
array<Byte>^ byteArray = gcnew array<Byte>(25);
Why would I get these compiler errors?
error C2065: 'array' : undeclared identifier
error C2065: 'gcnew' : undeclared identifier
error C2275: 'System::Byte' : illegal use of this type as an expression
error C3192: syntax error : '^' is not a prefix operator (did you mean '*'?)
I am calling this method inside a class with
using namespace System;
__gc class MyClass
This feels like I am missing something very basic here. Even this causes errors:
array<Byte>^ byteArray;
or
array<Byte> * byteArray;
Thank you!!
The syntax __gc class was used in the, now obsolete, Managed C++. In C++/CLI, use ref class.
For more information see the section Syntax changes in the Wikipedia article C++/CLI.

Resources