问题描述
大家好.
我使用Visual Studio 2008 Express C#构建项目.基本上我试图使用以下代码在Windows 7 x64上通过directsound捕获音频,但这给了我错误:
BadImageFormatException不是有效的Win32应用程序. (来自HRESULT的异常:0x800700C1)
谁能看到我的代码在我的哪里出了问题,或者我该如何解决这个问题?
我已将其设置为使用x86而不是x64或AnyCpu进行编译,但也尝试过使用这些方法
Hi Everyone.
Im building an project using Visual studio 2008 express c#. Basically im trying to catch audio via directsound on Window 7 x64 using the below code but it is giving me the error:
BadImageFormatException is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)
Can anyone see where ive went wrong with my code or how i could fix this issue?
I''ve set it to compile using x86 rather than x64 or AnyCpu but have tried those aswell
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using Microsoft.DirectX.DirectSound;
namespace USBGlowLightDirectX
{
public partial class Form1 : Form
{
WaveFormat waveFormat = default(WaveFormat);
CaptureBuffer _dwCapBuffer = default(CaptureBuffer);
AutoResetEvent _resetEvent = new AutoResetEvent(false);
Notify _notify = default(Notify);
Int32 _dwOutputBufferSize;
Int32 _dwCaptureBufferSize;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//Setup the Capturing Format
waveFormat.SamplesPerSecond = 96000;
waveFormat.BitsPerSample = 16;
waveFormat.Channels = 2;
waveFormat.FormatTag = WaveFormatTag.Pcm;
waveFormat.BlockAlign = (short)(waveFormat.Channels * (waveFormat.BitsPerSample / 8));
waveFormat.AverageBytesPerSecond = waveFormat.SamplesPerSecond * waveFormat.BlockAlign;
var _dwNotifySize = Math.Max(4096, waveFormat.AverageBytesPerSecond / 8);
_dwNotifySize -= _dwNotifySize % waveFormat.BlockAlign;
_dwCaptureBufferSize = _dwNotifySize;
_dwOutputBufferSize = _dwNotifySize / 2;
//Setup the Capture Buffer
var cap = default(Capture);
var cdc = new CaptureDevicesCollection();
for (int i = 0; i < cdc.Count; i++)
{
if (cdc[i].Description.ToLower().Contains("Stereo Mix".ToLower()))
{
cap = new Capture(cdc[i].DriverGuid);
break;
}
}
var capDesc = new CaptureBufferDescription
{
Format = waveFormat,
BufferBytes = _dwCaptureBufferSize
};
_dwCapBuffer = new CaptureBuffer(capDesc, cap); //This is the Capture Buffer
//setup buffer notifications to allow buffer to reset when full
var bpn1 = new BufferPositionNotify();
bpn1.Offset = _dwCapBuffer.Caps.BufferBytes / 2 - 1;
bpn1.EventNotifyHandle = _resetEvent.SafeWaitHandle.DangerousGetHandle();
var bpn2 = new BufferPositionNotify();
bpn2.Offset = _dwCapBuffer.Caps.BufferBytes - 1;
bpn2.EventNotifyHandle = _resetEvent.SafeWaitHandle.DangerousGetHandle();
_notify.SetNotificationPositions(new BufferPositionNotify[] { bpn1, bpn2 });
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (this.checkBox1.Checked == true)
{
int offset = 0;
Thread _dwCaptureThread = new Thread((ThreadStart)delegate
{
_dwCapBuffer.Start(true);
while (this.checkBox1.Checked == true)
{
_resetEvent.WaitOne();
_dwCapBuffer.Read(offset, typeof(short), LockFlag.None, _dwOutputBufferSize);
offset = (offset + _dwOutputBufferSize) % _dwCaptureBufferSize;
}
_dwCapBuffer.Stop();
});
_dwCaptureThread.Start();
}
}
}
}
哦,使用DirectSound而不是Xaudio的原因是XP系统的向后兼容性.
Oh and the reason for using DirectSound instead of Xaudio is for backward compatability for XP systems.
推荐答案
这篇关于BadImageFormatException 0x800700C1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!