|
Repost: please read the guidelines on posting to these forums and post your question once only.
|
|
|
|
|
I have a data glove, its driver is visual c++ version. I want to code a test program in managed C++ has some trouble.
===========================================================
// fglove.h
//
typedef struct
{
// The contents of this struct are platform-dependent and subject to
// change. You should not manipulate the contents of this struct directly.
void *m_pStuff;
} fdGlove;
fdGlove *fdOpen(char *pPort);
===========================================================
//FrmDataGlove.h
#pragma once
#include < stdio.h >
#include < stdlib.h >
#include < vcclr.h >
#include "fglove.h"
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Runtime::InteropServices;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO::Ports;
public ref class FrmDataGlove : public System::Windows::Forms::Form
{
public: fdGlove *m_pGlove;
private: System::Void btnGetData_Click(System::Object^ sender, System::EventArgs^ e)
{
char* p1;
p1=StringToPChar(this->serialPort->PortName);
m_pGlove=fdOpen(p1); //maybe there has wrong syntax
}
}
Above is I capture some code in my project, when I compile the compiler has the wrong message:
--------------------------------------------------------------------------------------------
錯誤 1 error LNK2028: 無法解析的語彙基元 (0A000010) "struct fdGlove * __clrcall fdOpen(char *)" (?fdOpen@@$$FYMPAUfdGlove@@PAD@Z) 在函式 "private: void __clrcall DataGlove::FrmDataGlove::btnGetData_Click(class System::Object ^,class System::EventArgs ^)" (?btnGetData_Click@FrmDataGlove@DataGlove@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z) 中被參考 DataGlove.obj
-------------------------------------------------------------------------------------------
錯誤 2 error LNK2019: 無法解析的外部符號 "struct fdGlove * __clrcall fdOpen(char *)" (?fdOpen@@$$FYMPAUfdGlove@@PAD@Z) 在函式 "private: void __clrcall DataGlove::FrmDataGlove::btnGetData_Click(class System::Object ^,class System::EventArgs ^)" (?btnGetData_Click@FrmDataGlove@DataGlove@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z) 中被參考 DataGlove.obj
-------------------------------------------------------------------------------------------
錯誤 3 fatal error LNK1120: 2 個無法解析的外部符號 C:\Documents and Settings\jimhuang688\My Documents\Visual Studio 2005\Projects\DataGlove\Debug\DataGlove.exe
-------------------------------------------------------------------------------------------
|
|
|
|
|
jetjeankimo wrote: when I compile the compiler has the wrong message:
These are linker errors.
How fdGlove struct is compiled (compiler switch used)? From the __clrcall in the error message, I am guessing you are using /clr:pure switch to compile managed code.
Possible reason for this error will be in the mismatch of calling conventions. You native code will be using the normal __cdecl and the managed code compiled with /clr:pure will be using __clrcall . To resolve, try to use the same calling convention for both. I believe, you need /clr switch.
|
|
|
|
|
Thanks for your suggestion.
My compiler setting in common language runtime support that has /clr, /clr:pure, /clr:safe and /clr:oldSyntax. I choose the /clr.
C/C++ advanced setting has _cdel(/Gd), _fastcal(/Gr) and /stdcall(/Gz). I choose the _cdecl(/Gd).
After compile, it has these errors.
--------------------------------------------------------------------------------------------------
錯誤 1 error LNK2028: 無法解析的語彙基元 (0A000010) "struct fdGlove * __cdecl fdOpen(char *)" (?fdOpen@@$$FYAPAUfdGlove@@PAD@Z) 在函式 "private: void __clrcall DataGlove::FrmDataGlove::btnGetData_Click(class System::Object ^,class System::EventArgs ^)" (?btnGetData_Click@FrmDataGlove@DataGlove@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z) 中被參考 DataGlove.obj
-----------------------------------------------------------------------------------------------------
錯誤 2 error LNK2019: 無法解析的外部符號 "struct fdGlove * __cdecl fdOpen(char *)" (?fdOpen@@$$FYAPAUfdGlove@@PAD@Z) 在函式 "private: void __clrcall DataGlove::FrmDataGlove::btnGetData_Click(class System::Object ^,class System::EventArgs ^)" (?btnGetData_Click@FrmDataGlove@DataGlove@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z) 中被參考 DataGlove.obj
------------------------------------------------------------------------------------------------------
錯誤 3 fatal error LNK1120: 2 個無法解析的外部符號 C:\Documents and Settings\jimhuang688\My Documents\Visual Studio 2005\Projects\DataGlove\Debug\DataGlove.exe
---------------------------------------------------------------------------------------------------------
|
|
|
|
|
Is your native struct and managed code in same project? If both are different projects, what type of project is the native one? Is common language runtime support is enabled there?
|
|
|
|
|
My project is CLR Windows Form Application project,and just use one project. The /clr setting is enabled. Thank you!
|
|
|
|
|
Can you post your native struct's code here?
|
|
|
|
|
/*--------------------------------------------------------------------------*/
// fglove.h
//
// 5DT Data Glove driver SDK
// Version 1.04a
//
// Copyright (C) 2000-2001, 5DT <Fifth Dimension Technologies>
// http://www.5dt.com/
/*--------------------------------------------------------------------------*/
#ifndef _FGLOVE_H_
#define _FGLOVE_H_
/*--------------------------------------------------------------------------*/
enum EfdGloveHand
{
FD_HAND_LEFT, // left-handed glove
FD_HAND_RIGHT // right-handed glove
};
enum EfdGloveTypes
{
FD_GLOVENONE, // no glove
FD_GLOVE7, // 7-sensor
FD_GLOVE7W, // 7-sensor, wireless
FD_GLOVE16, // 16-sensor
FD_GLOVE16W // 16-sensor, wireless
};
enum EfdSensors
{
FD_THUMBNEAR=0,
FD_THUMBFAR,
FD_THUMBINDEX,
FD_INDEXNEAR,
FD_INDEXFAR,
FD_INDEXMIDDLE,
FD_MIDDLENEAR,
FD_MIDDLEFAR,
FD_MIDDLERING,
FD_RINGNEAR,
FD_RINGFAR,
FD_RINGLITTLE,
FD_LITTLENEAR,
FD_LITTLEFAR,
FD_THUMBPALM,
FD_WRISTBEND,
FD_PITCH,
FD_ROLL
};
/*--------------------------------------------------------------------------*/
typedef struct
{
// The contents of this struct are platform-dependent and subject to
// change. You should not manipulate the contents of this struct directly.
void *m_pStuff;
} fdGlove;
/*--------------------------------------------------------------------------*/
fdGlove *fdOpen(char *pPort);
int fdClose(fdGlove *pFG);
int fdGetGloveHand(fdGlove *pFG);
int fdGetGloveType(fdGlove *pFG);
int fdGetNumSensors(fdGlove *pFG);
void fdGetSensorRawAll(fdGlove *pFG, unsigned short *pData);
unsigned short fdGetSensorRaw(fdGlove *pFG, int nSensor);
void fdSetSensorRawAll(fdGlove *pFG, unsigned short *pData);
void fdSetSensorRaw(fdGlove *pFG, int nSensor, unsigned short nRaw);
void fdGetSensorScaledAll(fdGlove *pFG, float *pData);
float fdGetSensorScaled(fdGlove *pFG, int nSensor);
int fdGetNumGestures(fdGlove *pFG);
int fdGetGesture(fdGlove *pFG);
void fdGetCalibrationAll(fdGlove *pFG, unsigned short *pUpper, unsigned short *pLower);
void fdGetCalibration(fdGlove *pFG, int nSensor, unsigned short *pUpper, unsigned short *pLower);
void fdSetCalibrationAll(fdGlove *pFG, unsigned short *pUpper, unsigned short *pLower);
void fdSetCalibration(fdGlove *pFG, int nSensor, unsigned short nUpper, unsigned short nLower);
void fdResetCalibration(fdGlove *pFG);
void fdGetSensorMaxAll(fdGlove *pFG, float *pMax);
float fdGetSensorMax(fdGlove *pFG, int nSensor);
void fdSetSensorMaxAll(fdGlove *pFG, float *pMax);
void fdSetSensorMax(fdGlove *pFG, int nSensor, float fMax);
void fdGetThresholdAll(fdGlove *pFG, float *pUpper, float *pLower);
void fdGetThreshold(fdGlove *pFG, int nSensor, float *pUpper, float *pLower);
void fdSetThresholdAll(fdGlove *pFG, float *pUpper, float *pLower);
void fdSetThreshold(fdGlove *pFG, int nSensor, float fUpper, float fLower);
void fdGetGloveInfo(fdGlove *pFG, unsigned char *pData);
void fdGetDriverInfo(fdGlove *pFG, unsigned char *pData);
/*--------------------------------------------------------------------------*/
#endif // #ifndef _FGLOVE_H_
/*--------------------------------------------------------------------------*/
#pragma once
#include < stdio.h >
#include < stdlib.h >
#include < vcclr.h >
#include "fglove.h"
namespace DataGlove
{
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Runtime::InteropServices;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO::Ports;
/// <summary>
/// Form1 的摘要
///
/// 警告: 如果您變更這個類別的名稱,就必須變更與這個類別所依據之所有 .resx 檔案關聯的
/// Managed 資源編譯器工具的 'Resource File Name' 屬性。
/// 否則,這些設計工具
/// 將無法與這個表單關聯的當地語系化資源
/// 正確互動。
/// </summary>
public ref class FrmDataGlove : public System::Windows::Forms::Form
{
public:
FrmDataGlove(void)
{
InitializeComponent();
array<String^>^ serialPorts = nullptr;
try
{
// Get a list of serial port names.
serialPorts = SerialPort::GetPortNames();
}
catch (Win32Exception^ ex)
{
Console::WriteLine(ex->Message);
}
for each (String^ str in serialPorts)
{
this->cmbCOM->Items->Add(str);
}
//
// SerialPort
//
this->serialPort->PortName="COM1";
this->serialPort->BaudRate=9600;
this->serialPort->DataBits=8;
this->serialPort->Parity=Parity::None;
this->serialPort->StopBits=StopBits::One;
this->cmbCOM->SelectedItem="COM1";
this->cmbBudRte->SelectedIndex=2;
this->cmbParity->SelectedIndex=0;
this->cmbStopBits->SelectedIndex=0;
this->cmbDataBits->SelectedIndex=0;
}
protected:
/// <summary>
/// 清除任何使用中的資源。
/// </summary>
~FrmDataGlove()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::ComboBox^ cmbCOM;
private: System::Windows::Forms::Label^ lblCOM;
private: System::Windows::Forms::Label^ lblBudRte;
private: System::Windows::Forms::ComboBox^ cmbBudRte;
private: System::Windows::Forms::ComboBox^ cmbDataBits;
private: System::Windows::Forms::Label^ lblDataBit;
private: System::Windows::Forms::ComboBox^ cmbParity;
private: System::Windows::Forms::Label^ lblParity;
private: System::Windows::Forms::Label^ lblStopBit;
private: System::Windows::Forms::ComboBox^ cmbStopBits;
private: System::Windows::Forms::Button^ btnConnect;
private: System::Windows::Forms::Button^ btnDisConnect;
private: System::Windows::Forms::Label^ lblStatus;
private: System::IO::Ports::SerialPort^ serialPort;
private: System::Windows::Forms::GroupBox^ grpRS232;
private: System::Windows::Forms::GroupBox^ grpGesture;
private: System::Windows::Forms::Label^ lblTilt1;
private: System::Windows::Forms::Label^ lblGesture1;
private: System::Windows::Forms::Label^ lblTilt;
private: System::Windows::Forms::Label^ lblGesture;
private: System::Windows::Forms::Button^ btnGetData;
private: System::ComponentModel::IContainer^ components;
public: fdGlove *m_pGlove;
#pragma region Windows Form Designer generated code
/// <summary>
/// 此為設計工具支援所需的方法 - 請勿使用程式碼編輯器修改這個方法的內容。
///
/// </summary>
void InitializeComponent(void)
{
this->components = (gcnew System::ComponentModel::Container());
this->cmbCOM = (gcnew System::Windows::Forms::ComboBox());
this->lblCOM = (gcnew System::Windows::Forms::Label());
this->lblBudRte = (gcnew System::Windows::Forms::Label());
this->cmbBudRte = (gcnew System::Windows::Forms::ComboBox());
this->cmbDataBits = (gcnew System::Windows::Forms::ComboBox());
this->lblDataBit = (gcnew System::Windows::Forms::Label());
this->cmbParity = (gcnew System::Windows::Forms::ComboBox());
this->lblParity = (gcnew System::Windows::Forms::Label());
this->lblStopBit = (gcnew System::Windows::Forms::Label());
this->cmbStopBits = (gcnew System::Windows::Forms::ComboBox());
this->btnConnect = (gcnew System::Windows::Forms::Button());
this->btnDisConnect = (gcnew System::Windows::Forms::Button());
this->lblStatus = (gcnew System::Windows::Forms::Label());
this->serialPort = (gcnew System::IO::Ports::SerialPort(this->components));
this->grpRS232 = (gcnew System::Windows::Forms::GroupBox());
this->grpGesture = (gcnew System::Windows::Forms::GroupBox());
this->lblTilt1 = (gcnew System::Windows::Forms::Label());
this->lblGesture1 = (gcnew System::Windows::Forms::Label());
this->lblTilt = (gcnew System::Windows::Forms::Label());
this->lblGesture = (gcnew System::Windows::Forms::Label());
this->btnGetData = (gcnew System::Windows::Forms::Button());
this->grpRS232->SuspendLayout();
this->grpGesture->SuspendLayout();
this->SuspendLayout();
//
// cmbCOM
//
this->cmbCOM->FormattingEnabled = true;
this->cmbCOM->Location = System::Drawing::Point(79, 18);
this->cmbCOM->Name = L"cmbCOM";
this->cmbCOM->Size = System::Drawing::Size(121, 20);
this->cmbCOM->TabIndex = 0;
this->cmbCOM->Text = L"COM1";
this->cmbCOM->SelectedIndexChanged += gcnew System::EventHandler(this, &FrmDataGlove::cmbCOM_SelectedIndexChanged);
//
// lblCOM
//
this->lblCOM->AutoSize = true;
this->lblCOM->Location = System::Drawing::Point(6, 18);
this->lblCOM->Name = L"lblCOM";
this->lblCOM->Size = System::Drawing::Size(53, 12);
this->lblCOM->TabIndex = 1;
this->lblCOM->Text = L"COM Port";
//
// lblBudRte
//
this->lblBudRte->AutoSize = true;
this->lblBudRte->Location = System::Drawing::Point(5, 44);
this->lblBudRte->Name = L"lblBudRte";
this->lblBudRte->Size = System::Drawing::Size(54, 12);
this->lblBudRte->TabIndex = 2;
this->lblBudRte->Text = L"Baud Rate";
//
// cmbBudRte
//
this->cmbBudRte->FormattingEnabled = true;
this->cmbBudRte->Items->AddRange(gcnew cli::array< System::Object^ >(5) {L"38400", L"19200", L"9600", L"4800", L"2400"});
this->cmbBudRte->Location = System::Drawing::Point(79, 44);
this->cmbBudRte->Name = L"cmbBudRte";
this->cmbBudRte->Size = System::Drawing::Size(121, 20);
this->cmbBudRte->TabIndex = 3;
this->cmbBudRte->Text = L"9600";
this->cmbBudRte->SelectedIndexChanged += gcnew System::EventHandler(this, &FrmDataGlove::cmbBudRte_SelectedIndexChanged);
//
// cmbDataBits
//
this->cmbDataBits->FormattingEnabled = true;
this->cmbDataBits->Items->AddRange(gcnew cli::array< System::Object^ >(4) {L"5", L"6", L"7", L"8"});
this->cmbDataBits->Location = System::Drawing::Point(79, 70);
this->cmbDataBits->Name = L"cmbDataBits";
this->cmbDataBits->Size = System::Drawing::Size(121, 20);
this->cmbDataBits->TabIndex = 4;
this->cmbDataBits->Text = L"5";
this->cmbDataBits->SelectedIndexChanged += gcnew System::EventHandler(this, &FrmDataGlove::cmbDataBits_SelectedIndexChanged);
//
// lblDataBit
//
this->lblDataBit->AutoSize = true;
this->lblDataBit->Location = System::Drawing::Point(12, 70);
this->lblDataBit->Name = L"lblDataBit";
this->lblDataBit->Size = System::Drawing::Size(47, 12);
this->lblDataBit->TabIndex = 5;
this->lblDataBit->Text = L"Data Bits";
//
// cmbParity
//
this->cmbParity->FormattingEnabled = true;
this->cmbParity->Items->AddRange(gcnew cli::array< System::Object^ >(5) {L"Even", L"Mark", L"None", L"Odd", L"Space"});
this->cmbParity->Location = System::Drawing::Point(79, 96);
this->cmbParity->Name = L"cmbParity";
this->cmbParity->Size = System::Drawing::Size(121, 20);
this->cmbParity->TabIndex = 6;
this->cmbParity->Text = L"None";
this->cmbParity->SelectedIndexChanged += gcnew System::EventHandler(this, &FrmDataGlove::cmbParity_SelectedIndexChanged);
//
// lblParity
//
this->lblParity->AutoSize = true;
this->lblParity->Location = System::Drawing::Point(27, 96);
this->lblParity->Name = L"lblParity";
this->lblParity->Size = System::Drawing::Size(32, 12);
this->lblParity->TabIndex = 7;
this->lblParity->Text = L"Parity";
//
// lblStopBit
//
this->lblStopBit->AutoSize = true;
this->lblStopBit->Location = System::Drawing::Point(12, 122);
this->lblStopBit->Name = L"lblStopBit";
this->lblStopBit->Size = System::Drawing::Size(47, 12);
this->lblStopBit->TabIndex = 8;
this->lblStopBit->Text = L"Stop Bits";
//
// cmbStopBits
//
this->cmbStopBits->FormattingEnabled = true;
this->cmbStopBits->Items->AddRange(gcnew cli::array< System::Object^ >(3) {L"One", L"OnePointFive", L"Two"});
this->cmbStopBits->Location = System::Drawing::Point(79, 122);
this->cmbStopBits->Name = L"cmbStopBits";
this->cmbStopBits->Size = System::Drawing::Size(121, 20);
this->cmbStopBits->TabIndex = 9;
this->cmbStopBits->Text = L"One";
this->cmbStopBits->SelectedIndexChanged += gcnew System::EventHandler(this, &FrmDataGlove::cmbStopBits_SelectedIndexChanged);
//
// btnConnect
//
this->btnConnect->Location = System::Drawing::Point(206, 18);
this->btnConnect->Name = L"btnConnect";
this->btnConnect->Size = System::Drawing::Size(135, 23);
this->btnConnect->TabIndex = 10;
this->btnConnect->Text = L"Connect";
this->btnConnect->UseVisualStyleBackColor = true;
this->btnConnect->Click += gcnew System::EventHandler(this, &FrmDataGlove::btnConnect_Click);
//
// btnDisConnect
//
this->btnDisConnect->Location = System::Drawing::Point(206, 45);
this->btnDisConnect->Name = L"btnDisConnect";
this->btnDisConnect->Size = System::Drawing::Size(135, 23);
this->btnDisConnect->TabIndex = 11;
this->btnDisConnect->Text = L"Dis-Connect";
this->btnDisConnect->UseVisualStyleBackColor = true;
this->btnDisConnect->Click += gcnew System::EventHandler(this, &FrmDataGlove::btnDisConnect_Click);
//
// lblStatus
//
this->lblStatus->BackColor = System::Drawing::Color::Red;
this->lblStatus->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
this->lblStatus->Location = System::Drawing::Point(347, 18);
this->lblStatus->Name = L"lblStatus";
this->lblStatus->Size = System::Drawing::Size(50, 50);
this->lblStatus->TabIndex = 12;
//
// grpRS232
//
this->grpRS232->Controls->Add(this->btnDisConnect);
this->grpRS232->Controls->Add(this->lblStatus);
this->grpRS232->Controls->Add(this->cmbCOM);
this->grpRS232->Controls->Add(this->lblCOM);
this->grpRS232->Controls->Add(this->btnConnect);
this->grpRS232->Controls->Add(this->lblBudRte);
this->grpRS232->Controls->Add(this->cmbStopBits);
this->grpRS232->Controls->Add(this->cmbBudRte);
this->grpRS232->Controls->Add(this->lblStopBit);
this->grpRS232->Controls->Add(this->cmbDataBits);
this->grpRS232->Controls->Add(this->lblParity);
this->grpRS232->Controls->Add(this->lblDataBit);
this->grpRS232->Controls->Add(this->cmbParity);
this->grpRS232->Location = System::Drawing::Point(12, 12);
this->grpRS232->Name = L"grpRS232";
this->grpRS232->Size = System::Drawing::Size(405, 149);
this->grpRS232->TabIndex = 13;
this->grpRS232->TabStop = false;
this->grpRS232->Text = L"RS232 Setting";
//
// grpGesture
//
this->grpGesture->Controls->Add(this->btnGetData);
this->grpGesture->Controls->Add(this->lblTilt1);
this->grpGesture->Controls->Add(this->lblGesture1);
this->grpGesture->Controls->Add(this->lblTilt);
this->grpGesture->Controls->Add(this->lblGesture);
this->grpGesture->Location = System::Drawing::Point(432, 12);
this->grpGesture->Name = L"grpGesture";
this->grpGesture->Size = System::Drawing::Size(200, 149);
this->grpGesture->TabIndex = 14;
this->grpGesture->TabStop = false;
this->grpGesture->Text = L"Gesture and Tilt";
//
// lblTilt1
//
this->lblTilt1->BackColor = System::Drawing::Color::White;
this->lblTilt1->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
this->lblTilt1->Location = System::Drawing::Point(91, 64);
this->lblTilt1->Name = L"lblTilt1";
this->lblTilt1->Size = System::Drawing::Size(100, 25);
this->lblTilt1->TabIndex = 3;
this->lblTilt1->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
//
// lblGesture1
//
this->lblGesture1->BackColor = System::Drawing::SystemColors::ControlLightLight;
this->lblGesture1->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
this->lblGesture1->Location = System::Drawing::Point(91, 20);
this->lblGesture1->Name = L"lblGesture1";
this->lblGesture1->Size = System::Drawing::Size(100, 25);
this->lblGesture1->TabIndex = 2;
this->lblGesture1->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
//
// lblTilt
//
this->lblTilt->AutoSize = true;
this->lblTilt->Location = System::Drawing::Point(64, 70);
this->lblTilt->Name = L"lblTilt";
this->lblTilt->Size = System::Drawing::Size(21, 12);
this->lblTilt->TabIndex = 1;
this->lblTilt->Text = L"Tilt";
//
// lblGesture
//
this->lblGesture->AutoSize = true;
this->lblGesture->Location = System::Drawing::Point(6, 26);
this->lblGesture->Name = L"lblGesture";
this->lblGesture->Size = System::Drawing::Size(79, 12);
this->lblGesture->TabIndex = 0;
this->lblGesture->Text = L"Current Gesture";
//
// btnGetData
//
this->btnGetData->Location = System::Drawing::Point(10, 96);
this->btnGetData->Name = L"btnGetData";
this->btnGetData->Size = System::Drawing::Size(181, 38);
this->btnGetData->TabIndex = 4;
this->btnGetData->Text = L"Get Data";
this->btnGetData->UseVisualStyleBackColor = true;
this->btnGetData->Click += gcnew System::EventHandler(this, &FrmDataGlove::btnGetData_Click);
//
// FrmDataGlove
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(648, 266);
this->Controls->Add(this->grpGesture);
this->Controls->Add(this->grpRS232);
this->Name = L"FrmDataGlove";
this->Text = L"Data Glove";
this->grpRS232->ResumeLayout(false);
this->grpRS232->PerformLayout();
this->grpGesture->ResumeLayout(false);
this->grpGesture->PerformLayout();
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void cmbCOM_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e)
{
if ( this->serialPort->IsOpen)
{
this->serialPort->Close();
this->serialPort->PortName=static_cast<String^>(this->cmbCOM->SelectedItem);
this->serialPort->Open();
}
else
{
this->serialPort->PortName=static_cast<String^>(this->cmbCOM->SelectedItem);
}
}
private: System::Void cmbBudRte_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e)
{
switch(cmbBudRte->SelectedIndex)
{
case 0:this->serialPort->BaudRate=38400;
case 1:this->serialPort->BaudRate=19200;
case 2:this->serialPort->BaudRate=9600;
case 3:this->serialPort->BaudRate=4800;
case 4:this->serialPort->BaudRate=2400;
}
}
private: System::Void cmbParity_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e)
{
switch(cmbParity->SelectedIndex)
{
case 0: this->serialPort->Parity=Parity::Even;
case 1: this->serialPort->Parity=Parity::Mark;
case 2: this->serialPort->Parity=Parity::None;
case 3: this->serialPort->Parity=Parity::Odd;
case 4: this->serialPort->Parity=Parity::Space;
}
}
private: System::Void cmbStopBits_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e)
{
switch(cmbStopBits->SelectedIndex)
{
case 0:this->serialPort->StopBits=StopBits::One;
case 1:this->serialPort->StopBits=StopBits::OnePointFive ;
case 2:this->serialPort->StopBits=StopBits::Two;
}
}
private: System::Void cmbDataBits_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e)
{
switch(cmbDataBits->SelectedIndex)
{
case 0:this->serialPort->DataBits=5;
case 1:this->serialPort->DataBits=6;
case 2:this->serialPort->DataBits=7;
case 3:this->serialPort->DataBits=8;
}
}
private: System::Void btnConnect_Click(System::Object^ sender, System::EventArgs^ e) {
this->serialPort->Open();
if (this->serialPort->IsOpen)
{
Color color;
this->lblStatus->BackColor=color.LimeGreen;
}
else
{
Color color;
this->lblStatus->BackColor=color.Red;
}
}
private: System::Void btnDisConnect_Click(System::Object^ sender, System::EventArgs^ e) {
this->serialPort->Close();
if (this->serialPort->IsOpen)
{
Color color;
this->lblStatus->BackColor=color.LimeGreen;
}
else
{
Color color;
this->lblStatus->BackColor=color.Red;
}
}
private: System::Void btnGetData_Click(System::Object^ sender, System::EventArgs^ e)
{
char* p1;
p1=StringToPChar(this->serialPort->PortName);
m_pGlove=fdOpen(p1);
}
private:char* StringToPChar(String^ str)
{
// Reference MSDN library example
// Pin memory so GC can't move it while native function is called
pin_ptr<const wchar_t> wch = PtrToStringChars(str);
// Conversion to char* :
// Can just convert wchar_t* to char* using one of the
// conversion functions such as:
// WideCharToMultiByte()
// wcstombs_s()
// ... etc
size_t convertedChars = 0;
size_t sizeInBytes = ((str->Length + 1) * 2);
errno_t err = 0;
char* ch = (char *)malloc(sizeInBytes);
err = wcstombs_s(&convertedChars,ch,sizeInBytes,wch,sizeInBytes);
if (err!= 0)
{
return 0;
}
else
{
return ch;
}
};
};
};
// DataGlove.cpp: 主要專案檔。
#include "stdafx.h"
#include "FrmDataGlove.h"
using namespace DataGlove;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// 建立任何控制項之前,先啟用 Windows XP 視覺化效果
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// 建立主視窗並執行
Application::Run(gcnew FrmDataGlove());
return 0;
}
Thank you very much.
|
|
|
|
|
Thank You! I find the error is the linker setting is not to be set the lib dependancy.
|
|
|
|
|
Where I can download spy++? I can't go to msdn because something is blocking my Internet Explorer from accessing any website related to microsoft. I'm using Visual C++ 2008 Express Edition
thanks for any question or answer
|
|
|
|
|
Hi,
Spy++ is distributed with all other versions of Visual Studio except the Express Edition. As far as I know its not available for free download. There are probably some good alternatives on the internet if you search.
You could however install a trial of a full version of Visual Studio 2008 [^] and Spy++ will be available in the installation.
Best Wishes,
-David Delaune
|
|
|
|
|
Randor wrote: You could however install a trial of a full version of Visual Studio 2008 [^] and Spy++ will be available in the installation.
But I have a nasty problem. I can't open any website related to microsoft or related to anti-virus. But I will download the trial version of Visual Studio 2008 via my mother's computer. Thanks
|
|
|
|
|
ant-damage wrote: But I have a nasty problem. I can't open any website related to microsoft or related to anti-virus. But I will download the trial version of Visual Studio 2008 via my mother's computer. Thanks
You might want to get a good anti-virus there.
|
|
|
|
|
About the trial version, it's too huge to download, and I don't have a fast internet connection, and I can only download 1GB of data per month.
|
|
|
|
|
Something that came up with a quick Google is this[^], which claims to be the "Compact equivalent of Spy++ with visual interface, versatile & easy to use"
Good luck.
|
|
|
|
|
|
|
I've been using the DeflateStream and the GZipStream for a while and recently I found out that both streams produced an excessive amount of data when compressing data.
Here is my question: Is there a bug in the compression algorythm?
|
|
|
|
|
ant-damage wrote: produced an excessive amount of data when compressing data
What are you compressing? The LZ77 algorithm can actually create MORE data depending on what your compressing.
ant-damage wrote: Is there a bug in the compression algorythm?
No.
Best Wishes,
-David Delaune
|
|
|
|
|
I'm compressing a binary file. it is a 678KB file, and after compressing all bytes of it with DeflateStream I've got 1MB of data. I used the zlib compression library on the same file and I'v got a smaller file with 671KB.
I searched around the web and I found out that it's possible that the DeflateStream algorythm has a bug, and generates too much data compared with the original file data.
|
|
|
|
|
ant-damage wrote: after compressing all bytes of it with DeflateStream I've got 1MB of data.
Did you mean compressing with GZipStream? Because... DeflateStream does not do compression.
ant-damage wrote: I searched around the web and I found out that it's possible that the DeflateStream algorythm has a bug, and generates too much data compared with the original file data.
The GZipStream class does not check for incompressible data. Yes it is possible to create more data.. this is the nature of the algorithm. I guess it would be better if the GZipStream class detected that it would be unable to compress the data. Classifying it as a bug is debatable.
I agree with you that the GZipStream class should be smart and detect this situation.
Best Wishes,
-David Delaune
|
|
|
|
|
Randor wrote: DeflateStream does not do compression
Yes it does, if we are to believe the documentation[^], compared to GZipStream it leaves out the CRC and things like that.
|
|
|
|
|
I have found that the results are better when you use the biggest possible Write (so buffer first, then write it all out at once). It's slower of course, but for some reason this implementation gives really poor results on small writes.
Such a big expansion seems excessive though. It can only happen due to crappy implementation, since the Deflate spec contains an escape mechanism to store uncompressed data with only tiny overhead, but then this implementation is not known for being good in any way.
|
|
|
|
|
Hi Guys this is my first post on the forum (Despite being a long time browser), i hope you can help me.
I am attempting to create and display a modeless form within some C++ code. It works fine when the form is displayed as a modal form using ShowDialog(). However when i use Show(), the form is displayed but with black spaces where the UI controls (Label and Button) should be. You can see that there should be something there but there isn't?
I'm guessing it may be somekind of threading issue? As in the main thread is attempting to create controls on a different thread?
Has anyone come across this issue before and if so how did they get around it?
Thanks
|
|
|
|
|
Hi,
whatever language you use, you shouldn't use multiple threads accessing controls on a single form; this[^] may be useful for you.
|
|
|
|
|