Autor Beitrag
stigge
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 426

WinXP
Delphi 2007
BeitragVerfasst: Mi 01.08.07 13:01 
Ich versuche ein Programm zu schreiben, das eine MP3-Datei ausführt.
Hier mein bisheriger Code:
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace MP3
{
    public class MP3Player
    {
        private string _Alias;

        public MP3Player(string pAlias)
        {
            this._Alias = pAlias;
        }

        public bool Play(string pFileName)
        {
            bool ret = false;
            StringBuilder retApi = new StringBuilder(new string(' '256));
            if (GetShortPathName(pFileName, retApi, retApi.Length) > 0)
            {
                //MCI öffnen
                int intMciResult = mciSendString(string.Format("open {0} type MPEGVideo alias {1}", retApi.ToString(), this._Alias), string.Empty, 0, IntPtr.Zero);

                int intPlayResult = -1;
                if (intMciResult == 0)
                {
                    //MP3 Play
                    intPlayResult = mciSendString(string.Format("play {0} from 0"this._Alias), string.Empty, 0, IntPtr.Zero);
                }

                ret = intPlayResult == 0;
            }
            return ret;
        }

        public bool Stop()
        {
            bool ret = false;
            if (mciSendString(string.Format("stop {0}"this._Alias), string.Empty, 0, IntPtr.Zero) == 0)
            {
                ret = mciSendString(string.Format("close {0}"this._Alias), string.Empty, 0, IntPtr.Zero) == 0;
            }
            return ret;
        }
        [DllImport("winmm.dll")]
        private static extern int mciSendString(string lpCommand, string lpReturn, int nReturnLength, IntPtr callBack);

        [DllImport("kernel32")]
        private static extern int GetShortPathName(string lpLongPath, StringBuilder lpShortPath, int Buffer);
    }
}

namespace DeviceApplication13
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        MP3.MP3Player _M = new MP3.MP3Player("myPlayer");
        private void button1_Click(object sender, System.EventArgs e)
        {
            this._M.Play(@"\Storage Card\test.mp3");
            
        }
    }
}

Jetzt bekomm ich aber eine Fehlermeldung mit der ich nichts anfangen kann:
ausblenden Quelltext
1:
"DeviceApplication14.Form1.Dispose(bool)": Es wurde keine passende Methode zum Überschreiben gefunden.					

Kann mir jemand sagen, was daran falsch ist?
Es kann auch sein das ich hier totalen Müll produziert habe, ich hab erst mit c# angefangen und noch nicht wirklich viel Ahnung...

Der Fehler ist übrigens in folgender Datei:
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
namespace DeviceApplication14
{
    partial class Form1
    {
        /// <summary>
        /// Erforderliche Designervariable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;
        private System.Windows.Forms.MainMenu mainMenu1;

        /// <summary>
        /// Verwendete Ressourcen bereinigen.
        /// </summary>
        /// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Vom Windows Form-Designer generierter Code

        /// <summary>
        /// Erforderliche Methode für die Designerunterstützung.
        /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
        /// </summary>
        private void InitializeComponent()
        {
            this.mainMenu1 = new System.Windows.Forms.MainMenu();
            this.button1 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(2448);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(7220);
            this.button1.TabIndex = 0;
            this.button1.Text = "button1";
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
            this.AutoScroll = true;
            this.ClientSize = new System.Drawing.Size(638455);
            this.Controls.Add(this.button1);
            this.Menu = this.mainMenu1;
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.Button button1;
    }
}

Von Hand hab ich da aber nix geändert...

Moderiert von user profile iconChristian S.: Code- durch C#-Tags ersetzt


Zuletzt bearbeitet von stigge am Mi 01.08.07 13:23, insgesamt 2-mal bearbeitet
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Mi 01.08.07 13:21 
Die Warnung ist doch eigentlich selbsterklärend: Du musst die Form-Klasse vor alle anderen Klassen der Datei verschieben. Am Besten hälst du dich einfach an die Regel "pro Datei nur eine Klasse", übersichtlicher geht es imho nicht mehr.

PS: Noch zwei kleine Hinweis: Für gewöhnlich werden sowohl Felder als auch Parameter ohne Präfix und mit kleinem Anfangsbuchstaben benannt. Ein Namespace macht erst Sinn ab einer Handvoll Member (auf eine genauere Anzahl verzichte ich *g*, FxCop sieht afaik 5 als Minimum an).

PPS: Warum hast du jetzt die Warnung entfernt :gruebel: ? Mit dem angehängten Code ist jetzt jedenfalls die Ursache des anderen Fehlers ersichtlich: In der User-Code-Datei benutzt du den Namespace XYZ13, im autogenerierten Code XYZ14. Einige dich mal, am Besten auf einen sinnvollen Bezeichner :wink: .
stigge Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 426

WinXP
Delphi 2007
BeitragVerfasst: Mi 01.08.07 13:41 
Ich habs nämlich geschafft alle Fehler zu entfernen indem ich einfach den Code in ein neues Projekt kopiert habe.
Allerdings gibt es auf einem PPC/PDA die nötige DLL nicht, deshalb war alles umsonst...
weiß jemand wie man auf einem PPC/PDA Musik wiedergeben kann?