Archive for 29 十二月, 2005

Read Full Post »

今天測試了一下 .Net 環境開發 DirectX 程式,寫了一個播放 wav 聲音的簡單程式如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX.DirectSound; 
namespace DirectSoundDemo {
    public partial class Form1 : Form {
        public Form1() {

        private void button1_Click(object sender, EventArgs e) {
            Device dev = new Device();
            dev.SetCooperativeLevel(this, CooperativeLevel.Normal );            
            Microsoft.DirectX.DirectSound.Buffer buf = new Microsoft.DirectX.DirectSound.Buffer(@"c:winntmediatada.wav", dev) ;
            buf.Play(0, BufferPlayFlags.Looping );


結果在 VS2005 Express IDE 環境以 debug 模式執行時丟出下面的訊息:
LoaderLock was detected
Message: DLL ‘C:WINNTassemblyGACMicrosoft.DirectX1.0.2902.0__31bf3856ad364e35Microsoft.DirectX.dll’ is attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.

詳細資訊可以 MSDN 的 LoaderLock 關鍵字文件

Debug | Exceptions | Managed Debugging Assistants | LoaderLock 的 Thrown 勾選取消即可。

在 .Net 環境寫 DirectX 真的比較容易,不同於用 DirectX SDK 繁瑣,只要簡單的幾行指令就可以達成需求。要執行上述範例,記得在專案中加入 Microsoft.DirectX.DirectSound 的 Reference

Read Full Post »