|
-
October 2nd, 2010, 03:37 AM
#7
Re: Using C++ for USB interfacing
Hi Alex, the full code is about 30k characters long, even after I removed unnecessary bits, I've attached it as a .txt file though. Anyway, the code below is from the start to where the error is. I've changed it a little with reference to the link you gave along with the errors that were listed.
Code:
// zebraDlg.cpp : implementation file
//
#using <System.dll>
#include "stdafx.h"
#include "zebra.h"
#include "zebraDlg.h"
#include <string>
#include <fstream>
#include "windows.h"
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include "usb.h"
#include <setupapi.h>
#include <hidsdi.h>
using namespace System;
using namespace System::Object;
using namespace System::MarshalByRefObject;
using namespace System::ComponentModel;
using namespace System::ComponentModel::Component;
using namespace System::ComponentModel::Container;
using namespace System::Collections;
using namespace System::Windows;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO::Ports;
using namespace System::Threading;
using namespace System::ComponentModel::ComponentResourceManager
extern "C" {
#include "hidsdi.h"
}
#pragma comment(lib, "setupapi.lib")
#pragma comment(lib, "hid.lib")
#include "bliondi.h" //self defined header
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
//class for error dialog
class CerrorDlg : public CDialog
{
public:
CerrorDlg() :CDialog(IDD) {} //*******Updated constructor
// Dialog Data
enum { IDD = IDD_error };
};
//public ref class zebra : public System::Windows::Forms::Form
public ref class SerialPort : public Component;
{
public:
void InitializeComponent()
{
this->components = gcnew System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager ^resources = gcnew System.ComponentModel.ComponentResourceManager(CzebraDlg.typeid);
this->SerialPort = gcnew System.IO.Ports.SerialPort(this->components);
}
}
internal:
{
//VB TO C++ CONVERTER TODO TASK: In C++, an object cannot reference itself in its class-level declarations:
array<System.IO.Ports.SerialPort^> ^SerialPort = gcnew array<System.IO.Ports.SerialPort^>(this->components + 1);
};
The error messages are below
1>.\zebraDlg.cpp(54) : error C2504: 'Component' : base class undefined
1>.\zebraDlg.cpp(54) : error C2143: syntax error : missing ',' before ';'
1>.\zebraDlg.cpp(65) : error C2470: 'internal' : looks like a function definition, but there is no parameter list; skipping apparent body
1>.\zebraDlg.cpp(59) : error C2039: 'components' : is not a member of 'SerialPort'
1> .\zebraDlg.cpp(54) : see declaration of 'SerialPort'
1>.\zebraDlg.cpp(59) : error C2061: syntax error : identifier 'System'
1>.\zebraDlg.cpp(60) : error C2882: 'System' : illegal use of namespace identifier in expression
1>.\zebraDlg.cpp(60) : error C2228: left of '.ComponentModel' must have class/struct/union
1>.\zebraDlg.cpp(60) : error C2228: left of '.ComponentResourceManager' must have class/struct/union
1>.\zebraDlg.cpp(60) : error C2065: 'resources' : undeclared identifier
1>.\zebraDlg.cpp(60) : error C2061: syntax error : identifier 'System'
1>.\zebraDlg.cpp(61) : error C2273: 'function-style cast' : illegal as right side of '->' operator
1>.\zebraDlg.cpp(61) : error C2061: syntax error : identifier 'System'
As for the button, since an error above stated that "SerialPort1" was not part of "SerialPort", I replaced "SerialPort1" with "SerialPort" alone. It seemed to have fixed that one error but now I have a load of 'syntax errors' the code and errors are below.
Code:
void CzebraDlg::OnBnClickedButton5()
{
try
{
if (SerialPort.IsOpen)
{
SerialPort.Close();
}
SerialPort.PortName = "COM" + IDC_EDIT2.Text;
SerialPort.Open();
}
catch (Exception ^ex)
{
CerrorDlg cid; //*** Create an instance of our dialog
cid.DoModal(); //Display Dialog box
}
}
And the errors for the button now are
1>.\zebraDlg.cpp(1691) : error C2059: syntax error : '.'
1>.\zebraDlg.cpp(1692) : error C2143: syntax error : missing ';' before '{'
1>.\zebraDlg.cpp(1693) : error C2143: syntax error : missing ';' before '.'
1>.\zebraDlg.cpp(1693) : error C2143: syntax error : missing ';' before '.'
1>.\zebraDlg.cpp(1695) : error C2143: syntax error : missing ';' before '.'
1>.\zebraDlg.cpp(1695) : error C2143: syntax error : missing ';' before '.'
1>.\zebraDlg.cpp(1696) : error C2143: syntax error : missing ';' before '.'
1>.\zebraDlg.cpp(1696) : error C2143: syntax error : missing ';' before '.'
Perhaps I failed to include something? Thanks a lot in advance!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|