[cpp/cli] open/close szufladki czytnika cd

0

Chciałem zrobić program który otwiera i zamyka cd-rom .
Nawet sie wszystko kompiluje ale nie działa .
<ort>Prosił bym</ort> o jakieś wskazówki co mam poprawić żeby zadziałało .
Korzystam z visual c++

#pragma once
#include <windows.h>
#include <mmsystem.h>
#define mciSendString

namespace sd {

	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
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </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::Button^  button1;
	protected: 
	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->button1 = (gcnew System::Windows::Forms::Button());
			this->button2 = (gcnew System::Windows::Forms::Button());
			this->SuspendLayout();
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(25, 62);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(117, 41);
			this->button1->TabIndex = 0;
			this->button1->Text = L"button1";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// button2
			// 
			this->button2->Location = System::Drawing::Point(30, 148);
			this->button2->Name = L"button2";
			this->button2->Size = System::Drawing::Size(168, 59);
			this->button2->TabIndex = 1;
			this->button2->Text = L"button2";
			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(292, 266);
			this->Controls->Add(this->button2);
			this->Controls->Add(this->button1);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->ResumeLayout(false);

		}

#pragma endregion
		void open(){
		 mciSendString("Set CDAudio Door Open wait", 0, 0, 0); //otwieranie
		}
		void close(){
  mciSendString("Set CDAudio Door Closed wait", 0, 0, 0); //zamykanie
		}
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) { void open();
			 }
	private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) { void close();
			 }
	};
}
0

Nie chcę mi się analizować całego kodu, po prostu podeślę Tobie funkcję, którą dawno temu napisałem. Otwiera i zamyka ona stację tyle razy ile jest podane w parametrze:

void petla_dvd(int ile)
{
	OpenParm.lpstrDeviceType=_T("CDAudio");
	mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE, (DWORD_PTR)&OpenParm);
	dID = OpenParm.wDeviceID;
	for(int i=0; i<ile; ++i)
	{
			mciSendCommand(dID, MCI_SET, MCI_SET_DOOR_OPEN, (DWORD_PTR)&SetParm);
			mciSendCommand(dID, MCI_SET, MCI_SET_DOOR_CLOSED, (DWORD_PTR)&SetParm);
	}
	mciSendCommand(dID, MCI_CLOSE, MCI_NOTIFY, (DWORD_PTR)&SetParm);
}

Tylko tak:

  1. Dołącz bibliotekę mmsystem.h
  2. Ręcznie dołącz bibliotekę winmm.lib: Project->Properities->Configuration Properities->Linker->Command Line. Wpisz ją w polu Additional Options
  3. Zmienne jakie zostały wykorzystane - ja mam jako globalne, dlatego nie są tu widoczne definicje:
MCI_OPEN_PARMS OpenParm;
MCI_SET_PARMS SetParm;
MCIDEVICEID dID;

Powinno zadziałać

Pzdr

0

nie działa sypie errorami poza tym ja chciałbym zrobić to tak funkcja wysuń osobno i funkcja wsuń osobno i potem ją tylko wywoływać

0

a zauwazyles roznice miedzy c++ a c++/cli czy tez ot tak wkleiles ja doslownie?

0

tak wkleiłem dosłownie jak Fuv dał .

0

Jakimi errorami. Chyba chcesz, by ci nie pomóc..

0
#pragma once
#include <windows.h>
#include <mmsystem.h>

Int MCI_OPEN_PARMS OpenParm, MCI_SET_PARMS SetParm, MCIDEVICEID dID;

namespace sd {

        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
        ///
        /// WARNING: If you change the name of this class, you will need to change the
        ///          'Resource File Name' property for the managed resource compiler tool
        ///          associated with all .resx files this class depends on.  Otherwise,
        ///          the designers will not be able to interact properly with localized
        ///          resources associated with this form.
        /// </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::Button^  button1;
        protected:
        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->button1 = (gcnew System::Windows::Forms::Button());
                        this->button2 = (gcnew System::Windows::Forms::Button());
                        this->SuspendLayout();
                        //
                        // button1
                        //
                        this->button1->Location = System::Drawing::Point(25, 62);
                        this->button1->Name = L"button1";
                        this->button1->Size = System::Drawing::Size(117, 41);
                        this->button1->TabIndex = 0;
                        this->button1->Text = L"button1";
                        this->button1->UseVisualStyleBackColor = true;
                        this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
                        //
                        // button2
                        //
                        this->button2->Location = System::Drawing::Point(30, 148);
                        this->button2->Name = L"button2";
                        this->button2->Size = System::Drawing::Size(168, 59);
                        this->button2->TabIndex = 1;
                        this->button2->Text = L"button2";
                        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(292, 266);
                        this->Controls->Add(this->button2);
                        this->Controls->Add(this->button1);
                        this->Name = L"Form1";
                        this->Text = L"Form1";
                        this->ResumeLayout(false);

                }

