VS C# 2008 SP1mciSendString kann nicht im Verzeichnispfad gespeichert werden
Ich habe eine kleine Anwendung erstellt, die Audio aufzeichnet und wiedergibt. Allerdings muss meine Anwendung die Wave-Datei im Anwendungsdatenverzeichnis auf dem Benutzercomputer speichern.
Der mciSendString verwendet eine C-Stil-Zeichenfolge als Parameter und muss im 8.3-Format vorliegen. Mein Problem ist jedoch, dass ich es nicht speichern kann. Und was seltsam ist, ist manchmal und manchmal nicht. Wie auch immer, die meiste Zeit ist fehlgeschlagen. Wenn ich jedoch direkt auf dem C-Laufwerk speichere funktioniert es erstmal alles. Ich habe 3 verschiedene Methoden benutzt, die ich unten kodiert habe.
Die Fehlernummer, die ich erhalte, wenn es nicht ist 286. „Die Datei gespeichert wurde nicht. Stellen Sie sicher, dass Ihr System ausreichend Speicherplatz hat oder eine intakte Netzwerkverbindung“
Vielen Dank für alle suggestins,
[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;
}
Danke, ich werde das versuchen. – ant2009