1 Replies - 1378 Views - Last Post: 04 September 2015 - 09:06 AM

#1 Atton  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 10-June 15

Thread Issues

Posted 20 July 2015 - 08:20 AM

I've been working on make a program, that provides the user with there ping. Much like how cmd ping works however in the form of a GUI. I have however ran into an issue with a timer that is meant to trigger the function. So how do I fix the issue on this code and am I doing it right?
#include <string>
#include <windows.h>
#include <stdexcept>
#include <sstream>
#include <iomanip>
#include <bitset>
#include <iostream>
#include <limits>
#include <msclr\marshal_cppstd.h>
#pragma once

namespace PingPhuckersGUI {
	using namespace std;
	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 mainGUI
	/// </summary>
	public ref class mainGUI : public System::Windows::Forms::Form
	{
	public:
		mainGUI(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~mainGUI()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  goButton;
	protected: 

	protected: 
	private: System::Windows::Forms::TextBox^  pingAddressBox;
	private: System::Windows::Forms::TextBox^  pingOutbox;
	private: System::Windows::Forms::TextBox^  pingDelayBox;


	private: System::Windows::Forms::Label^  pingL;
	private: System::Windows::Forms::Label^  pingServerDelay;

	private: System::Windows::Forms::PictureBox^  pictureBox1;



	private:
	void setText(int data)
	{
		pingOutbox->Text = Convert::ToString(data);

		cout << data << endl;
	}

	void mainPingThing()
	{
		// This is for the dll ignore it 
		// Note the dll is compiled under vs2012
		HINSTANCE hinstDLL;
		hinstDLL = LoadLibrary("PingPhuckersDLL.dll");
		typedef void(*pingFunction)(string,int&);
		pingFunction ping(0);
		ping = (pingFunction)GetProcAddress(hinstDLL,"pingTheServer");
		// Other code goes here
	
		String ^ Site = pingAddressBox->Text;
		String ^ Delay = pingDelayBox->Text;
		string theSite(msclr::interop::marshal_as<std::string>(Site));
		string theDelay(msclr::interop::marshal_as<std::string>(Delay));
		int intDelay = atoi(theDelay.c_str());
		int speed = 0;
		int unfuckDelay(0);
		ping(theSite,speed);// Main ping function
		
		Sleep(intDelay);
		
		FreeLibrary(hinstDLL);
		
		//mainPingThing();
		setText(speed);
	}
		/// <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(mainGUI::typeid));
			this->goButton = (gcnew System::Windows::Forms::Button());
			this->pingAddressBox = (gcnew System::Windows::Forms::TextBox());
			this->pingOutbox = (gcnew System::Windows::Forms::TextBox());
			this->pingDelayBox = (gcnew System::Windows::Forms::TextBox());
			this->pingL = (gcnew System::Windows::Forms::Label());
			this->pingServerDelay = (gcnew System::Windows::Forms::Label());
			this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox1))->BeginInit();
			this->SuspendLayout();
			// 
			// goButton
			// 
			this->goButton->Location = System::Drawing::Point(3, 110);
			this->goButton->Name = L"goButton";
			this->goButton->Size = System::Drawing::Size(85, 31);
			this->goButton->TabIndex = 0;
			this->goButton->Text = L"Go";
			this->goButton->UseVisualStyleBackColor = true;
			this->goButton->Click += gcnew System::EventHandler(this, &mainGUI::goButton_Click);
			// 
			// pingAddressBox
			// 
			this->pingAddressBox->Location = System::Drawing::Point(94, 110);
			this->pingAddressBox->Multiline = true;
			this->pingAddressBox->Name = L"pingAddressBox";
			this->pingAddressBox->Size = System::Drawing::Size(229, 35);
			this->pingAddressBox->TabIndex = 1;
			this->pingAddressBox->Text = L"google.com";
			this->pingAddressBox->TextChanged += gcnew System::EventHandler(this, &mainGUI::pingAddressBox_TextChanged);
			// 
			// pingOutbox
			// 
			this->pingOutbox->Location = System::Drawing::Point(3, 25);
			this->pingOutbox->MaxLength = 8;
			this->pingOutbox->Name = L"pingOutbox";
			this->pingOutbox->ReadOnly = true;
			this->pingOutbox->Size = System::Drawing::Size(85, 20);
			this->pingOutbox->TabIndex = 2;
			this->pingOutbox->Text = L"0";
			this->pingOutbox->TextChanged += gcnew System::EventHandler(this, &mainGUI::pingOutbox_TextChanged);
			// 
			// pingDelayBox
			// 
			this->pingDelayBox->Location = System::Drawing::Point(3, 77);
			this->pingDelayBox->Name = L"pingDelayBox";
			this->pingDelayBox->Size = System::Drawing::Size(92, 20);
			this->pingDelayBox->TabIndex = 3;
			this->pingDelayBox->Text = L"2";
			this->pingDelayBox->TextChanged += gcnew System::EventHandler(this, &mainGUI::pingDelayBox_TextChanged);
			// 
			// pingL
			// 
			this->pingL->AutoSize = true;
			this->pingL->Location = System::Drawing::Point(0, 9);
			this->pingL->Name = L"pingL";
			this->pingL->Size = System::Drawing::Size(88, 13);
			this->pingL->TabIndex = 4;
			this->pingL->Text = L"Ping Milliseconds";
			// 
			// pingServerDelay
			// 
			this->pingServerDelay->AutoSize = true;
			this->pingServerDelay->Location = System::Drawing::Point(0, 61);
			this->pingServerDelay->Name = L"pingServerDelay";
			this->pingServerDelay->Size = System::Drawing::Size(95, 13);
			this->pingServerDelay->TabIndex = 5;
			this->pingServerDelay->Text = L"Ping Server Delay ";
			// 
			// pictureBox1
			// 
			this->pictureBox1->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"pictureBox1.Image")));
			this->pictureBox1->Location = System::Drawing::Point(112, 12);
			this->pictureBox1->Name = L"pictureBox1";
			this->pictureBox1->Size = System::Drawing::Size(196, 85);
			this->pictureBox1->SizeMode = System::Windows::Forms::PictureBoxSizeMode::CenterImage;
			this->pictureBox1->TabIndex = 6;
			this->pictureBox1->TabStop = false;
			// 
			// mainGUI
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(96, 96);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Dpi;
			this->BackgroundImage = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"$this.BackgroundImage")));
			this->ClientSize = System::Drawing::Size(329, 149);
			this->Controls->Add(this->pictureBox1);
			this->Controls->Add(this->pingServerDelay);
			this->Controls->Add(this->pingL);
			this->Controls->Add(this->pingDelayBox);
			this->Controls->Add(this->pingOutbox);
			this->Controls->Add(this->pingAddressBox);
			this->Controls->Add(this->goButton);
			this->ForeColor = System::Drawing::Color::Black;
			this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedDialog;
			this->Location = System::Drawing::Point(90, 90);
			this->MaximizeBox = false;
			this->MinimizeBox = false;
			this->Name = L"mainGUI";
			this->ShowIcon = false;
			this->ShowInTaskbar = false;
			this->StartPosition = System::Windows::Forms::FormStartPosition::Manual;
			this->Text = L"PingPhuckers";
			this->TopMost = true;
			this->Load += gcnew System::EventHandler(this, &mainGUI::mainGUI_Load);
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox1))->EndInit();
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion

	private: System::Void mainGUI_Load(System::Object^  sender, System::EventArgs^  e) 
	{
		// This is when the gui loads lol
		cout << "GUI OPEN" << std::endl;
	}

	private: System::Void goButton_Click(System::Object^  sender, System::EventArgs^  e)
	{
		Timer ^TimerTime = gcnew Timer();
		//TimerTime->Stop();
		TimerTime->Interval = 1000;
		TimerTime->Start();
		mainPingThing();
		TimerTime->Stop;
	}
	// Holders
	private: System::Void pingAddressBox_TextChanged(System::Object^  sender, System::EventArgs^  e) 
	{
	}
	private: System::Void pingOutbox_TextChanged(System::Object^  sender, System::EventArgs^  e) 
	{
	}
	private: System::Void pingDelayBox_TextChanged(System::Object^  sender, System::EventArgs^  e) 
	{
	}
};
}



Is This A Good Question/Topic? 0
  • +

Replies To: Thread Issues

#2 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,832
  • Joined: 25-October 06

Re: Thread Issues

Posted 04 September 2015 - 09:06 AM

you probably need to make your Timer ^TimerTime a class variable and remove the TimerTime->Stop(); from goButton_Click() method and add an event handler which on timeout stops the timer
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1