How can i get value from textbox? - c++-cli

I've started C++ 1 week ago and learnt a lot of useful things. Now i'm coding a hack for an online game. i did it like that;
DWORD ENEMY = 0x01516370; //Base address
DWORD ENEMY_OFFSET = 0x4;
void Map1Function(bool fEnable)
{
if(fEnable)
{
WritePointer(ENEMY, ENEMY_OFFSET, textbox1->Text);
}
else
{
WritePointer(ENEMY, ENEMY_OFFSET, textbox1->Text);
}
}
How can i get value from textbox ? Thanks.
My function :
#include <Windows.h>
bool WritePointer(unsigned long ulBase, int iOffset, int iValue)
{
__try { *(int*)(*(unsigned long*)ulBase + iOffset) = iValue; return true; }
__except (EXCEPTION_EXECUTE_HANDLER) { return false; }
}
But it gives that error when i do it like that ^ :
c:\users\*\documents\visual studio 2010\projects\tutorial\tutorial\Hacks.h(63): error C2065: 'textbox1' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\tutorial\tutorial\Hacks.h(63): error C2227: left of '->Text' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\users\*\documents\visual studio 2010\projects\tutorial\tutorial\Hacks.h(67): error C2065: 'textbox1' : undeclared identifier
1>c:\users\*\documents\visual studio 2010\projects\tutorial\tutorial\Hacks.h(67): error C2227: left of '->Text' must point to class/struct/union/generic type
1> type is ''unknown-type''
Full src :
#pragma once
namespace Tutorial {
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::GroupBox^ groupBox1;
private: System::Windows::Forms::CheckBox^ checkBox5;
private: System::Windows::Forms::CheckBox^ checkBox4;
private: System::Windows::Forms::CheckBox^ checkBox3;
private: System::Windows::Forms::RadioButton^ radioButton3;
private: System::Windows::Forms::RadioButton^ radioButton2;
private: System::Windows::Forms::RadioButton^ radioButton1;
private: System::Windows::Forms::CheckBox^ checkBox2;
private: System::Windows::Forms::CheckBox^ checkBox1;
private: System::Windows::Forms::LinkLabel^ linkLabel1;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::CheckBox^ checkBox8;
private: System::Windows::Forms::CheckBox^ checkBox7;
private: System::Windows::Forms::CheckBox^ checkBox6;
private: System::Windows::Forms::TextBox^ textBox1;
protected:
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)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->linkLabel1 = (gcnew System::Windows::Forms::LinkLabel());
this->label1 = (gcnew System::Windows::Forms::Label());
this->checkBox8 = (gcnew System::Windows::Forms::CheckBox());
this->checkBox7 = (gcnew System::Windows::Forms::CheckBox());
this->checkBox6 = (gcnew System::Windows::Forms::CheckBox());
this->checkBox5 = (gcnew System::Windows::Forms::CheckBox());
this->checkBox4 = (gcnew System::Windows::Forms::CheckBox());
this->checkBox3 = (gcnew System::Windows::Forms::CheckBox());
this->radioButton3 = (gcnew System::Windows::Forms::RadioButton());
this->radioButton2 = (gcnew System::Windows::Forms::RadioButton());
this->radioButton1 = (gcnew System::Windows::Forms::RadioButton());
this->checkBox2 = (gcnew System::Windows::Forms::CheckBox());
this->checkBox1 = (gcnew System::Windows::Forms::CheckBox());
this->groupBox1->SuspendLayout();
this->SuspendLayout();
//
// groupBox1
//
this->groupBox1->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"groupBox1.BackgroundImage")));
this->groupBox1->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Zoom;
this->groupBox1->Controls->Add(this->textBox1);
this->groupBox1->Controls->Add(this->linkLabel1);
this->groupBox1->Controls->Add(this->label1);
this->groupBox1->Controls->Add(this->checkBox8);
this->groupBox1->Controls->Add(this->checkBox7);
this->groupBox1->Controls->Add(this->checkBox6);
this->groupBox1->Controls->Add(this->checkBox5);
this->groupBox1->Controls->Add(this->checkBox4);
this->groupBox1->Controls->Add(this->checkBox3);
this->groupBox1->Controls->Add(this->radioButton3);
this->groupBox1->Controls->Add(this->radioButton2);
this->groupBox1->Controls->Add(this->radioButton1);
this->groupBox1->Controls->Add(this->checkBox2);
this->groupBox1->Controls->Add(this->checkBox1);
this->groupBox1->Location = System::Drawing::Point(0, 0);
this->groupBox1->Name = L"groupBox1";
this->groupBox1->Size = System::Drawing::Size(856, 799);
this->groupBox1->TabIndex = 0;
this->groupBox1->TabStop = false;
this->groupBox1->Text = L"Functions";
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(115, 273);
this->textBox1->Multiline = true;
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(54, 18);
this->textBox1->TabIndex = 13;
//
// linkLabel1
//
this->linkLabel1->AutoSize = true;
this->linkLabel1->Location = System::Drawing::Point(9, 309);
this->linkLabel1->Name = L"linkLabel1";
this->linkLabel1->Size = System::Drawing::Size(114, 15);
this->linkLabel1->TabIndex = 12;
this->linkLabel1->TabStop = true;
this->linkLabel1->Text = L"www.elitepvpers.com";
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(9, 294);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(126, 15);
this->label1->TabIndex = 11;
this->label1->Text = L"Credits : SilverEmerald";
//
// checkBox8
//
this->checkBox8->AutoSize = true;
this->checkBox8->Location = System::Drawing::Point(12, 272);
this->checkBox8->Name = L"checkBox8";
this->checkBox8->Size = System::Drawing::Size(103, 19);
this->checkBox8->TabIndex = 10;
this->checkBox8->Text = L"Room Password";
this->checkBox8->UseVisualStyleBackColor = true;
this->checkBox8->CheckedChanged += gcnew System::EventHandler(this, &Form1::checkBox8_CheckedChanged);
//
// checkBox7
//
this->checkBox7->AutoSize = true;
this->checkBox7->Location = System::Drawing::Point(12, 247);
this->checkBox7->Name = L"checkBox7";
this->checkBox7->Size = System::Drawing::Size(83, 19);
this->checkBox7->TabIndex = 9;
this->checkBox7->Text = L"No Gravity";
this->checkBox7->UseVisualStyleBackColor = true;
this->checkBox7->CheckedChanged += gcnew System::EventHandler(this, &Form1::checkBox7_CheckedChanged);
//
// checkBox6
//
this->checkBox6->AutoSize = true;
this->checkBox6->Location = System::Drawing::Point(12, 222);
this->checkBox6->Name = L"checkBox6";
this->checkBox6->Size = System::Drawing::Size(76, 19);
this->checkBox6->TabIndex = 1;
this->checkBox6->Text = L"Cam Hack";
this->checkBox6->UseVisualStyleBackColor = true;
this->checkBox6->CheckedChanged += gcnew System::EventHandler(this, &Form1::checkBox6_CheckedChanged);
//
// checkBox5
//
this->checkBox5->AutoSize = true;
this->checkBox5->Location = System::Drawing::Point(12, 197);
this->checkBox5->Name = L"checkBox5";
this->checkBox5->Size = System::Drawing::Size(85, 19);
this->checkBox5->TabIndex = 8;
this->checkBox5->Text = L"Infinite SP";
this->checkBox5->UseVisualStyleBackColor = true;
this->checkBox5->CheckedChanged += gcnew System::EventHandler(this, &Form1::checkBox5_CheckedChanged);
//
// checkBox4
//
this->checkBox4->AutoSize = true;
this->checkBox4->Location = System::Drawing::Point(12, 172);
this->checkBox4->Name = L"checkBox4";
this->checkBox4->Size = System::Drawing::Size(124, 19);
this->checkBox4->TabIndex = 7;
this->checkBox4->Text = L"HP Refill / Suicide";
this->checkBox4->UseVisualStyleBackColor = true;
this->checkBox4->CheckedChanged += gcnew System::EventHandler(this, &Form1::checkBox4_CheckedChanged);
//
// checkBox3
//
this->checkBox3->AutoSize = true;
this->checkBox3->Location = System::Drawing::Point(12, 147);
this->checkBox3->Name = L"checkBox3";
this->checkBox3->Size = System::Drawing::Size(163, 19);
this->checkBox3->TabIndex = 6;
this->checkBox3->Text = L"[Conquest] Frozen Enemies";
this->checkBox3->UseVisualStyleBackColor = true;
this->checkBox3->CheckedChanged += gcnew System::EventHandler(this, &Form1::checkBox3_CheckedChanged);
//
// radioButton3
//
this->radioButton3->AutoSize = true;
this->radioButton3->Location = System::Drawing::Point(12, 122);
this->radioButton3->Name = L"radioButton3";
this->radioButton3->Size = System::Drawing::Size(81, 19);
this->radioButton3->TabIndex = 5;
this->radioButton3->TabStop = true;
this->radioButton3->Text = L"Deactivate";
this->radioButton3->UseVisualStyleBackColor = true;
this->radioButton3->CheckedChanged += gcnew System::EventHandler(this, &Form1::radioButton3_CheckedChanged);
//
// radioButton2
//
this->radioButton2->AutoSize = true;
this->radioButton2->Location = System::Drawing::Point(12, 97);
this->radioButton2->Name = L"radioButton2";
this->radioButton2->Size = System::Drawing::Size(72, 19);
this->radioButton2->TabIndex = 4;
this->radioButton2->TabStop = true;
this->radioButton2->Text = L"HitRange";
this->radioButton2->UseVisualStyleBackColor = true;
this->radioButton2->CheckedChanged += gcnew System::EventHandler(this, &Form1::radioButton2_CheckedChanged);
//
// radioButton1
//
this->radioButton1->AutoSize = true;
this->radioButton1->Location = System::Drawing::Point(12, 72);
this->radioButton1->Name = L"radioButton1";
this->radioButton1->Size = System::Drawing::Size(79, 19);
this->radioButton1->TabIndex = 3;
this->radioButton1->TabStop = true;
this->radioButton1->Text = L"WallShoot";
this->radioButton1->UseVisualStyleBackColor = true;
this->radioButton1->CheckedChanged += gcnew System::EventHandler(this, &Form1::radioButton1_CheckedChanged);
//
// checkBox2
//
this->checkBox2->AutoSize = true;
this->checkBox2->Location = System::Drawing::Point(12, 47);
this->checkBox2->Name = L"checkBox2";
this->checkBox2->Size = System::Drawing::Size(106, 19);
this->checkBox2->TabIndex = 2;
this->checkBox2->Text = L"Design Changer";
this->checkBox2->UseVisualStyleBackColor = true;
this->checkBox2->CheckedChanged += gcnew System::EventHandler(this, &Form1::checkBox2_CheckedChanged);
//
// checkBox1
//
this->checkBox1->AutoSize = true;
this->checkBox1->Location = System::Drawing::Point(12, 22);
this->checkBox1->Name = L"checkBox1";
this->checkBox1->Size = System::Drawing::Size(69, 19);
this->checkBox1->TabIndex = 1;
this->checkBox1->Text = L"No Blast";
this->checkBox1->UseVisualStyleBackColor = true;
this->checkBox1->CheckedChanged += gcnew System::EventHandler(this, &Form1::checkBox1_CheckedChanged);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(7, 15);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(705, 344);
this->Controls->Add(this->groupBox1);
this->Font = (gcnew System::Drawing::Font(L"Comic Sans MS", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(162)));
this->MaximizeBox = false;
this->Name = L"Form1";
this->Text = L"S4League EU In-Game Hack 23.03.14";
this->groupBox1->ResumeLayout(false);
this->groupBox1->PerformLayout();
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void checkBox1_CheckedChanged(System::Object^ sender, System::EventArgs^ e);
private: System::Void checkBox2_CheckedChanged(System::Object^ sender, System::EventArgs^ e);
private: System::Void radioButton1_CheckedChanged(System::Object^ sender, System::EventArgs^ e);
private: System::Void checkBox8_CheckedChanged(System::Object^ sender, System::EventArgs^ e);
private: System::Void radioButton2_CheckedChanged(System::Object^ sender, System::EventArgs^ e);
private: System::Void radioButton3_CheckedChanged(System::Object^ sender, System::EventArgs^ e);
private: System::Void checkBox3_CheckedChanged(System::Object^ sender, System::EventArgs^ e);
private: System::Void checkBox4_CheckedChanged(System::Object^ sender, System::EventArgs^ e);
private: System::Void checkBox5_CheckedChanged(System::Object^ sender, System::EventArgs^ e);
private: System::Void checkBox6_CheckedChanged(System::Object^ sender, System::EventArgs^ e);
private: System::Void checkBox7_CheckedChanged(System::Object^ sender, System::EventArgs^ e);
};
}

