Visual C++ 2010 Express GUI noob

Hi all,

I've created a class to control a robotic arm via USB. It works perfectly in the command line but I cannot make any headway getting it to work with a MS Visual C++ 2010 express Form. I include the header file, but whenever I try and create an object in Form1.h I get a linker error. I have tons of C++ experiences regarding backend stuff, but this is my first time playing with a GUI and I am getting my butt kicked. I really have googled the hell out of this and cannot find the solution.

What is the proper way to allow a Form's button to activate a function in a separate class? That is, given, RoboticArm.h, where do I include the header file and where do I create an Object
RoboticArm TestArm ;
so that when I click the button, in the Click event I can say, TestArm.Move(); , or some similar solution.

Thanks for any help, I really appreciate your time.

Regards,

Rudolf
Last edited on
Post some class code and post some of your form code lets see what you have
Hi bobdabilder,

Thanks for the reply, I believe I'm really getting confused with namespaces, but I've tried in vain to resolve this.
Robotic arm header file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef OWI535_H_INCLUDED
#define OWI535_H_INCLUDED

#include <libusb.h>

class OWI535
{
public:

	OWI535();
	~OWI535();

	void searchlightOn ();

	void searchlightOff();

	void gripperOpen();
	void gripperClose();

	void wristUp();
	void wristDown();

	void elbowUp();
	void elbowDown();

	void shoulderUp();
	void shoulderDown();

	void baseClockwise();
	void baseCounterClockwise();

	void armStop();


private:
	
	int setupUsbAndConnect();
	int armExecute();
	void tearDownUsb();

	int moveResolution ;

	unsigned char robotCommand[3];

	
};

#endif 


Here is the main cpp file where the code breaks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// ArmGUI.cpp : main project file.

#include "stdafx.h"
#include "Form1.h"
#include "OWI535.h"
using namespace ArmGUI;

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
	//THIS LINE HERE BREAKS THE BUILD
	OWI535 testArm;
	//THIS LINE HERE BREAKS THE BUILD

	// Enabling Windows XP visual effects before any controls are created
	Application::EnableVisualStyles();
	Application::SetCompatibleTextRenderingDefault(false); 

	// Create the main window and run it
	Application::Run(gcnew Form1());
	
	return 0;
}


I don't know why the line where I try and create an object OWI535 breaks the build, but it does, with this error:
ArmGUI.obj : error LNK2019: unresolved external symbol "public: __clrcall OWI535::OWI535(void)" (??0OWI535@@$$FQAM@XZ) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)

Additionally, here is Form1.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#pragma once

namespace ArmGUI {
	
	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 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: System::Windows::Forms::Button^  button1;
	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->button1 = (gcnew System::Windows::Forms::Button());
			this->SuspendLayout();
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(12, 12);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(75, 23);
			this->button1->TabIndex = 0;
			this->button1->Text = L"button1";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(284, 262);
			this->Controls->Add(this->button1);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->ResumeLayout(false);

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

			 }
	};


}



If you can tell me where to create my object and how to create it so that this builds I'd be very very grateful. :)

Thanks for your time,

Rudolf
I have tons of C++ experiences


Your posted code is not written in C++ language, it is written in C++/CLI Microsoft only proprietary language.
@ Modoran,

Thanks for the help bud. miss quote: "...regarding backend stuff", as in DSP work and embedded systems. This is my first time dealing with MS VS and its GUI wizard (There's a hint in the title). Honestly, thanks for pointing out that it's not standard C++.

Seeing as you're such a kind troll, would you mind pointing out where my blatant idiocy and inexperience has led me astray? I need a form with 6 buttons and each button has to call one function - the allure of a 5 minute point-and-click solution was great. Would you say for such a simple requirement it would be better to drop the proprietary stuff and setup a Qt/wxWidgets system on windows? Coincidentally I see wxWidgets has actually released binaries for MS VS for the first time... I have to develop in MS VS because I'm inheriting a project and a colleague that only works on the Windows platform in MS VS.

Anyway, any help will greatly be appreciated to get the proprietary stuff to work if the folks on this forum don't mind it. In the mean time I'll get a wxWidget project up and running.

Regards,

Rudolf
MS Visual Studio can use standard C++ as well, select "win32 application" from project wizard. If you use Express Edition, then there the resource editor is not included ( you could create a simple dialog-based application which uses only win33api directly and use a 3rd party resource editor for free, like resedit, which generates the neccesary files for you which must be added to VS project using a drag & drop interface)
http://www.resedit.net/
to assign event to a control double click on that control where have u drawed it
and then don't chage anything in properties tab, nor the name of function
Silverstar is correct. Double click the button on design view to add code to the event. Did you add your header file to the project by right clicking the project folder and selecti g add existing item ?
Hi guys,

Thanks for all the replies. Modoran, resedit ia very useful. I've downloaded the Win7 SDK and see how that goes.

Silvestar/bobdbilder, I understand how it is supposed to work from the VB6 and Delphi 6 work I've done, but it's not. :)

I've given up trying to get this to work - I'm obviously doing something wrong but I'm running out of time on how to fix it. I've pulled in all my source code and header files that created the API, moved all the include directives to stdafx.h and now I'm just compiling and linking everything in one project to one executable. This is working and I'll leave it at that for now.

Again, thanks for the replies, and thanks for the resedit tool, I really appreciate it.

Regards,

Rudolf
Quick question:

Did you add the import library for your arm dll to the linker input. The error you're getting is a linker error.

I'm guessing your robot arm control library is a native DLL?

I've linked unmanaged i.e. native DLLs to managed i.e. C++/CLR code and it just works, although I instantiated my objects on the unmanaged heap, rather than as concrete objects e.g. In your form class, add a pointer to your object, and create it with new, and destroy it with delete (rather than using gcnew as you would with ref classes). Then you shoudl be able to call methods on your object using the standard -> operator.

Last edited on
Topic archived. No new replies allowed.