0
0

hi all,
i ‘m newbie, i’m coding to play the music file, i used to cf 2.0, pocket pc 2003 on vs 2008. but when i complie, throw an error:
"Can’t find PInvoke DLL ‘path...\fmodce.dll’."
and the following my code:
[code:2og0ycw4]
using System;
using System.Runtime;
using System.Runtime.InteropServices;
namespace SmartDeviceDemo
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
private System.Windows.Forms.MainMenu mainMenu1;

    /// &lt;summary&gt;
    /// Clean up any resources being used.
    /// &lt;/summary&gt;
    /// &lt;param name=&quot;disposing&quot;&gt;true if managed resources should be disposed; otherwise, false.&lt;/param&gt;
    protected override void Dispose(bool disposing)
    {
        if (disposing &amp;&amp; (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows Form Designer generated code

    /// &lt;summary&gt;
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// &lt;/summary&gt;
    private void InitializeComponent()
    {
        this.mainMenu1 = new System.Windows.Forms.MainMenu();
        this.button1 = new System.Windows.Forms.Button();
        this.button2 = new System.Windows.Forms.Button();
        this.SuspendLayout();
        // 
        // button1
        // 
        this.button1.Location = new System.Drawing.Point(26, 70);
        this.button1.Name = &quot;button1&quot;;
        this.button1.Size = new System.Drawing.Size(194, 22);
        this.button1.TabIndex = 0;
        this.button1.Text = &quot;play music 1&quot;;
        this.button1.Click += new System.EventHandler(this.button1_Click);
        // 
        // button2
        // 
        this.button2.Location = new System.Drawing.Point(26, 107);
        this.button2.Name = &quot;button2&quot;;
        this.button2.Size = new System.Drawing.Size(194, 20);
        this.button2.TabIndex = 1;
        this.button2.Text = &quot;play music 2&quot;;
        this.button2.Click += new System.EventHandler(this.button2_Click);
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
        this.AutoScroll = true;
        this.ClientSize = new System.Drawing.Size(240, 268);
        this.Controls.Add(this.button2);
        this.Controls.Add(this.button1);
        this.Menu = this.mainMenu1;
        this.Name = &quot;Form1&quot;;
        this.Text = &quot;Form1&quot;;
        this.ResumeLayout(false);

    }

    #endregion

    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Button button2;

    //Declare
    public static IntPtr GetStream(string filename)
    {
        // Get the filename in bytes
        byte[] filenamebytes = System.Text.Encoding.Default.GetBytes(filename + null);

        // Get a handle depending on which framework we are using
        GCHandle hfile = GCHandle.Alloc(filenamebytes, GCHandleType.Pinned);
        if (Environment.Version.Major == 1) return new IntPtr(hfile.AddrOfPinnedObject().ToInt32() + 4);
        else return hfile.AddrOfPinnedObject();
    }

    #region Using Fmod
    [DllImport(&quot;E:\\WindowCE\\SmartDeviceDemo\\fmodce.dll&quot;, EntryPoint = &quot;FSOUND_Init&quot;, SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)]
    public static extern bool Init(int mixrate, int maxsoftwarechannels, int flags);

    /// &lt;summary&gt;
    /// Get the length of a stream
    /// &lt;/summary&gt;
    [DllImport(&quot;E:\\WindowCE\\SmartDeviceDemo\\fmodce.dll&quot;, EntryPoint = &quot;FSOUND_Stream_GetLength&quot;, SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)]
    public static extern int GetLength(IntPtr fstream);

    /// &lt;summary&gt;
    /// Get the current position of the stream
    /// &lt;/summary&gt;
    [DllImport(&quot;E:\\WindowCE\\SmartDeviceDemo\\fmodce.dll&quot;, EntryPoint = &quot;FSOUND_Stream_GetPosition&quot;, SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)]
    public static extern UInt32 GetPosition(IntPtr fstream);

    /// &lt;summary&gt;
    /// Open a stream
    /// &lt;/summary&gt;
    [DllImport(&quot;E:\\WindowCE\\SmartDeviceDemo\\fmodce.dll&quot;, EntryPoint = &quot;FSOUND_Stream_Open&quot;, SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)]
    public static extern IntPtr Open(IntPtr data, int mode, int offset, int length);

    /// &lt;summary&gt;
    /// Start playing from the stream
    /// &lt;/summary&gt;
    [DllImport(&quot;E:\\WindowCE\\SmartDeviceDemo\\fmodce.dll&quot;, EntryPoint = &quot;FSOUND_Stream_Play&quot;, SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)]
    public static extern int Play(int channel, IntPtr fstream);

    /// &lt;summary&gt;
    /// Set the position of the stream
    /// &lt;/summary&gt;
    [DllImport(&quot;E:\\WindowCE\\SmartDeviceDemo\\fmodce.dll&quot;, EntryPoint = &quot;FSOUND_Stream_SetPosition&quot;, SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)]
    public static extern bool SetPosition(IntPtr fstream, UInt32 position);

    /// &lt;summary&gt;
    /// Stop playing the stream
    /// &lt;/summary&gt;
    [DllImport(&quot;E:\\WindowCE\\SmartDeviceDemo\\fmodce.dll&quot;, EntryPoint = &quot;FSOUND_Stream_Stop&quot;, SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)]
    public static extern bool Stop(IntPtr fstream);

    /// &lt;summary&gt;
    /// Close FMOD and release resources
    /// &lt;/summary&gt;
    //[DllImport(&quot;fmodce.dll&quot;, EntryPoint = &quot;FSOUND_Close&quot;, SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)]
    //public static extern void Close(); 
    #endregion

    //Play the music
    private void PlayStopCloseMP3File()
    {
        // Declare our handles
        IntPtr soundStream;
        IntPtr soundHandle;

        // Initialize fmod with mixrate equal to 44.1kHz
        SmartDeviceDemo.Form1.Init(44100, 16, 0);

        // Initialize the handle with the track file.
        // Note that you must provide the full Pocket PC path. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnppcgen/html/ppc_io.asp for more info...
        soundStream = SmartDeviceDemo.Form1.GetStream(&quot;E:\\English songs\\full_house.mp3&quot;);

        // Open the stream in Normal mode, which is combination of Mono sound, 16 bits, Signed
        soundHandle = SmartDeviceDemo.Form1.Open(soundStream, 0x100, 0, 0);

        // Start playing
        SmartDeviceDemo.Form1.Play(0, soundHandle);

        // -----------------------------
        // Do Something here...
        // -----------------------------

        // Stop playing
        SmartDeviceDemo.Form1.Stop(soundHandle);

        // Release the ressources
        //SmartDeviceDemo.Form1.Close();
    }
}

}
[/code:2og0ycw4]

anyone know, please help now…………..

thanks advance

Best regard

  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.