#pragma endregion
              void petla_dvd(int ile)
{
        OpenParm.lpstrDeviceType=_T("CDAudio");
        mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE, (DWORD_PTR)&OpenParm);
        dID = OpenParm.wDeviceID;
        for(int i=0; i<ile; ++i)
        {
                        mciSendCommand(dID, MCI_SET, MCI_SET_DOOR_OPEN, (DWORD_PTR)&SetParm);
                        mciSendCommand(dID, MCI_SET, MCI_SET_DOOR_CLOSED, (DWORD_PTR)&SetParm);
        }
        mciSendCommand(dID, MCI_CLOSE, MCI_NOTIFY, (DWORD_PTR)&SetParm);
}
			
   




        private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) { petla_dvd();
                         }
        private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {  
                         }
        };
}
------ Rebuild All started: Project: sd, Configuration: Debug Win32 ------
Deleting intermediate and output files for project 'sd', configuration 'Debug|Win32'
Compiling...
stdafx.cpp
Compiling...
sd.cpp
c:\documents and settings\****l\****\*****\*****\******\hua55\sd\sd\Form1.h(5) : error C2146: syntax error : missing ';' before identifier 'MCI_OPEN_PARMS'
c:\documents and settings\****l\****\*****\*****\******\hua55\sd\sd\Form1.h(5) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\****l\****\*****\*****\******\hua55\sd\sd\Form1.h(5) : error C2146: syntax error : missing ';' before identifier 'SetParm'
c:\documents and settings\****l\****\*****\*****\******\hua55\sd\sd\Form1.h(5) : error C2377: 'MCI_SET_PARMS' : redefinition; typedef cannot be overloaded with any other symbol
        C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\mmsystem.h(3294) : see declaration of 'MCI_SET_PARMS'
c:\documents and settings\****l\****\*****\*****\******\hua55\sd\sd\Form1.h(5) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\****l\****\*****\*****\******\hua55\sd\sd\Form1.h(5) : error C2146: syntax error : missing ';' before identifier 'dID'
c:\documents and settings\****l\****\*****\*****\******\hua55\sd\sd\Form1.h(5) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\****l\****\*****\*****\******\hua55\sd\sd\Form1.h(5) : error C2377: 'MCIDEVICEID' : redefinition; typedef cannot be overloaded with any other symbol
        C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\mmsystem.h(2789) : see declaration of 'MCIDEVICEID'
c:\documents and settings\****l\****\*****\*****\******\hua55\sd\sd\Form1.h(5) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\****l\****\*****\*****\******\hua55\sd\sd\Form1.h(104) : error C3861: '_T': identifier not found
c:\documents and settings\****l\****\*****\*****\******\hua55\sd\sd\Form1.h(120) : error C2660: 'sd::Form1::petla_dvd' : function does not take 0 arguments
AssemblyInfo.cpp
Generating Code...
Build log was saved at "file://c:\documents and settings\****l\****\*****\*****\******\hua55\sd\sd\Debug\BuildLog.htm"
sd - 11 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
0

Na dobry poczatek zamien

Int MCI_OPEN_PARMS OpenParm, MCI_SET_PARMS SetParm, MCIDEVICEID dID;

na

MCI_OPEN_PARMS OpenParm;
MCI_SET_PARMS SetParm;
MCIDEVICEID dID;

poza tym twoja funkcja musi przyjac jakas wartosc jako pierwszy argument, jesli dobrze zrozumialem bedzie to wartosc ile razy naped ma sie otworzyc/zamknac.

0

Ok ale mi chodzi żeby były 2 funkcje 1 otwórz 2 zamknij
a nie chce mieć otwórz np 5 razy .
Chciałem żeby to wyglądało tak

void open()--to odpowiada za otwórz

void close() to odpowiada za zamknij

i sobie wywołuje pod danym butonem

1 użytkowników online, w tym zalogowanych: 0, gości: 1