Windows Forms problem z WiimoteLib

0

Witam tak jak w temacie mam problem odnośnie powyższej biblioteki. Biblioteke dodałem poprzez References->Add new References i wybrałem plik WiimoteLib.dll. Następnie postępowałem zgodnie z przykładami z C# tj analogicznie jak tam starałem się stworzyć

#pragma once

namespace formatka {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	using namespace WiimoteLib;
	/// <summary>
	/// Summary for Form1
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
				
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
		
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;
**		Wiimote wm  = gcnew Wiimote(); //error C3845: 'formatka::Form1::wm': only static data members can be initialized inside a ref class or value type**

#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->SuspendLayout();
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(13, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(284, 262);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->ResumeLayout(false);

		}
#pragma endregion
	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
**Wiimote wm  = gcnew Wiimote(); //error C3767: 'WiimoteLib::Wiimote::Wiimote': candidate function(s) not accessible**
			 }
	};
}

Gwiazdkami zaznaczyłem miejsca w których występowanie tego co chce daje mi takie błędy czytałem że problem z dostępnością wiąże się niby z tym że funkcje nie są publiczne czy coś. Jestem dość bardzo początkującym programistą dlatego prosiłbym o w miarę jasne odpowiedzi.
Strona do lekkiego tutoriala http://channel9.msdn.com/coding4fun/articles/Managed-Library-for-Nintendos-Wiimote

0

Że niby gcnew ma ci zwrócić wskaźnik do wskaźnika? gcnew zwraca handle do obiektu na stercie zarządzanej.
Dlaczego próbujesz pisać w C++/CLI kompletnie nie znając tego języka?

1
private:
    Wiimote ^wm;
    ...
    Form1(void)
    {
        InitializeComponent();
        //
        //TODO: Add the constructor code here
        wm = gcnew Wiimote();
        //
    }

dwie sprawy:

  1. jeśli Wiimote to klasa w C# (class) to w C++/CLI powinien być daszek ^ przy typie, a jeśli w C# jest struct to bez daszka (wiem, bardzo upraszczam)
  2. tak inicjalizować od razu pola klasy można tylko gdy są static, pozostałe w konstruktorze. Niestety, nawet w nadchodzącym Visualu 11 tego jeszcze nie poprawili.
0

Wielkie dzięki

0

Kolejny problem złapał mnie przy użyciu poniższych funkcji

#pragma endregion
	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) 
			 { 

				 wm->WiimoteChanged+=wm_WiimoteChanged;

				 wm->Connect();
				 
			 }
	private: void button1_Click(System::Object^  sender, System::EventArgs^  e) 
        {
            wm->SetLEDs(1);
            checkBox1->Checked = wm->WiimoteState->ButtonState.A;
        }

	 void wm_WiimoteChanged(System::Object^ sender, WiimoteChangedEventArgs^ args)
			 {
				 //current state information
				 WiimoteState ^ws= args->WiimoteState;

			 }
	private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
			 }
	};
}

Kompilator zgłasza mi błąd
error C3867: 'formatka::wm_WiimoteChanged': function call missing argument list; use '&formatka::wm_WiimoteChanged' to create a pointer to member
tyczy się to tego użycia
wm->WiimoteChanged+=wm_WiimoteChanged;
jak wrzuce
wm->WiimoteChanged+=wm_WiimoteChanged();
to kompilator zwraca ze funkcja nie przyjmuje 0 argumentow i faktycznie nie zwraca 0 ale nie wiem jakie tam wpisac
Prosiłbym jakąś mądrą głowe o pomoc bo ja juz wysiadam, cały czas się też wzoruje na przykładach w C# i jakos opornie ale idzie

0

@myxhir pytanie z innej beczki.
Co to będzie za projekt i jakiego urządzenia będziesz używał?
Ja bawiłem się kiedyś wagą (Badanie środka ciężkości człowieka) dość fajna zabawka.

0

mamy zrobić formatkę pod konsole WII i za jej pomocą mamy wybierać układ robota Staubli - układ globalny, narzędzia itp. i ruchy z WII mają być przekładane na ruch manipulatora. A używać będziemy nunchaka czy jak to się pisze i Wii remote.

0
wm->WiimoteChanged+=wm_WiimoteChanged;
wm->WiimoteChanged += gcnew WiimoteChangedEventHandler(this, &Form1::wm_WiimoteChanged);

I znowu: Teoretycznie skrócona składnia z C# mogłaby działać. Ale niestety nie jest to tak zrobione, i trzeba jawnie stworzyć delegata.

w C# też tak można:

wm.WiimoteChanged += new WiimoteChangedEventHandler(this, wm_WiimoteChanged);

