There is a line #include "Algorithm.h" in Form1.h
Algorithm.h and Form1.h are the automatic codes of winforms in VisualStudio2010, and they are in the same directory.
I added only 2 lines; the "include" and the instruction in line 40 (this line is in the definition of the class Form1 - "public ref class Form1 : public System::Windows::Forms::Form"
what is the problem??
thanks!
Related
We are receiving the following exceptions in one of our code :
java.lang.IllegalAccessError: tried to access class base.BaseMessage from class message.beans.TerminalPowerCommandProducer$Proxy$_$$_WeldSubclass
Our class structure is as follows :
The Base Message creator class with default message properties
package messages.base
//... required imports
abstract class BaseMessage{ //some protected variables and methods }
the intermediate message class with extension to BaseMessage some additional properties for specific message types
package messages.base
//... required imports
public abstract class PowerMessage extends BaseMessage {//some more protected variables and Logger(using #Inject) and methods}
The actual implementation of the above abstract classes
package messages.beans
//... required imports
#Named
public class TerminalCommandMessage extends PowerMessage {// some more variables with injections and methods with abstract method implementation}
This class is now injected in some other classes :
package messages.beans
#Named
public class TerminalPowerCommandProducer {
#Inject
TerminalCommandMessage commandMessage
//some other code
}
We are receiving exception as reported above.
We are using WildFly version 10.1.0 Final with jdk 8
Is there an issue with the way we have consumed it?
Because if we mark the BaseMessage class as public it all works fine.
I have a lib project with a few utility functions of mine and it works fine with console applications.
Now I started a Windows Form application, included that lib and it gives me an "Exception thrown at 0xxxx (ntdll.dll) in : 0xC0000005: Access violation reading location 0xxxx."
The application code is just the code Visual Studio added to the new project. No code of my own added, except the #include of my lib header.
I commented my lib code, piece by piece and found that when I comment the line "ofstream MyLog;" the exception goes away.
I did rebuild this project from scratch a couple of time: same results. Pretty much: (1) Create new WinForm project, (2) add existing project MyLibTest, (3) 'Add reference...' to connect them, (4) add the #include in the main cpp and (5) run it.
I dont know if this is relevant, but since I started this WinForm project, Visual Studio spent many, many hours downloading symbols from Microsoft Symbol Server. (elsewhere here at stackoverflow it is said that this MS server is really slow)
This is relevant: I am new to c++ and I have created several mini projects in Visual Studio 2015 to experiment with several aspects of the language (file reading, classes, string manipulation, vectors, lists, Windows forms, etc). Now I am trying to put all of them together.
My code
//------ MyLibTest.h --------
#pragma once
#include <stdio.h>
#include <string>
#include <map>
#include <Windows.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <time.h>
#include <cstdarg>
#include <memory>
//------ MyLibTest.cpp --------
#include "MyLibTEST.h"
using namespace std;
ofstream MyLog; // <<<< if i comment this line, the Access violation exception does not happen
WinForm application CODE added by Visual Studio 2015
//------ MyForm.h --------
#pragma once
namespace MyWindowsFormTest {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~MyForm()
{
if (components)
{
delete components;
}
}
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->components = gcnew System::ComponentModel::Container();
this->Size = System::Drawing::Size(300,300);
this->Text = L"MyForm";
this->Padding = System::Windows::Forms::Padding(0);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
}
#pragma endregion
};
}
//------ MyForm.cpp --------
#include "Q:\MyDesv\Visual Studio Projects\Projects\MyLibTest\MyLib\MyLibTest.h"
#include "MyForm.h"
using namespace System;
using namespace System::Windows::Forms;
[STAThread]
void Main(array<String^>^ args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
MyWindowsFormTest::MyForm form;
Application::Run(%form);
}
Call Stack
ntdll.dll!RtlValidateHeap() Unknown
KernelBase.dll!_HeapValidate#12() Unknown
> ucrtbased.dll!_CrtIsValidHeapPointer(const void * block) Line 1407 C++
ucrtbased.dll!_msize_dbg(void * block, int block_use) Line 1059 C++
ucrtbased.dll!_msize(void * block) Line 38 C++
ucrtbased.dll!_recalloc_dbg(void * block, unsigned int count, unsigned int element_size, int block_use, const char * file_name, int line_number) Line 784 C++
ucrtbased.dll!_register_onexit_function::__l2::<lambda>() Line 112 C++
ucrtbased.dll!__crt_seh_guarded_call<int>::operator()<void <lambda>(void),int <lambda>(void) &,void <lambda>(void) >(__acrt_lock_and_call::__l2::void <lambda>(void) && setup, _register_onexit_function::__l2::int <lambda>(void) & action, __acrt_lock_and_call::__l2::void <lambda>(void) && cleanup) Line 204 C++
ucrtbased.dll!__acrt_lock_and_call<int <lambda>(void) >(const __acrt_lock_id lock_id, _register_onexit_function::__l2::int <lambda>(void) && action) Line 912 C++
ucrtbased.dll!_register_onexit_function(_onexit_table_t * table, int(*)() function) Line 84 C++
CppWinForm2.exe!_onexit(int(*)() function) Line 268 C++
CppWinForm2.exe!atexit(void(*)() function) Line 276 C++
CppWinForm2.exe!std::`dynamic initializer for '_Fac_tidy_reg''() Line 65 C++
[External Code]
mscoreei.dll!__CorExeMain#0() Unknown
mscoree.dll!__CorExeMain_Exported#0() Unknown
kernel32.dll!#BaseThreadInitThunk#12() Unknown
ntdll.dll!__RtlUserThreadStart() Unknown
ntdll.dll!__RtlUserThreadStart#8() Unknown
This is a known issue (since around 2007). It is related to having a winforms project with native C++ static objects. It seems that Winform projects by default skip the crt initialization, which obviously has an impact on any static objects.
You can read more about it in This link from a Microsoft support person and This link from another stackoverflow question.
Basically your Winforms project has a Main function that looks something like
[STAThread]
void Main(array<String^>^ args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
MyWindowsFormTest::MyForm form;
Application::Run(%form);
}
First step is change the main declaration to:
int main(..)
Then go Project->Properties->Linker->Advanced->Entry Point. Change this from "Main" to something like "?mainCRTStartupStrArray##$$FYMHP$01EAPE$AAVString#System###Z". This may vary depending on your VS version.
IMO though, unless you are deep into project development rather don't use WinForms. As I understand it, the support is discontinued... .
Environment
Visual Studio 2013 and C++/CLI.
The (ho/e)rror
I faced a situation of IntelliSense giving error on a compiler compliant row. Thus a false positive.
The error is the following:
IntelliSense: function "< full qualified method name >" cannot be
called with the given argument list argument types are: <
expected argument type > object type is: < object type >
What happened
I made a UserControl. There I declared a custom event with relative delegate. I created a form. In form constructor I alloc a my user control instance and try to attach a form method to the control custom event.
Compiler says everything is ok. IntelliSense tells me that event attachment mismatches types.
How to reproduce
I digged in the problem and created an essential context that should reproduce the problem:
Create a solution with two projects: FavaTest (as ClassLibrary) and FavaForm (as Console application...or whatever).
In FavaTest create a UserControl whose name is FavaClass and paste the following in FavaClass.h.
#pragma once
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
namespace FavaTest {
public ref class FavaClass : public System::Windows::Forms::UserControl
{
public:
FavaClass(void)
{
InitializeComponent();
}
// -- here defines very simple event --
delegate void FavaDelegate();
event FavaDelegate^ FavaEvent;
protected:
~FavaClass()
{
if (components)
{
delete components;
}
}
private:
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->SuspendLayout();
//
// FavaClass
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->Name = L"FavaClass";
this->Size = System::Drawing::Size(249, 147);
this->ResumeLayout(false);
}
#pragma endregion
};
}
In project FavaForm create a Form whose name is LaForm and paste the following in LaForm.h
namespace FavaForm {
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 LaForm : public System::Windows::Forms::Form
{
public:
LaForm(void)
{
InitializeComponent();
// here simply allocs a FavaClass object and try to attach to FavaEvent event
FavaTest::FavaClass ^item = gcnew FavaTest::FavaClass();
item->FavaEvent += gcnew FavaTest::FavaClass::FavaDelegate(this, &LaForm::onfava);
}
void onfava(){}
protected:
~LaForm()
{
if (components)
{
delete components;
}
}
private:
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->SuspendLayout();
//
// LaForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(368, 261);
this->Name = L"LaForm";
this->Text = L"LaForm";
this->ResumeLayout(false);
}
#pragma endregion
};
}
Build FavaTest
In FavaForm project common properties add a new reference to FavaTest in order to use its generated dll as a dependencie
Build solution.
Now, while the compiler heralds everything is fine, you should see that IntelliSense complains something on the event attachment row, with the following errore message:
IntelliSense: function "FavaTest::FavaClass::FavaEvent::add" cannot be called with the given argument list
argument types are:
(FavaTest::FavaClass::FavaDelegate ^)
object type is: FavaTest::FavaClass ^
Ready to run package
I packaged all this in a side-test-standalone-solution zip file in order to make it possibile to unzip and run, but unfortunately (IMHO also questionably) I cannot post it here dued to SE guidelines, so it's up to you to make the debug context according to the above.
The question
I could also be missing something, but I used several times this algorithm before and it worked perfectly, now I'm experiencing this on two different machines (VS2013 and VS2015). Does this error apply to you too? And what's wrong with IntelliSense? It is such a simple scenario that I can't imagine I'm the only one experiencing it. I found no clue on the Internet though.
Solved.
It came out that in order to avoid IntelliSense to get crazy, the delegate definition has to be out of the event parent class scope. So in my situation all I had to do to get things right (for IntelliSense) was to move delegate outside the class adding the public keyword, such as:
namespace FavaTest
{
public delegate void FavaDelegate(); // moved out of the class with "public"
public ref class FavaClass : public System::Windows::Forms::UserControl
{
public:
[...]
// -- here defines very simple event --
// delegate row away from here
event FavaDelegate^ FavaEvent;
[...]
}
}
I'm new to WPF and I'm actually migrating a project from Silverlight to WPF 4.0 and my problem is that I can't find the equivalence for IApplicationService and IApplicationLifetimeAware.
The library and namespace System.Windows is well loaded, yet I have the error message;
"The type or namespace name 'IApplicationLifetimeAware' could not be found'.
Any idea what am i missing please.
Thanks
Finally I found that there's no direct migration and all need to be recoded.
but if anyone is implementing IApplicationService and IApplicationLifetimeAware just to access the StatService(), you can simply make the method public, without argument..
public void StartService()
{
.
.
}
and call the method during instanciation in App.xaml.cs
public App()
{
this.Startup += this.Application_Startup;
this.Exit += this.Application_Exit;
InitializeComponent();
OfflineDatabaseService x = new OfflineDatabaseService();
x.StartService();
}
i have a winforms project, and i created a class on assembly A that inherits from System.Windows.Forms.Form to serve as a base class for various forms on my project, the base class is something like:
public partial class DataForm<T> : Form where T : class
{
T currentRecord;
protected T CurrentRecord
{
get
{
return currentRecord;
}
set
{
currentRecord = value;
CurrentRecordChanged();
}
}
}
Now, when i create a form on assembly B that inherits from my DataForm the designer won't load, but if i compile it the app runs fine.
The form looks like:
public partial class SomeTableWindow : DataForm<SomeTable>
{
public SomeTableWindow ()
{
InitializeComponent();
}
}
The error I'm getting is:
The designer could not be shown for this file because none of the classes within it can be designed.
The designer inspected the following classes in the file: CultivosWindow --- The base
class 'TripleH.Erp.Controls.DataForm' could not be loaded. Ensure the assembly has
been referenced and that all projects have been built.
Instances of this error (1)
1. Hide Call Stack
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host)
Is this a bug on the designer?, Am I doing something wrong? Is there some workaround this?
Thank you for your help
It's a known limitation. Basically you can work around this by declaring another class that inherits from the generic class.
For instance:
class Generic<T> : UserControl
{
}
then
class GenericInt : Generic<int> { }
then use GenericInt instead of Generic. SUcks I know.