本帖最后由 hvac_011 于 2012-08-30 08:01:42 编辑

解决方案 »

  1.   

    在你电脑上搜搜看有没有,如果没有,就去网上下一个,dllimport时,指明路径
      

  2.   

    这个问题已经折磨我2天了!我各种方法都尝试了,dll已经拷贝到win32文件夹下面了,但是系统原来就有,我在工程的引用路径中也添加了,相关路径 可是就是不行!我在论坛中看到了其他的关于多媒体定时器的应用,我也拷贝了一份在我机器上运行,都是在运行中出现同样的问题!using System;
    using System.Diagnostics;
    using System.Runtime.InteropServices;
    using System.Threading;namespace O_S_updata
    {
    public class MMTimer : IDisposable
    {
    //Lib API declarations
    [DllImport("Winmm.dll", CharSet = CharSet.Auto)]
    static extern uint timeSetEvent(uint uDelay, uint uResolution, TimerCallback lpTimeProc, UIntPtr dwUser, uint fuEvent); [DllImport("Winmm.dll", CharSet = CharSet.Auto)]
    static extern uint timeKillEvent(uint uTimerID); [DllImport("Winmm.dll", CharSet = CharSet.Auto)]
    static extern uint timeGetTime(); [DllImport("Winmm.dll", CharSet = CharSet.Auto)]
    static extern uint timeBeginPeriod(uint uPeriod); [DllImport("Winmm.dll", CharSet = CharSet.Auto)]
    static extern uint timeEndPeriod(uint uPeriod); //Timer type definitions
    [Flags]
    public enum fuEvent : uint
    {
    TIME_ONESHOT = 0,      //Event occurs once, after uDelay milliseconds.
    TIME_PERIODIC = 1,
    TIME_CALLBACK_FUNCTION = 0x0000,  /* callback is function */
    //TIME_CALLBACK_EVENT_SET = 0x0010, /* callback is event - use SetEvent */
    //TIME_CALLBACK_EVENT_PULSE = 0x0020  /* callback is event - use PulseEvent */
    } //Delegate definition for the API callback
    delegate void TimerCallback(uint uTimerID, uint uMsg, UIntPtr dwUser, UIntPtr dw1, UIntPtr dw2); //IDisposable code
    private bool disposed = false; public void Dispose()
    {
    Dispose(true);
    GC.SuppressFinalize(this);
    } private void Dispose(bool disposing)
    {
    if (!this.disposed)
    {
    if (disposing)
    {
    Stop();
    }
    }
    disposed = true;
    } ~MMTimer()
    {
    Dispose(false);
    } /// <summary>
    /// The current timer instance ID
    /// </summary>
    uint id = 0; /// <summary>
    /// The callback used by the the API
    /// </summary>
    TimerCallback thisCB; /// <summary>
    /// The timer elapsed event
    /// </summary>
    public event EventHandler Timer;
    protected virtual void OnTimer(EventArgs e)
    {
    if (Timer != null)
    Timer(this, e);
    } public MMTimer()
    {
    //Initialize the API callback
    thisCB = CBFunc;
    } /// <summary>
    /// Stop the current timer instance (if any)
    /// </summary>
    public void Stop()
    {
    lock (this)
    {
    if (id != 0)
    {
    timeKillEvent(id);
    Console.WriteLine("MMTimer " + id.ToString() + " stopped");
    id = 0;
    }
    }
    } /// <summary>
    /// Start a timer instance
    /// </summary>
    /// <param name="ms">Timer interval in milliseconds</param>
    /// <param name="repeat">If true sets a repetitive event, otherwise sets a one-shot</param>
    public void Start(uint ms, bool repeat)
    {
    //Kill any existing timer
    Stop(); //Set the timer type flags
    fuEvent f = fuEvent.TIME_CALLBACK_FUNCTION | (repeat ? fuEvent.TIME_PERIODIC : fuEvent.TIME_ONESHOT); lock (this)
    {
    id = timeSetEvent(ms, 0, thisCB, UIntPtr.Zero, (uint)f);
    if (id == 0)
    throw new Exception("timeSetEvent error");
    Console.WriteLine("MMTimer " + id.ToString() + " started");
    }
    } void CBFunc(uint uTimerID, uint uMsg, UIntPtr dwUser, UIntPtr dw1, UIntPtr dw2)
    {
    //Callback from the MMTimer API that fires the Timer event. Note we are in a different thread here
    OnTimer(new EventArgs());
    }
    }
    }都是调用 timeSetEvent时出错!
      

  3.   

    用完全路径试下,如:[DllImport("C:\WINDOWS\system32\Winmm.dll", CharSet = CharSet.Auto)]
      

  4.   


    忽视了一个重要环节!!!
    我是在wince环境下使用!刚才我重新建立一个window平台去编译它 就没哟问题!但是在CE下面就不行!
      

  5.   


    这个DLLIMPORT 是一个很变态的东西,我以前试过放在c:\windows\system32\目录不行,提示找不到,但是放在c:\windows\system\目录就好了你可以参考一下,多放几个目录试试。。
      

  6.   

    注册一下这个dll应该可以
    regsvr32 DllFullPath,保存为.bat文件,然后run as administration还有在项目的reference当中看看Embed Interop type是不是true,如果是的话,设置为false试试看
      

  7.   


    不行啊!这个问题不是在桌面windows下,而是在Wince下,在window桌面平台是没有问题的!!就是当把工程建立为智能设备时他就找不到 文件!!!
      

  8.   

    可能是wince下没有winmm.dll的引用文件。就是win32下面缺少winmm.dll的导入文件。
      

  9.   

    不懂wince,但是弱弱的问一下,wince下这个dll是自带的?如果没有注册直接引用是引用不到的
      

  10.   

    我已经把dll问价拷贝到,软件运行的wince目录下面了!
      

  11.   

    是否wince压根就不支持啊。参考:http://topic.csdn.net/u/20091118/11/97cef9b8-6fc6-4128-8a8f-7a654956a381.html