It's textBox1, not textbox1; variables are case sensitive.
Also, this won't work, you need to convert the string from the Text property to an int value. You will need this:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
int value = Convert::ToInt32(textBox1->Text);
WritePointer(ENEMY, ENEMY_OFFSET, value);
}
Notice how the textBox1 is used within the Form1 class. It is necessary because the textBox1 is private to the class.

Related

Connection between two Indy UDP Servers

I'm using RAD Studio 10.2 with two instances of TIdUDPServer from Indy 10.
I run my program on Windows 10 and check the counters of sent and received packages, but there are no packages received. At the same time, I see through Wireshark that they come to the PC, but the second TIdUDPServer does not receive the packages. Why?
Here is my code:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
typedef struct {
char Data[10000];
} struct_Buffer;
int i = 0;
int n = 0;
int k = 0;
int TxSize = 1400;
char TxData;
struct_Buffer TxBuffer;
AnsiString ServerIP1 = "192.168.10.1";
AnsiString ServerIP2 = "192.168.10.2";
TBytes Buffer;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
class TMyQueueProc1 : public TCppInterfacedObject<TThreadProcedure>
{
private:
int m_counter;
TIdBytes m_bytes;
public:
TMyQueueProc1(int ACounter, const TIdBytes &AData) : m_counter(ACounter), m_bytes(AData) {}
INTFOBJECT_IMPL_IUNKNOWN(TInterfacedObject);
void __fastcall Invoke()
{
Form1->Label1->Caption = "Rx " + IntToStr(m_counter);
}
};
void __fastcall TForm1::FormCreate(TObject *Sender)
{
try {
TIdSocketHandle *SocketHandle_Server = Form1->IdUDPServer1->Bindings->Add();
SocketHandle_Server->IP = ServerIP1;
SocketHandle_Server->Port = 4004;
Form1->IdUDPServer1->Active = true;
}
catch(Exception *ex) {
ShowMessage("IdUDPServer1 start error!");
}
try {
TIdSocketHandle *SocketHandle_Echo = Form1->IdUDPServer2->Bindings->Add();
SocketHandle_Echo->IP = ServerIP2;
SocketHandle_Echo->Port = 4004;
Form1->IdUDPServer2->Active = true;
}
catch(Exception *ex) {
ShowMessage("IdUDPServer2 start error!");
}
Timer1->Interval = 100;
Timer1->Enabled = true;
Label3->Caption = "IdUPDServer1: " + ServerIP1;
Label4->Caption = "IdUDPServer2: " + ServerIP2;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
TxData++;
if (TxData == 255) TxData = 0;
for (k = 0; k < TxSize; k++) TxBuffer.Data[k] = TxData;
Buffer = RawToBytes(&TxBuffer.Data[0], TxSize);
Form1->IdUDPServer1->SendBuffer(ServerIP2, 4004, Buffer);
n++;
Label2->Caption = "Tx " + IntToStr(n);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::IdUDPServer2UDPRead(TIdUDPListenerThread *AThread, const TIdBytes AData,
TIdSocketHandle *ABinding)
{
i++;
TThread::Queue(NULL, _di_TThreadProcedure(new TMyQueueProc1(i, AData)));
}
//---------------------------------------------------------------------------

Visual Studio C++ ERR : Functions already have bodies

Just a warning, I'm new and inexperienced in C++ so if I have really bad syntax or I'm missing something obvious, please excuse me. I'm trying to make a program that allows me to open other programs (like game launchers) from inside of it.
I don't want to define the programs in the code so I can change it without recompiling. I'm using a Visual Studio generated Windows Form header file that I've made a few tweaks to and a main cpp file. When I go to compile, I get an ERR_MESSAGE saying that my functions already have bodies. Here's my code:
CPP Script MyForm.cpp:
#include "MyForm.h"
#include <iostream> // Debug (Remove once done)
#include <fstream> // File stream
#include <stdlib.h> // Execute files
using namespace std;
using namespace System;
using namespace System::Windows::Forms;
// Creating the virtual file arrays
char line1[];
char line2[];
char line3[];
char line4[];
char line5[];
char line6[];
char line7[];
char line8[];
char line9[];
char line10[];
char line11[];
char line12[];
namespace Loader {
void loadProgram(int num) {
char new_line[] = { '\n' };
if (num == 1) {
if (line2 != new_line) {
system(line2);
}
}
else if (num == 2) {
if (line4 != new_line) {
system(line4);
}
}
else if (num == 3) {
if (line6 != new_line) {
system(line6);
}
}
else if (num == 4) {
if (line8 != new_line) {
system(line8);
}
}
else if (num == 5) {
if (line10 != new_line) {
system(line10);
}
}
else if (num == 6) {
if (line12 != new_line) {
system(line12);
}
}
}
}
[STAThreadAttribute]
int main() {
// Assigning variables made in pre-processing
const int lineLength = 255;
if (!lineLength) {
const int lineLength = 255;
}
unsigned int lineLengthUnsigned = lineLength;
char line1[lineLength];
char line2[lineLength];
char line3[lineLength];
char line4[lineLength];
char line5[lineLength];
char line6[lineLength];
char line7[lineLength];
char line8[lineLength];
char line9[lineLength];
char line10[lineLength];
char line11[lineLength];
char line12[lineLength];
ifstream file("Programs.txt"); // Load programs list file (READ ONLY)
// Odd lines are program names, even lines are program shortcuts
file.getline(line1, lineLength);
file.getline(line2, lineLength);
file.getline(line3, lineLength);
file.getline(line4, lineLength);
file.getline(line5, lineLength);
file.getline(line6, lineLength);
file.getline(line7, lineLength);
file.getline(line8, lineLength);
file.getline(line9, lineLength);
file.getline(line10, lineLength);
file.getline(line11, lineLength);
file.getline(line12, lineLength);
// Below will run the window
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
FileOpener::MyForm form;
Application::Run(%form);
}
Header File MyForm.h:
#pragma once
#include "MyForm.cpp"
using namespace System;
using namespace System::Windows::Forms;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Data;
using namespace System::Drawing;
namespace FileOpener {
/// <summary>
/// Summary for MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~MyForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::Button^ button3;
private: System::Windows::Forms::Button^ button4;
private: System::Windows::Forms::Button^ button5;
private: System::Windows::Forms::Button^ button6;
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)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(MyForm::typeid));
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->button3 = (gcnew System::Windows::Forms::Button());
this->button4 = (gcnew System::Windows::Forms::Button());
this->button5 = (gcnew System::Windows::Forms::Button());
this->button6 = (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(64, 64);
this->button1->TabIndex = 0;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(82, 12);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(64, 64);
this->button2->TabIndex = 1;
this->button2->Text = L"button2";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &MyForm::button2_Click);
//
// button3
//
this->button3->Location = System::Drawing::Point(152, 12);
this->button3->Name = L"button3";
this->button3->Size = System::Drawing::Size(64, 64);
this->button3->TabIndex = 2;
this->button3->Text = L"button3";
this->button3->UseVisualStyleBackColor = true;
this->button3->Click += gcnew System::EventHandler(this, &MyForm::button3_Click);
//
// button4
//
this->button4->Location = System::Drawing::Point(12, 82);
this->button4->Name = L"button4";
this->button4->Size = System::Drawing::Size(64, 64);
this->button4->TabIndex = 3;
this->button4->Text = L"button4";
this->button4->UseVisualStyleBackColor = true;
this->button4->Click += gcnew System::EventHandler(this, &MyForm::button4_Click);
//
// button5
//
this->button5->Location = System::Drawing::Point(82, 82);
this->button5->Name = L"button5";
this->button5->Size = System::Drawing::Size(64, 64);
this->button5->TabIndex = 4;
this->button5->Text = L"button5";
this->button5->UseVisualStyleBackColor = true;
this->button5->Click += gcnew System::EventHandler(this, &MyForm::button5_Click);
//
// button6
//
this->button6->Location = System::Drawing::Point(152, 82);
this->button6->Name = L"button6";
this->button6->Size = System::Drawing::Size(64, 64);
this->button6->TabIndex = 5;
this->button6->Text = L"button6";
this->button6->UseVisualStyleBackColor = true;
this->button6->Click += gcnew System::EventHandler(this, &MyForm::button6_Click);
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->BackColor = System::Drawing::Color::Black;
this->BackgroundImage = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"$this.BackgroundImage")));
this->ClientSize = System::Drawing::Size(228, 157);
this->Controls->Add(this->button6);
this->Controls->Add(this->button5);
this->Controls->Add(this->button4);
this->Controls->Add(this->button3);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
this->Icon = (cli::safe_cast<System::Drawing::Icon^>(resources->GetObject(L"$this.Icon")));
this->Name = L"MyForm";
this->Text = L"File Opener";
this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
this->ResumeLayout(false);
}
private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) {
}
public: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Loader::loadProgram(1);
}
public: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
Loader::loadProgram(2);
}
public: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
Loader::loadProgram(3);
}
public: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
Loader::loadProgram(4);
}
public: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) {
Loader::loadProgram(5);
}
public: System::Void button6_Click(System::Object^ sender, System::EventArgs^ e) {
Loader::loadProgram(6);
}
};
}
#pragma endregion
Again, sorry for any facepalm-worthy parts in my code or this post, as this is my first post. Any pointers/tips would be appreciated!
I was able to fix the functions already have bodies error by using PeterT's suggestion.