(nadal krócej…)

0

wówczas kompilator wyrzuca mi - przy Twojej propozycji
wm->WiimoteChanged += gcnew WiimoteChangedEventHandler(this, &Form1::wm_WiimoteChanged);

d:\documents\visual studio 2010\projects\formatka\formatka\Form1.h(101): error C2061: syntax error : identifier 'WiimoteChangedEventHandler'

co ciekawe analizujac tutorial do tej biblioteki w C# jest inne uzycie

// setup the event to handle state changes
    wm.WiimoteChanged += wm_WiimoteChanged; 

a funkcja jest napisana

 void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args)
{
    // current state information
    WiimoteState ws = args.WiimoteState;

    // write out the state of the A button    
    Debug.WriteLine(ws.ButtonState.A);
}

co dla mnie jest dziwne ze wrzucana jest funkcja bez argumentow ale może C# tak ma
wrzuce moze cały kod na tą chwilę jaki mam, może będzie łatwiej to ogarnąć

#pragma once
namespace formatka {
	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	using namespace WiimoteLib;
	/// <summary>
	/// Summary for Form1
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{		
	public:
		Wiimote ^wm;
		WiimoteCollection ^mWC;
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			wm = gcnew Wiimote();
			mWC = gcnew WiimoteCollection();
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::CheckBox^  checkBox1;
	private: System::Windows::Forms::TextBox^  textBox1;
	protected: 

	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->checkBox1 = (gcnew System::Windows::Forms::CheckBox());
			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
			this->SuspendLayout();
			// 
			// checkBox1
			// 
			this->checkBox1->AutoSize = true;
			this->checkBox1->Location = System::Drawing::Point(113, 76);
			this->checkBox1->Name = L"checkBox1";
			this->checkBox1->Size = System::Drawing::Size(80, 17);
			this->checkBox1->TabIndex = 0;
			this->checkBox1->Text = L"checkBox1";
			this->checkBox1->UseVisualStyleBackColor = true;
			// 
			// textBox1
			// 
			this->textBox1->Location = System::Drawing::Point(36, 13);
			this->textBox1->Name = L"textBox1";
			this->textBox1->Size = System::Drawing::Size(100, 20);
			this->textBox1->TabIndex = 1;
			this->textBox1->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_TextChanged);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(410, 262);
			this->Controls->Add(this->textBox1);
			this->Controls->Add(this->checkBox1);
			this->Margin = System::Windows::Forms::Padding(1, 3, 1, 3);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) 
			 { 

			wm->WiimoteChanged += gcnew WiimoteChangedEventHandler(this, &Form1::wm_WiimoteChanged); /////// Wspomniany error d:\documents\visual studio 2010\projects\formatka\formatka\Form1.h(98): error C2061: syntax error : identifier 'WiimoteChangedEventHandler'
1>  Generating Code...
			wm->Connect();
				 
			 }
	private: void button1_Click(System::Object^  sender, System::EventArgs^  e) 
        {
            wm->SetLEDs(1);
            checkBox1->Checked = wm->WiimoteState->ButtonState.A;
        }

	 void wm_WiimoteChanged(System::Object^ sender, WiimoteChangedEventArgs^ args)
			 {
				 //current state information
				 WiimoteState ^ws= args->WiimoteState;

			 }
	private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
			 }
	};
}

 
0

co dla mnie jest dziwne ze wrzucana jest funkcja bez argumentow ale może C# tak ma
Bo wrzucana jest funkcja a nie wynik wywołania tej funkcji.

// Wspomniany error d:\documents\visual studio 2010\projects\formatka\formatka\Form1.h(98): error C2061: syntax error : identifier 'WiimoteChangedEventHandler'
To są naprawdę podstawy: radzenie sobie z błędem. Zobacz jakiego typu dokładnie jest to zdarzenie WiimoteChanged. Ja strzelałem tak tylko na podstawie gógla.

0

wiem że podstawy, wczoraj zacząłem przegladac neta i widze że zanim się stworzy delegata trzeba użyc slowa delegate, w tym przypadku też nie należałoby tego zrobic ?

1

pomógł następujący zabieg

private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) 
			 { 
				 wm->WiimoteChanged += gcnew System::EventHandler<WiimoteChangedEventArgs^>(this, &Form1::wm_WiimoteChanged);
			 }

	private: System::Void wm_WiimoteChanged(System::Object^ sender, WiimoteChangedEventArgs^  args)
			 {
				 //current state information
				 WiimoteState ^ws= args->WiimoteState;
				 checkBox1->Checked = wm->WiimoteState->ButtonState.A;
			 } 

1 użytkowników online, w tym zalogowanych: 0, gości: 1