C# mciSendString无法保存到目录路径
VS C#2008 SP1 我创建了一个记录和播放音频的小应用程序。但是,我的应用程序需要将wave文件保存到用户计算机上的应用程序数据目录中 mciSendString将C样式的字符串作为参数,并且必须采用8.3格式。然而,我的问题是我无法保存它。奇怪的是,它有时做,有时不做。然而,大部分时间都是失败。但是,如果我直接保存到C驱动器,它会在第一时间工作。我使用了下面编码的3种不同方法 失败时我得到的错误号是286。“该文件未保存。请确保您的系统有足够的磁盘空间或具有完整的网络连接” 非常感谢你的建议C# mciSendString无法保存到目录路径,c#,mcisendstring,C#,Mcisendstring,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;
}
试试这个:
[
string directoryString=“C:\DOCUME~1\Steve\APPLIC~1\”;
Directory.SetCurrentDirectory(directoryString);
mciSendString(@“save recsound Test.wav”,null,0,IntPtr.Zero);
mciSendString(“closerecsound”,null,0,IntPtr.Zero);
]试试这个:
[
string directoryString=“C:\DOCUME~1\Steve\APPLIC~1\”;
Directory.SetCurrentDirectory(directoryString);
mciSendString(@“save recsound Test.wav”,null,0,IntPtr.Zero);
mciSendString(“closerecsound”,null,0,IntPtr.Zero);
]我在
C驱动器和D驱动器中测试它,只要目录路径不包含空间,它就可以工作“C:\Test.wav”和“D:\mp3\Test.wav”
都可以工作,但是“D:\mp4 folder\Test.wav”
不工作。我在C drive
和D drive
中测试它,只要目录路径不包含空间就可以工作<代码>“C:\Test.wav”和“D:\mp3\Test.wav”
都可以工作,但是“D:\mp4 folder\Test.wav”
不工作。谢谢,我会试试。谢谢,我会试试的。