makePtr doesn't work?

So I'm new to c++ and opencv, and now I'm trying the stitching sample from opencv using windows form application on visual studio 2013. Here is my code:
#include <opencv2/opencv.hpp>
#include <opencv2/opencv_modules.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/core/utility.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/features2d.hpp>
#include <opencv2/stitching/detail/blenders.hpp>
#include <opencv2/stitching/detail/camera.hpp>
#include <opencv2/stitching/detail/exposure_compensate.hpp>
#include <opencv2/stitching/detail/matchers.hpp>
#include <opencv2/stitching/detail/motion_estimators.hpp>
#include <opencv2/stitching/detail/seam_finders.hpp>
#include <opencv2/stitching/detail/util.hpp>
#include <opencv2/stitching/detail/warpers.hpp>
#include <opencv2/stitching/warpers.hpp>
#include <iostream>
#include <string>
#include <vector>
#pragma once
namespace Stitch {
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 System::IO;
/// <summary>
/// Summary for MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public :
std::vector<cv::Mat> *gbr_arr;
array<System::String^>^ dir_arr;
cv::Mat *hasil_gbr;
int jml_gbr;
MyForm(void)
{
InitializeComponent();
gbr_arr = new std::vector<cv::Mat>;
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~MyForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::MenuStrip^ menuStrip1;
protected:
private: System::Windows::Forms::ToolStripMenuItem^ fileToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ loadImageToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ saveImageToolStripMenuItem;
private: System::Windows::Forms::ToolStripSeparator^ toolStripSeparator1;
private: System::Windows::Forms::ToolStripMenuItem^ closeToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ aboutToolStripMenuItem;
private: System::Windows::Forms::OpenFileDialog^ openFileDialog1;
private: System::Windows::Forms::SaveFileDialog^ saveFileDialog1;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::ProgressBar^ progressBar1;
private: System::Windows::Forms::Panel^ panel1;
private: System::ComponentModel::BackgroundWorker^ backgroundWorker1;
private: System::Windows::Forms::Label^ label1;
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->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
this->fileToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->loadImageToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->saveImageToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->toolStripSeparator1 = (gcnew System::Windows::Forms::ToolStripSeparator());
this->closeToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->aboutToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
this->saveFileDialog1 = (gcnew System::Windows::Forms::SaveFileDialog());
this->button1 = (gcnew System::Windows::Forms::Button());
this->progressBar1 = (gcnew System::Windows::Forms::ProgressBar());
this->panel1 = (gcnew System::Windows::Forms::Panel());
this->backgroundWorker1 = (gcnew System::ComponentModel::BackgroundWorker());
this->label1 = (gcnew System::Windows::Forms::Label());
this->menuStrip1->SuspendLayout();
this->SuspendLayout();
//
// menuStrip1
//
this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {
this->fileToolStripMenuItem,
this->aboutToolStripMenuItem
});
this->menuStrip1->Location = System::Drawing::Point(0, 0);
this->menuStrip1->Name = L"menuStrip1";
this->menuStrip1->Size = System::Drawing::Size(829, 24);
this->menuStrip1->TabIndex = 0;
this->menuStrip1->Text = L"menuStrip1";
//
// fileToolStripMenuItem
//
this->fileToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(4) {
this->loadImageToolStripMenuItem,
this->saveImageToolStripMenuItem, this->toolStripSeparator1, this->closeToolStripMenuItem
});
this->fileToolStripMenuItem->Name = L"fileToolStripMenuItem";
this->fileToolStripMenuItem->Size = System::Drawing::Size(37, 20);
this->fileToolStripMenuItem->Text = L"File";
//
// loadImageToolStripMenuItem
//
this->loadImageToolStripMenuItem->Name = L"loadImageToolStripMenuItem";
this->loadImageToolStripMenuItem->Size = System::Drawing::Size(136, 22);
this->loadImageToolStripMenuItem->Text = L"Load Image";
this->loadImageToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm::loadImageToolStripMenuItem_Click);
//
// saveImageToolStripMenuItem
//
this->saveImageToolStripMenuItem->Name = L"saveImageToolStripMenuItem";
this->saveImageToolStripMenuItem->Size = System::Drawing::Size(136, 22);
this->saveImageToolStripMenuItem->Text = L"Save Image";
this->saveImageToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm::saveImageToolStripMenuItem_Click);
//
// toolStripSeparator1
//
this->toolStripSeparator1->Name = L"toolStripSeparator1";
this->toolStripSeparator1->Size = System::Drawing::Size(133, 6);
//
// closeToolStripMenuItem
//
this->closeToolStripMenuItem->Name = L"closeToolStripMenuItem";
this->closeToolStripMenuItem->Size = System::Drawing::Size(136, 22);
this->closeToolStripMenuItem->Text = L"Close";
this->closeToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm::closeToolStripMenuItem_Click);
//
// aboutToolStripMenuItem
//
this->aboutToolStripMenuItem->Name = L"aboutToolStripMenuItem";
this->aboutToolStripMenuItem->Size = System::Drawing::Size(52, 20);
this->aboutToolStripMenuItem->Text = L"About";
//
// openFileDialog1
//
this->openFileDialog1->Filter = L"JPEG Files (*.jpg)|*.jpg|PNG Files (*.png)|*.png|All Files (*.*)|*.*";
this->openFileDialog1->FilterIndex = 3;
this->openFileDialog1->InitialDirectory = L"E:\\\\Gambar";
this->openFileDialog1->Multiselect = true;
this->openFileDialog1->RestoreDirectory = true;
//
// button1
//
this->button1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Bottom | System::Windows::Forms::AnchorStyles::Right));
this->button1->Location = System::Drawing::Point(717, 293);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(100, 23);
this->button1->TabIndex = 1;
this->button1->Text = L"Process";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
//
// progressBar1
//
this->progressBar1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>(((System::Windows::Forms::AnchorStyles::Bottom | System::Windows::Forms::AnchorStyles::Left)
| System::Windows::Forms::AnchorStyles::Right));
this->progressBar1->Location = System::Drawing::Point(0, 322);
this->progressBar1->Name = L"progressBar1";
this->progressBar1->Size = System::Drawing::Size(829, 23);
this->progressBar1->TabIndex = 2;
//
// panel1
//
this->panel1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom)
| System::Windows::Forms::AnchorStyles::Left)
| System::Windows::Forms::AnchorStyles::Right));
this->panel1->AutoSizeMode = System::Windows::Forms::AutoSizeMode::GrowAndShrink;
this->panel1->BackColor = System::Drawing::SystemColors::ControlLightLight;
this->panel1->Location = System::Drawing::Point(0, 27);
this->panel1->Name = L"panel1";
this->panel1->Size = System::Drawing::Size(829, 260);
this->panel1->TabIndex = 3;
//
// backgroundWorker1
//
this->backgroundWorker1->DoWork += gcnew System::ComponentModel::DoWorkEventHandler(this, &MyForm::backgroundWorker1_DoWork);
//
// label1
//
this->label1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Bottom | System::Windows::Forms::AnchorStyles::Left));
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(12, 298);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(0, 13);
this->label1->TabIndex = 4;
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(829, 345);
this->Controls->Add(this->label1);
this->Controls->Add(this->panel1);
this->Controls->Add(this->progressBar1);
this->Controls->Add(this->button1);
this->Controls->Add(this->menuStrip1);
this->MainMenuStrip = this->menuStrip1;
this->Name = L"MyForm";
this->Text = L"Stitcher";
this->WindowState = System::Windows::Forms::FormWindowState::Maximized;
this->menuStrip1->ResumeLayout(false);
this->menuStrip1->PerformLayout();
this->ResumeLayout(false);
this->PerformLayout();
}
void MarshalString(System::String ^ s, cv::String& os) {
using namespace Runtime::InteropServices;
const char* chars =
(const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer();
os = chars;
Marshal::FreeHGlobal(IntPtr((void*)chars));
}
#pragma endregion
private: System::Void loadImageToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
using namespace Runtime::InteropServices;
panel1->AutoScroll = true;
panel1->Controls->Clear();
int x = 20;
int y = 20;
int maxHeight = -1;
if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
dir_arr = openFileDialog1->FileNames;
gbr_arr->clear();
for each (System::String^ gbr in dir_arr)
{
cv::String nama_gbr;
MarshalString(gbr, nama_gbr);
cv::Mat gambar = imread(nama_gbr);
gbr_arr->push_back(gambar);
PictureBox^ pic = gcnew PictureBox;
pic->Width = 0.3*(gambar.cols); pic->Height = 0.3*(gambar.rows);
pic->SizeMode = PictureBoxSizeMode::StretchImage;
pic->Image = System::Drawing::Image::FromFile(gbr);
pic->Location = System::Drawing::Point(x, y);
x += pic->Width + 10;
maxHeight = Math::Max(pic->Height, maxHeight);
if (x > this->panel1->Width)
{
x = 20;
y += pic->Height + 10;
}
this->panel1->Controls->Add(pic);
}
jml_gbr = static_cast<int> (gbr_arr->size());
}
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
label1->Controls->Clear();
label1->Text = "Stitching...";
panel1->Controls->Clear();
backgroundWorker1->RunWorkerAsync(1);
}
private: System::Void saveImageToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
if (saveFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
}
}
private: System::Void closeToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
Application::Exit();
}
private: System::Void backgroundWorker1_DoWork(System::Object^ sender, System::ComponentModel::DoWorkEventArgs^ e) {
cv::Ptr<cv::detail::FeaturesFinder> finder;
finder = cv::makePtr<cv::detail::SurfFeaturesFinder>();
std::vector<cv::detail::ImageFeatures> feature(jml_gbr);
std::vector<cv::detail::MatchesInfo> pairwise_matching;
for (int i = 0; i < jml_gbr; i++)
{
cv::Mat key;
(*finder) (gbr_arr[i], feature[i]);
feature[i].img_idx = i;
cv::drawKeypoints(gbr_arr[i], feature[i].keypoints, key, cv::Scalar::all(-1), 4);
cv::namedWindow("KeyPoints", CV_WINDOW_KEEPRATIO);
cv::imshow("KeyPoints", gbr_arr[i]);
cv::waitKey(0);
MessageBox::Show("Hello!");
}
finder->collectGarbage();
cv::detail::BestOf2NearestMatcher matcher(false, 0.65);
matcher(feature, pairwise_matching);
matcher.collectGarbage();
}
};
}
There was an error when I was trying this code for the first time, but it got fixed by itself (I don't know why and how). If I remember correctly, it was a System.Runtime.InteropServices.SEHException at this line:
finder = cv::makePtr<cv::detail::SurfFeaturesFinder>();
After the error gone, I've tried to run this program and it works just fine, but the program seems to stuck at that "makePtr" line. Is there something wrong in my code?

Add smooth animation when window grow

The idea I have is to give animation to a window/form when it grows. For example, the calculator of Windows 7 when it displays the unit converter or new features, the window changes size with smooth animation.
The problem is that I do not know which code to use when using a button to change the size (eg 200 pixels more).
I'm a beginner, so I do not know how to use "Timer" which was suggested to me.
On this page, can be found whole concept (in C#). You can even download the code already done (again, in C#):
http://www.vcskicks.com/size-transform.php
This is a simple implementation in C++/CLI. I used C++/CLI so I can play with the syntax. You can easily convert it to C#.
AnimateWindowResize.h
#pragma once
using namespace System;
using namespace System::IO; // Stream
using namespace System::Drawing; // Bitmap
using namespace System::Reflection; // Assembly
using namespace System::Collections::Generic;
using namespace System::Text;
using namespace System::Windows::Forms;
public ref class AnimateWindowResize
{
private:
static const int DEFAULT_STEP_AMOUNT = 15;
bool m_startExpanding;
bool m_animationEnabled;
bool m_isHorizontal;
Form^ m_windowsForm;
Button^ m_initiateButton;
int m_minSize;
int m_maxSize;
Timer^ m_timer;
int m_stepRate;
String^ m_initButtonText;
String^ m_finalButtonText;
String^ m_initButtonEmbeddedImageName;
String^ m_finalButtonEmbeddedImageName;
Bitmap^ m_initBitmap;
Bitmap^ m_finalBitmap;
public:
AnimateWindowResize(Form^ windowsForm, Button^ initiateButton, bool isHorizontal, int minSize, int maxSize, bool isWindowExpanded);
// init[final]EmbeddedImageName are images added under Linker -> Input -> Embed Managed Resource File.
AnimateWindowResize(Form^ windowsForm, Button^ initiateButton, String^ initEmbeddedImageName, String^ finalEmbeddedImageName, String^ initButtonText, String^ finalButtonText, bool isHorizontal, int minSize, int maxSize, bool isWindowExpanded);
protected:
void Init(Form^ windowsForm, Button^ initiateButton, String^ initEmbeddedImageName, String^ finalEmbeddedImageName, String^ initButtonText, String^ finalButtonText, bool isHorizontal, int minSize, int maxSize, bool isWindowExpanded)
{
m_initBitmap = nullptr;
m_finalBitmap = nullptr;
m_windowsForm = windowsForm;
m_initiateButton = initiateButton;
if (initButtonText != nullptr)
m_initiateButton->Text = initButtonText;
Stream^ stm = nullptr;
if(initEmbeddedImageName != nullptr)
stm = Assembly::GetEntryAssembly()->GetManifestResourceStream (initEmbeddedImageName);
if (stm != nullptr)
{
m_initBitmap = gcnew Bitmap(stm);
m_initiateButton->Image = m_initBitmap;
}
stm = nullptr;
if(finalEmbeddedImageName != nullptr)
stm = Assembly::GetEntryAssembly()->GetManifestResourceStream (finalEmbeddedImageName);
if (stm != nullptr)
m_finalBitmap = gcnew Bitmap(stm);
m_minSize = minSize;
m_maxSize = maxSize;
m_startExpanding = isWindowExpanded;
m_isHorizontal = isHorizontal;
m_initButtonText = initButtonText;
m_finalButtonText = finalButtonText;
m_initButtonEmbeddedImageName = initEmbeddedImageName;
m_finalButtonEmbeddedImageName = finalEmbeddedImageName;
m_animationEnabled = true;
m_stepRate = DEFAULT_STEP_AMOUNT;
// Calculate the step rate
m_stepRate = (int)((maxSize - minSize) / 10.0);
if (m_stepRate <= 0)
m_stepRate = DEFAULT_STEP_AMOUNT;
m_timer = gcnew Timer();
m_timer->Interval = 1;
m_timer->Enabled = false;
m_timer->Tick += gcnew EventHandler(this, &AnimateWindowResize::m_timer_Tick);
}
void m_timer_Tick(Object^ sender, EventArgs^ e)
{
if (m_startExpanding)
{
if (m_isHorizontal)
{
if (m_windowsForm->Width >= m_maxSize)
{
m_timer->Enabled = false;
}
else
{
int tempWidth = m_windowsForm->Width + m_stepRate;
if (tempWidth >= m_maxSize)
{
m_windowsForm->Width = m_maxSize;
m_timer->Enabled = false;
return;
}
m_windowsForm->Width += m_stepRate;
}
}
else // Vertical
{
if (m_windowsForm->Height >= m_maxSize)
{
m_timer->Enabled = false;
}
else
{
int tempHeight = m_windowsForm->Height + m_stepRate;
if (tempHeight >= m_maxSize)
{
m_windowsForm->Height = m_maxSize;
m_timer->Enabled = false;
return;
}
m_windowsForm->Height += m_stepRate;
}
}
}
else // Collaspe
{
if (m_isHorizontal)
{
if (m_windowsForm->Width <= m_minSize)
{
m_timer->Enabled = false;
}
else
{
int tempWidth = m_windowsForm->Width - m_stepRate;
if (tempWidth <= m_minSize)
{
m_windowsForm->Width = m_minSize;
m_timer->Enabled = false;
return;
}
m_windowsForm->Width -= m_stepRate;
}
}
else // Vertical
{
if (m_windowsForm->Height <= m_minSize)
{
m_timer->Enabled = false;
}
else
{
int tempHeight = m_windowsForm->Height - m_stepRate;
if (tempHeight <= m_minSize)
{
m_windowsForm->Height = m_minSize;
m_timer->Enabled = false;
return;
}
m_windowsForm->Height -= m_stepRate;
}
}
}
}
public:
void StartAnimation()
{
m_timer->Enabled = m_animationEnabled;
m_startExpanding = !m_startExpanding;
// Change the text of the initiate button.
if (m_startExpanding)
{
m_initiateButton->Text = m_finalButtonText == nullptr ? "Less" : m_finalButtonText;
if (m_finalBitmap != nullptr)
m_initiateButton->Image = m_finalBitmap;
}
else
{
m_initiateButton->Text = m_initButtonText == nullptr ? "More" : m_initButtonText;
if (m_initBitmap != nullptr)
m_initiateButton->Image = m_initBitmap;
}
if (!m_animationEnabled)
ResizeWithNoAnimation();
}
public:
property bool AnimationEnabled
{
bool get() { return m_animationEnabled; }
void set(bool value)
{
m_animationEnabled = value;
}
}
private:
void ResizeWithNoAnimation()
{
// Just resize the window.
if (m_startExpanding)
{
if (m_isHorizontal)
m_windowsForm->Width = m_maxSize;
else
m_windowsForm->Height = m_maxSize;
}
else
{
if (m_isHorizontal)
m_windowsForm->Width = m_minSize;
else
m_windowsForm->Height = m_minSize;
}
}
};
AnimateWindowResize.cpp
#include "AnimateWindowResize.h"
AnimateWindowResize::AnimateWindowResize(Form^ windowsForm, Button^ initiateButton, bool isHorizontal, int minSize, int maxSize, bool isWindowExpanded)
{
Init(windowsForm, initiateButton, nullptr, nullptr, nullptr, nullptr, isHorizontal, minSize, maxSize, isWindowExpanded);
}
// init[final]EmbeddedImageName are images added under Linker -> Input -> Embed Managed Resource File.
AnimateWindowResize::AnimateWindowResize(Form^ windowsForm, Button^ initiateButton, String^ initEmbeddedImageName, String^ finalEmbeddedImageName, String^ initButtonText, String^ finalButtonText, bool isHorizontal, int minSize, int maxSize, bool isWindowExpanded)
{
Init(windowsForm, initiateButton, initEmbeddedImageName, finalEmbeddedImageName, initButtonText, finalButtonText, isHorizontal, minSize, maxSize, isWindowExpanded);
}

Fmod include errors

I am making a C++ program to play some mp3 files and am running into trouble. I am getting identifier not found errors. Can anyone give me some advice besides including the header?
Here is my code:
#include "fmod.h"
#include "windows.h"
#include <string>
#include <iostream>
#include <msclr\marshal_cppstd.h>
#include <conio.h>
#pragma comment (lib, "fmodex64_vc.lib")
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 std;
/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
FSOUND_SAMPLE* handle;
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::TextBox^ textBox1;
protected:
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::ListBox^ list;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Button^ button2;
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->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->label1 = (gcnew System::Windows::Forms::Label());
this->list = (gcnew System::Windows::Forms::ListBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(97, 23);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(518, 20);
this->textBox1->TabIndex = 0;
this->textBox1->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_TextChanged);
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(12, 26);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(79, 13);
this->label1->TabIndex = 1;
this->label1->Text = L"Libray Location";
//
// list
//
this->list->FormattingEnabled = true;
this->list->Location = System::Drawing::Point(15, 80);
this->list->Name = L"list";
this->list->Size = System::Drawing::Size(757, 472);
this->list->TabIndex = 2;
//
// button1
//
this->button1->Location = System::Drawing::Point(697, 571);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 3;
this->button1->Text = L"Play";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(616, 571);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(75, 23);
this->button2->TabIndex = 4;
this->button2->Text = L"Refresh";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(784, 606);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Controls->Add(this->list);
this->Controls->Add(this->label1);
this->Controls->Add(this->textBox1);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
this->PerformLayout();
}
private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
msclr::interop::marshal_context context;
std::string standardString = context.marshal_as<std::string>(textBox1->Text);
GetAllFiles(standardString);
//list->Items->Add();
}
void GetAllFiles(string sPath){
WIN32_FIND_DATA FindFileData;
string sTmpPath = sPath;
sTmpPath += "\\*.*";
HANDLE hFind = FindFirstFile( sTmpPath.c_str(), &FindFileData );
if ( hFind == INVALID_HANDLE_VALUE )
return;
else {
do {
if ( ( FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) ) {
// if directory:
if ( strcmp(".", FindFileData.cFileName ) && strcmp("..", FindFileData.cFileName) ) {
sTmpPath = sPath;
sTmpPath += "\\";
sTmpPath += FindFileData.cFileName;
GetAllFiles( sTmpPath.c_str() );
}
}
else // if file:
{
sTmpPath = sPath;
sTmpPath += "\\";
sTmpPath += FindFileData.cFileName;
string fileType = sTmpPath.substr(sTmpPath.length()-3, sTmpPath.length());
if(fileType == "mp3"){
String^ myTempPath = gcnew String(sTmpPath.c_str());
list->Items->Add(myTempPath);//cout << sTmpPath << endl;
}
}
} while ( FindNextFile( hFind, &FindFileData) != 0 );
FindClose( hFind );
}
return;
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
// init FMOD sound system
FSOUND_Init (44100, 32, 0);
// load and play mp3
handle=FSOUND_Sample_Load (0,"E:\\Steve\\Music\\2 Pac\\Unknown Album\\Temptations.mp3",0, 0, 0);
FSOUND_PlaySound (0,handle);
FSOUND_Sample_Free (handle);
FSOUND_Close();
}
};
Here are my errors:
1>c:\users\steve\documents\visual studio 2010\projects\testforms\testforms\Form1.h(26): error C2143: syntax error : missing ';' before '*'
1>c:\users\steve\documents\visual studio 2010\projects\testforms\testforms\Form1.h(26): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\steve\documents\visual studio 2010\projects\testforms\testforms\Form1.h(26): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\steve\documents\visual studio 2010\projects\testforms\testforms\Form1.h(187): error C3861: 'FSOUND_Init': identifier not found
1>c:\users\steve\documents\visual studio 2010\projects\testforms\testforms\Form1.h (190): error C2065: 'handle' : undeclared identifier
1>c:\users\steve\documents\visual studio 2010\projects\testforms\testforms\Form1.h(190): error C3861: 'FSOUND_Sample_Load': identifier not found
1>c:\users\steve\documents\visual studio 2010\projects\testforms\testforms\Form1.h(191): error C2065: 'handle' : undeclared identifier
1>c:\users\steve\documents\visual studio 2010\projects\testforms\testforms\Form1.h (191): error C3861: 'FSOUND_PlaySound': identifier not found
1>c:\users\steve\documents\visual studio 2010\projects\testforms\testforms\Form1.h(192): error C2065: 'handle' : undeclared identifier
1>c:\users\steve\documents\visual studio 2010\projects\testforms\testforms\Form1.h(192): error C3861: 'FSOUND_Sample_Free': identifier not found
1>c:\users\steve\documents\visual studio 2010\projects\testforms\testforms\Form1.h(193): error C3861: 'FSOUND_Close': identifier not found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Mmmh just double check if you have the semicolon at the end of your header file, and if you have defined it "#ifndef" ... it's easy to forget