0

VS C# 2008 SP1

オーディオを録音および再生する小さなアプリケーションを作成しました。ただし、私のアプリケーションでは、wave ファイルをユーザーのコンピューターのアプリケーション データ ディレクトリに保存する必要があります。

mciSendString は C スタイルの文字列をパラメーターとして受け取り、8.3 形式である必要があります。しかし、私の問題は、それを保存できないことです。そして奇妙なのは、そうするときもあれば、そうでないときもあるということです。ただし、ほとんどの場合は失敗します。ただし、Cドライブに直接保存すると、初めてすべてが機能します。以下にコーディングした3つの異なる方法を使用しました。

失敗したときに表示されるエラー番号は 286 です。

ご提案いただきありがとうございます。

[DllImport("winmm.dll",CharSet=CharSet.Auto)]
        private static extern uint mciSendString([MarshalAs(UnmanagedType.LPTStr)] string command,
                                                 StringBuilder returnValue,
                                                 int returnLength,
                                                 IntPtr winHandle);

        [DllImport("winmm.dll", CharSet = CharSet.Auto)]
        private static extern int mciGetErrorString(uint errorCode, StringBuilder errorText, int errorTextSize);

[DllImport("Kernel32.dll", CharSet=CharSet.Auto)]
        private static extern int GetShortPathName([MarshalAs(UnmanagedType.LPTStr)] string longPath,
                                                   [MarshalAs(UnmanagedType.LPTStr)] StringBuilder shortPath,
                                                    int length);






 // Stop recording
        private void StopRecording()
        {
            // Save recorded voice
            string shortPath = this.shortPathName();
            string formatShortPath = string.Format("save recsound \"{0}\"", shortPath);
            uint result = 0;
            StringBuilder errorTest = new StringBuilder(256);

            // C:\DOCUME~1\Steve\APPLIC~1\Test.wav
            // Fails
            result = mciSendString(string.Format("{0}", formatShortPath), null, 0, IntPtr.Zero);
            mciGetErrorString(result, errorTest, errorTest.Length);

            // command line convention - fails 
            result = mciSendString("save recsound \"C:\\DOCUME~1\\Steve\\APPLIC~1\\Test.wav\"", null, 0, IntPtr.Zero);
            mciGetErrorString(result, errorTest, errorTest.Length);         

            // 8.3 short format - fails
            result = mciSendString(@"save recsound C:\DOCUME~1\Steve\APPLIC~1\Test.wav", null, 0, IntPtr.Zero);
            mciGetErrorString(result, errorTest, errorTest.Length);

            // Save to C drive works everytime.
            result = mciSendString(@"save recsound C:\Test.wav", null, 0, IntPtr.Zero);
            mciGetErrorString(result, errorTest, errorTest.Length);

            mciSendString("close recsound ", null, 0, IntPtr.Zero);
        }


// Get the short path name so that the mciSendString can save the recorded wave file
        private string shortPathName()
        {
            string shortPath = string.Empty;
            long length = 0;
            StringBuilder buffer = new StringBuilder(256);

            // Get the length of the path 
            length = GetShortPathName(this.saveRecordingPath, buffer, 256);

            shortPath = buffer.ToString();

            return shortPath;
        }
4

3 に答える 3

3

C driveとでテストしましたがD drive、ディレクトリ パスにスペースが含まれていない限り動作します。両方とも機能しますが、"C:\Test.wav"機能しません。"D:\mp3\test.wav""D:\mp4 folder\test.wav"

于 2012-09-08T13:32:55.957 に答える
1

これを試して:

[ string directoryString = "C:\DOCUME~1\Steve\APPLIC~1\"; Directory.SetCurrentDirectory(ディレクトリ文字列); mciSendString(@"save recsound Test.wav", null, 0, IntPtr.Zero); mciSendString("受信音を閉じる", null, 0, IntPtr.Zero); ]

于 2010-04-18T02:37:22.147 に答える