我写一个程序用到PlaySound函数,但是调用结束后,出现Project Project1.exe raised exception class EInvalidPointer with message 'Invalid pointer opertion'.Process stopped.Use Step or Run to continue.function PlaySound(pszSound: PChar; hmod: HMODULE; fdwSound: DWORD): BOOL; stdcall;
{$EXTERNALSYM PlaySoundA}函数原型:PlaySound('c16',Hinstance,SND_RESOURCE OR SND_SYNC);  //元.wav有谁知道是怎么回事吗?

解决方案 »

  1.   


    #define   IDR_SELECT     100
    #define   IDR_EAT        100
    #define   IDR_GOTO         100const
      cnt_SQUARE_SIZE = 56;{(270,102)}
      ResID_Wave_Select = 300;
      ResID_Wave_Move   = 301;
      ResID_Wave_Eat    = 302;
      ResID_Wave_Check  = 303;
      ResID_Wave_GameWin   = 304;
      ResID_Wave_GameOver  = 305;PlaySound(MAKEINTRESOURCE(nResId), MainInstance, SND_ASYNC or SND_NOWAIT or SND_RESOURCE);
      

  2.   

    IDR_SELECT    WAVE   DISCARDABLE  "Select.wav"
    IDR_EAT       WAVE   DISCARDABLE  "Eat.wav"
      

  3.   

    DLL有没有源码,调试一下,一般是野指针问题
      

  4.   

    看不明白你们写的,我的程序时在执行完PlaySound后程序要结束时报错的。
      

  5.   

    PlaySound(Pchar(l_c5),Hinstance,SND_RESOURCE OR SND_SYNC);  //l_c5是字符串变量
    就是他们执行完毕后会报指针错误的。
      

  6.   

    正好我有一个原来写的东东,供你参考
    {$R WaveResource.Res}{ TPlaySound }constructor TPlaySound.Create(const AName: string);
    begin
      FreeOnTerminate := True;
      inherited Create(True);
      FName := AName;
    end;procedure TPlaySound.Execute;
    begin
      inherited;
      MMSystem.PlaySound(PChar(FName), Hinstance, SND_RESOURCE or SND_SYNC);
    end;
      

  7.   

    你给的代码太少,看不明白我这有个调用的例子,供你参考
    {$R WavWork.RES} //新加入的编译资源文件的指令
    {  MyWav1 WAVE "D:\delphi\Demo\AutoGet\GetTask.wav"
       MyWav2 WAVE "D:\delphi\Demo\AutoGet\Get.wav" }procedure TMainForm.AlertSound(S_Name: String);
    begin
    //  调用.wav文件
    //  PlaySound(PChar(S_Name),0,SND_FILENAME or SND_ASYNC);
    //*/  调用资源文件中的wav
      PlaySound(PChar(S_Name),hInstance,Snd_ASync or Snd_Memory or snd_Resource);
    end;//调用的时候直接
      AlertSound('MyWav1');
      

  8.   

    为什么写两个PlaySound,第一个被Mask了,用第二个?那两个的区别是?
    我用的是PlaySound(PChar(S_Name),Hinstance,SND_RESOURCE OR SND_SYNC); 方式,有问题吗?
      

  9.   

    我也是用资源文件做的,程序代码如下:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,MMSystem, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    {$R   sounds.res}
    procedure TForm1.Button1Click(Sender: TObject);
    var
     l_str:string;
     l_c1,l_c2,l_c3,l_c4,l_c5,l_c6,l_c7:String;
     i:integer;
     l_flag:integer;        //标志位,是否读过yuan.wav
     Num:real;
     l_cc:String;
     l_Currency:Currency;
     m_bool:Boolean;
    begin
      //l_currency:=StrToCurr(Edit1.Text);
      l_currency:=88;  //例如读取88
      l_str:=CurrToStr(l_currency);
      Num:=StrToFloat(l_str);
      l_flag:=0;
      inherited;
         {0~9.99数字读取}
         if(Num<10) and (Num>=0)then
          begin
              l_c1:='c'+l_str[1];
              l_c3:='c'+l_str[3];
              l_c4:='c'+l_str[4];
              if not ( l_str[4] in ['0'..'9']) then
               begin
                 l_str[4]:='0';
               end;
            if not (l_str[3] in ['0'..'9'])  then
               begin
                  l_str[3]:='0';
               end;
           if StrToInt(l_str[1])<>0 then               //第一位
              begin
               PlaySound(Pchar(l_c1),Hinstance,SND_RESOURCE OR SND_SYNC);
              end
           else
              begin
                if  (StrToInt(l_str[3])=0) and (StrToInt(l_str[4])=0) then
                    PlaySound('c18',Hinstance,SND_RESOURCE OR SND_SYNC);
                    PlaySound('c16',Hinstance,SND_RESOURCE OR SND_SYNC);     //元.wav
              end;
           if (StrToInt(l_str[3])<>0) or (StrToInt(l_str[4])<>0) then
              begin
                PlaySound('c17',Hinstance,SND_RESOURCE OR SND_SYNC);   //点.wav
                l_flag:=l_flag+1;
              end;
           if StrToInt(l_str[3])<>0 then   //第三位
              begin
                PlaySound(Pchar(l_c3),Hinstance,SND_RESOURCE OR SND_SYNC);  //第三位
              end
           else
              begin
                if  StrToInt(l_str[4])<>0 then
                    PlaySound('c18',Hinstance,SND_RESOURCE OR SND_SYNC)
                else
                    if l_flag<1 then
                     PlaySound('c16',Hinstance,SND_RESOURCE OR SND_SYNC);     //元.wav
              end;
           if StrToInt(l_str[4])<>0 then   //第四位
              begin
                PlaySound(Pchar(l_c4),Hinstance,SND_RESOURCE OR SND_SYNC);  //第四位
                PlaySound('c16',Hinstance,SND_RESOURCE OR SND_SYNC);     //元.wav
              end
          end;
        {10~99.99的数字读取 Eg:99.10}     if (Num>=10) and (Num<100) then
           begin
            l_c1:='c'+ l_str[1];       //第一位
            l_c2:='c'+ l_str[2];       //第二位
            l_c4:='c'+ l_str[4];       //第四位
            l_c5:='c'+ l_str[5];       //第五位
            if not ( l_str[4] in ['0'..'9']) then
               begin
                 l_str[4]:='0';
               end;
            if not (l_str[5] in ['0'..'9'])  then
               begin
                  l_str[5]:='0';
               end;
             PlaySound(Pchar(l_c1),Hinstance,SND_RESOURCE OR SND_SYNC); //第一位
             PlaySound('c11',Hinstance,SND_RESOURCE OR SND_SYNC);       //拾
             if StrToInt(l_str[2])<>0 then
                begin
                  PlaySound(Pchar(l_c2),Hinstance,SND_RESOURCE OR SND_SYNC);   //第二位
                end;
             if  (StrToInt(l_str[4])=0) and (StrToInt(l_str[5])=0)  then
                begin
                   PlaySound('c16',Hinstance,SND_RESOURCE OR SND_SYNC);  //元.wav
                   l_flag:=1;
                end;
             if  (StrToInt(l_str[4])<>0)  or (StrToInt(l_str[5])<>0) then
                begin
                  PlaySound('c17',Hinstance,SND_RESOURCE OR SND_SYNC);     //点.wav
                  l_flag:=l_flag+1;
                end;
             if StrToInt(l_str[4])<>0 then                        //第四位
               begin
                PlaySound(Pchar(l_c4),Hinstance,SND_RESOURCE OR SND_SYNC);
                if StrToInt(l_str[5])=0  then
                   PlaySound('c16',Hinstance,SND_RESOURCE OR SND_SYNC);  //元.wav
               end
             else
                begin
                   if StrToInt(l_str[5])<>0  then
                      PlaySound('c18',Hinstance,SND_RESOURCE OR SND_SYNC)
                   else
                      if l_flag<1 then
                         PlaySound('c16',Hinstance,SND_RESOURCE OR SND_SYNC);  //元.wav
                end;
             if StrToInt(l_str[5])<>0 then                        //第五位
                begin
                  PlaySound(Pchar(l_c5),Hinstance,SND_RESOURCE OR SND_SYNC);
                  PlaySound('c16',Hinstance,SND_RESOURCE OR SND_SYNC);  //元.wav
                end;
           end;
    end.