Hi guys, I'm trying to link a Micro-controller board to my C++ program to control the relays on it. The vendor provided a test software in VB that involved entering the COM port number (4 in my case) and clicking a button to sync up with it, the full software and info on the board is here: [http://www.oceancontrols.com.au/KTA-223.html] under the link 'VB6 test software' link (I've also included .txt attachments of the VB code). I've tried converting the code to C++ along with using namespaces, etc, but I seem to have hit some problems. The code is pretty long so I'll post the relevant things and the errors.
Namespaces being used
using namespace System;
using namespace System::ComponentModel::Container;
using namespace System::ComponentModel;
using namespace System::Windows;
using namespace System::Windows::Forms;
Component Initialisation from VB changed to C++
public ref class zebra : public System::Windows::Forms::Form
{
public:
zebra(void)
{
InitializeComponent();
{
this->components = gcnew System::ComponentModel::Container();
System::ComponentModel::ComponentResourceManager ^resources = gcnew System::ComponentModel::ComponentResourceManager(zebra::typeid);
this->SerialPort1 = gcnew System::IO::Ports::SerialPort(this->components);
}
}
}
internal:
array<System::IO::Ports::SerialPort^> ^SerialPort1 = gcnew array<System::IO::Ports::SerialPort^>(this->components + 1);
For the above code, I got the following errors:
error C3083: 'Windows': the symbol to the left of a '::' must be a type
error C3083: 'Forms': the symbol to the left of a '::' must be a type
error C2039: 'Form' : is not a member of 'System'
error C2504: 'Form' : base class undefined
error C2470: 'internal' : looks like a function definition, but there is no parameter list; skipping apparent body
error C3861: 'InitializeComponent': identifier not found
error C2039: 'components' : is not a member of 'zebra'.\zebraDlg.cpp(44) : see declaration of 'zebra'
'ComponentModel': the symbol to the left of a '::' must be a type
and many others. I suspect I may gave failed to include something or that my syntax symbols and function calls are in error.
Lastly, the button that reads the COM port number from a text box to sync with the device (code below).
void CzebraDlg::OnBnClickedButton5()
{
try
{
if (SerialPort1::IsOpen)
{
SerialPort1->Close();
}
SerialPort1->PortName = "COM" + IDC_EDIT2->Text;
SerialPort1->Open();
}
catch (Exception ^ex)
{
CerrorDlg cid; //*** Create an instance of our dialog
cid.DoModal(); //Display Dialog box
}
}
For the button control, I get errors like
error C2227: left of '->Close' must point to class/struct/union/generic type
error C2227: left of '->PortName' must point to class/struct/union/generic type
and others all dealing with the '->' symbols.
I'm not really sure what the compiler is telling me but I suspect it is just a few lines I may not have. Can anyone help? The VB code I derived it from is from the link above. Thanks a lot in advance!! I'm using MFC to build the GUI.