我的代码中出现了随机访问违规错误

8

我一直在修改、调试、修改、调试(你知道的),但我就是想不出是什么原因导致了这些访问冲突!

最典型的情况是 Skype4COM.dll 中的“Read of address 80000000”,但我不认为是它里面的代码导致了这个问题。

我最初怀疑是我向 Skype API(通过 Skype4COM)发送了太多的命令,但在添加了一些暂停逻辑后,以确保 Skype 和 COM 对象能跟上,我意识到那不是原因——它仍然发生了!

我使用线程来执行这个操作,即使不使用线程,它仍会引起访问冲突。(我每次只使用一个线程)

以下是我的线程执行方法:

procedure TMyThread.Execute;
Var
  I             : Integer;
  User          : PUser;
  ReceiverName  : String;
  FullMessage   : String;
  PauseEvent    : TEvent;
  TimesToPause  : Integer;
  iPause        : Integer;
  J             : Integer;
  FExit         : Boolean;
begin
  inherited;
  if Terminated then
  Exit;

  FreeOnTerminate := True;

  CoInitialize(Nil);

  FExit         := True;
  UserList      := TList.Create;
  SkypeThr      := TSkype.Create(Nil);
  PauseEvent    := TEvent.Create(True);
  Try
  try
      SkypeThr.Attach(10,False);

      Synchronize(SyncBegin);

      iMax := UserList.Count;
      Synchronize(SyncSetMax);
      LogID := 'N/A';


      TimesToPause := Round(UserList.Count / 300);

      // For Loop
      for I := 0 to UserList.Count - 1 do
        begin

          FullMessage := sMessage;

          if (Trim(sFooter) <> '') and (bFooter) then
          FullMessage := FullMessage+sLineBreak+sFooter;

          User := PUser(UserList.Items[I]);

          ReceiverName    := User.DisplayName;
          if Trim(ReceiverName) = '' then
          ReceiverName    := User.SkypeID;

          FullMessage := ParseMessage(FullMessage,ReceiverName);
          LogId           := User.SkypeID;
          try
          SkypeThr.CreateChatWith(User.SkypeID).SendMessage(FullMessage);

          PauseEvent.WaitFor(10);
          if TimesToPause >= 1 then
          Begin
          for iPause := 1 to TimesToPause do
          begin

          J := iPause*300;
             if J = I then
             begin

              Synchronize(SyncPauseBegin);

              PauseEvent.WaitFor(3000);

              Synchronize(SyncPauseEnd);

             end;

          end;

          end;
          Except on E:Exception do
            begin
             ExErr := E.Message;
             ExLog := 'Sending message to user "'+User.SkypeID+'" failed: ';
             ExMsg := 'Error: Sending message to user "'+User.SkypeID+'" failed: ';
             Synchronize(Procedure
             Begin
              Log(ExMsg+ExErr+sLineBreak+' - Last logged Handle: '+LogID);
              if not AnsiContainsText(ExErr,'contact is disabled') then
              Begin
              ErrMsg(ExMsg+ExErr);
              FExit     := True;
              End else FExit := False;

             End
             );


             if FExit then
             Exit;

          end;
          End;



          iProgress := I+1;
          Synchronize(SyncProgress);

        end;

      // End my for loop
  // Except
  Except on E:Exception do
  begin
   ExErr := E.Message;
   ExLog := 'Error while broadcasting: ';
   ExMsg := 'An error has occured while broadcasting: ';
   Synchronize(
   Procedure
   Begin
    Log(ExMsg+ExErr);
    ErrMsg(ExMsg+ExErr);
   End
   );
   Exit;
  end;
  end;
  // Fínally
  Finally
  PauseEvent.Free;
  FreeList;
  SkypeThr.Free;
  Synchronize(SyncFinalize);
  CoUninitialize;
  End;


end;

访问冲突发生在整个过程的中间 - 我知道这是因为如果它在最后,显示进度的进度条将会满,但实际上它通常只有10-80%。
ErrMsg();基本上只是一个MessageDlg例程,所以我不必做所有的mbOk和其他东西。
Log();将错误添加到我的日志备忘录中。
如果您需要更多信息,请随时询问!
编辑:我忘了提到调试有点困难,因为AV发生在客户机上,而不是我的电脑上。然而,我将尝试记录每个可疑动作,通过在每个可疑行之前/之后放置Log();。
编辑2:我刚在另一个朋友的电脑上测试了一下,他的完美无缺。我有一些测试人员,大约50%的人报告了AV的问题。。
下面是madExcept日志之一:
date/time         : 2011-03-29, 02:01:51, 590ms
computer name     : MTPOCKETS-PC
user name         : mtpockets
registered owner  : mtpockets
operating system  : Windows 7 Starter build 7600
system language   : English
system up time    : 1 day 3 hours
program up time   : 3 hours 12 minutes
processors        : 2x Intel(R) Atom(TM) CPU N270 @ 1.60GHz
physical memory   : 105/1014 MB (free/total)
free disk space   : (C:) 100.42 GB
display mode      : 1024x600, 32 bit
process id        : $1ac8
allocated memory  : 111.87 MB
executable        : xSky.exe
exec. date/time   : 2011-03-27 20:15
version           : 0.9.2.448
compiled with     : Delphi 2010
madExcept version : 3.0l
contact name      : david gilyeat
contact email     : admin@matriscruiser.com
Reproducable      : no
callstack crc     : $280a264a, $5b090a2b, $5b090a2b
exception number  : 2
exception class   : EAccessViolation
exception message : Access violation at address 280A264A in module 'Skype4COM.dll'. Read of address 00B5E000.

main thread ($f8c):
280a264a +000 Skype4COM.dll
76cc8e97 +00a USER32.dll                 DispatchMessageW
75643e73 +0a4 oleaut32.dll               DispCallFunc
76cc8e97 +00a USER32.dll                 DispatchMessageW
00550079 +11d xSky.exe      Forms        TApplication.ProcessMessage
005500be +00a xSky.exe      Forms        TApplication.HandleMessage
005503e9 +0c9 xSky.exe      Forms        TApplication.Run
007b3771 +085 xSky.exe      xSky  49 +10 initialization
75e61192 +010 kernel32.dll               BaseThreadInitThunk

thread $a54:
76ea5caa +0a ntdll.dll     NtWaitForMultipleObjects
75e61192 +10 kernel32.dll  BaseThreadInitThunk

thread $1824:
76ea5cca +000a ntdll.dll                          NtWaitForSingleObject
75031796 +0066 KERNELBASE.dll                     WaitForSingleObjectEx
75e5effe +003e kernel32.dll                       WaitForSingleObjectEx
75e5efad +000d kernel32.dll                       WaitForSingleObject
0057a8f2 +16c6 xSky.exe       VirtualTrees        .TBaseVirtualTree
004a1526 +0042 xSky.exe       Classes             ThreadProc
00406cf0 +0028 xSky.exe       System       152 +0 ThreadWrapper
75e61192 +0010 kernel32.dll                       BaseThreadInitThunk

thread $12f4:
76cc8fbd +26 USER32.dll    GetMessageW
75e61192 +10 kernel32.dll  BaseThreadInitThunk

thread $10c8: <suspended>
76ea588a +00a ntdll.dll                    NtSetEvent
76e8fb6e +020 ntdll.dll                    RtlpUnWaitCriticalSection
76e8fb3f +000 ntdll.dll                    RtlLeaveCriticalSection
004a1d06 +11e xSky.exe     Classes         TThread.Synchronize
004a1dd5 +029 xSky.exe     Classes         TThread.Synchronize
005f2e42 +03a xSky.exe     pngimage        TChunkIDAT.CopyNonInterlacedRGBAlpha16
004a1526 +042 xSky.exe     Classes         ThreadProc
00406cf0 +028 xSky.exe     System   152 +0 ThreadWrapper
75e61192 +010 kernel32.dll                 BaseThreadInitThunk

thread $12bc:
76ea5caa +00a ntdll.dll                      NtWaitForMultipleObjects
7503686c +000 KERNELBASE.dll                 WaitForMultipleObjectsEx
75e5f145 +089 kernel32.dll                   WaitForMultipleObjectsEx
004a4cd6 +056 xSky.exe       SyncObjs        THandleObject.WaitFor
0052f368 +468 xSky.exe       Controls        TCustomHintShowHideThread.Execute
004a1526 +042 xSky.exe       Classes         ThreadProc
00406cf0 +028 xSky.exe       System   152 +0 ThreadWrapper
75e61192 +010 kernel32.dll                   BaseThreadInitThunk

thread $1da0:
76cc8fbd +26 USER32.dll             GetMessageW
00466549 +0d xSky.exe     madExcept CallThreadProcSafe
004665b3 +37 xSky.exe     madExcept ThreadExceptFrame
75e61192 +10 kernel32.dll           BaseThreadInitThunk
>> >> created by thread $e24 at:
75da480b +00 SHLWAPI.dll

thread $604: <suspended>
76ea5cca +00a ntdll.dll                      NtWaitForSingleObject
75031796 +066 KERNELBASE.dll                 WaitForSingleObjectEx
75e5effe +03e kernel32.dll                   WaitForSingleObjectEx
75e5efad +00d kernel32.dll                   WaitForSingleObject
004a1d22 +13a xSky.exe       Classes         TThread.Synchronize
004a1dd5 +029 xSky.exe       Classes         TThread.Synchronize
005f2e42 +03a xSky.exe       pngimage        TChunkIDAT.CopyNonInterlacedRGBAlpha16
004a1526 +042 xSky.exe       Classes         ThreadProc
00406cf0 +028 xSky.exe       System   152 +0 ThreadWrapper
75e61192 +010 kernel32.dll                   BaseThreadInitThunk

thread $1ee4:
76ea5cda +0a ntdll.dll     NtWaitForWorkViaWorkerFactory
75e61192 +10 kernel32.dll  BaseThreadInitThunk

thread $ff4: <priority:-1>
76cc8e97 +0a USER32.dll                  DispatchMessageW
004a1526 +42 xSky.exe     Classes        ThreadProc
00406cf0 +28 xSky.exe     System  152 +0 ThreadWrapper
75e61192 +10 kernel32.dll                BaseThreadInitThunk

thread $8ec:
76cc8fbd +26 USER32.dll    GetMessageW
75e61192 +10 kernel32.dll  BaseThreadInitThunk

modules:
00400000 xSky.exe              0.9.2.448          C:\Program Files\xSky Software LLC\xSky
28000000 Skype4COM.dll         1.0.36.0           C:\Program Files\xSky Software LLC\xSky
66980000 mso.dll               12.0.6545.5004     C:\Program Files\Common Files\Microsoft Shared\office12
67a00000 olmapi32.dll          12.0.6550.5001     C:\Program Files\Microsoft Office\Office12
69660000 SearchFolder.dll      6.1.7600.16385     C:\Windows\system32
69c40000 NetworkExplorer.dll   6.1.7600.16385     C:\Windows\system32
6a190000 StructuredQuery.dll   7.0.7600.16587     C:\Windows\System32
6a3c0000 davclnt.dll           6.1.7600.16723     C:\Windows\System32
6a7f0000 ntlanman.dll          6.1.7600.16385     C:\Windows\System32
6abb0000 EhStorAPI.dll         6.1.7600.16385     C:\Windows\system32
6bbc0000 mlang.dll             6.1.7600.16385     C:\Windows\system32
6bf20000 ieproxy.dll           8.0.7600.16722     C:\Program Files\Internet Explorer
6d890000 ieframe.DLL           8.0.7600.16723     C:\Windows\system32
6eba0000 msls31.dll            3.10.349.0         C:\Windows\system32
6ef40000 SHDOCVW.dll           6.1.7600.16385     C:\Windows\system32
6ef70000 actxprxy.dll          6.1.7600.16385     C:\Windows\system32
6f050000 LINKINFO.dll          6.1.7600.16385     C:\Windows\system32
6f220000 MSMAPI32.DLL          12.0.6413.1000     C:\Program Files\Common Files\SYSTEM\MSMAPI\1033
6f320000 pnrpnsp.dll           6.1.7600.16385     C:\Windows\system32
6f340000 napinsp.dll           6.1.7600.16385     C:\Windows\system32
6f350000 winrnr.dll            6.1.7600.16385     C:\Windows\System32
6f3b0000 sfc_os.DLL            6.1.7600.16385     C:\Windows\system32
6f3c0000 SFC.DLL               6.1.7600.16385     C:\Windows\system32
6f4b0000 PortableDeviceApi.dll 6.1.7600.16385     C:\Windows\system32
6f840000 DAVHLPR.dll           6.1.7600.16385     C:\Windows\System32
6f8f0000 ntshrui.dll           6.1.7600.16385     C:\Windows\system32
6f9c0000 CSCDLL.dll            6.1.7600.16385     C:\Windows\System32
6f9f0000 cscui.dll             6.1.7600.16385     C:\Windows\System32
6fa60000 EhStorShell.dll       6.1.7600.16385     C:\Windows\system32
6ffa0000 msi.dll               5.0.7600.16385     C:\Windows\system32
70300000 winspool.drv          6.1.7600.16385     C:\Windows\system32
70760000 MPR.dll               6.1.7600.16385     C:\Windows\system32
70dc0000 rasadhlp.dll          6.1.7600.16385     C:\Windows\system32
70dd0000 cscapi.dll            6.1.7600.16385     C:\Windows\system32
70ee0000 drprov.dll            6.1.7600.16385     C:\Windows\System32
70ef0000 mapi32.dll            1.0.2536.0         C:\Windows\system32
70fa0000 winmm.DLL             6.1.7600.16385     C:\Windows\system32
71080000 olepro32.dll          6.1.7600.16385     C:\Windows\system32
71140000 msimg32.dll           6.1.7600.16385     C:\Windows\system32
711b0000 MSVCR80.dll           8.0.50727.4927     C:\Windows\WinSxS\x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.4927_none_d08a205e442db5b5
71990000 wsock32.dll           6.1.7600.16385     C:\Windows\system32
719a0000 oleacc.dll            7.0.0.0            C:\Windows\system32
73120000 dhcpcsvc6.DLL         6.1.7600.16385     C:\Windows\system32
73130000 dhcpcsvc.DLL          6.1.7600.16385     C:\Windows\system32
731a0000 Fwpuclnt.dll          6.1.7600.16385     C:\Windows\system32
73340000 WINNSI.DLL            6.1.7600.16385     C:\Windows\system32
73350000 IPHLPAPI.DLL          6.1.7600.16385     C:\Windows\system32
734a0000 slc.dll               6.1.7600.16385     C:\Windows\system32
73570000 mssprxy.dll           7.0.7600.16385     C:\Windows\system32
73690000 NLAapi.dll            6.1.7600.16385     C:\Windows\system32
736c0000 ntmarta.dll           6.1.7600.16385     C:\Windows\system32
73720000 samcli.dll            6.1.7600.16385     C:\Windows\system32
73730000 wkscli.dll            6.1.7600.16385     C:\Windows\system32
73740000 netutils.dll          6.1.7600.16385     C:\Windows\system32
738d0000 WindowsCodecs.dll     6.1.7600.16385     C:\Windows\system32
73a30000 xmllite.dll           1.3.1000.0         C:\Windows\system32
73a60000 dwmapi.dll            6.1.7600.16385     C:\Windows\system32
73b40000 DUser.dll             6.1.7600.16385     C:\Windows\system32
73b70000 DUI70.dll             6.1.7600.16385     C:\Windows\system32
73c30000 gdiplus.dll           6.1.7600.16385     C:\Windows\WinSxS\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.7600.16385_none_72fc7cbf861225ca
73dc0000 uxtheme.dll           6.1.7600.16385     C:\Windows\system32
73e00000 propsys.dll           7.0.7600.16385     C:\Windows\system32
74010000 SAMLIB.dll            6.1.7600.16385     C:\Windows\system32
74050000 comctl32.dll          6.10.7600.16661    C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7600.16661_none_420fe3fa2b8113bd
744b0000 version.dll           6.1.7600.16385     C:\Windows\system32
74540000 wshtcpip.dll          6.1.7600.16385     C:\Windows\System32
747d0000 rsaenh.dll            6.1.7600.16385     C:\Windows\system32
748b0000 DNSAPI.dll            6.1.7600.16385     C:\Windows\system32
749e0000 wship6.dll            6.1.7600.16385     C:\Windows\System32
749f0000 mswsock.dll           6.1.7600.16385     C:\Windows\system32
74a30000 CRYPTSP.dll           6.1.7600.16385     C:\Windows\system32
74be0000 srvcli.dll            6.1.7600.16385     C:\Windows\system32
74d60000 Secur32.dll           6.1.7600.16385     C:\Windows\System32
74e90000 SspiCli.dll           6.1.7600.16385     C:\Windows\system32
74eb0000 WINSTA.dll            6.1.7600.16385     C:\Windows\System32
74ee0000 apphelp.dll           6.1.7600.16481     C:\Windows\system32
74f30000 CRYPTBASE.dll         6.1.7600.16385     C:\Windows\system32
74f40000 sxs.dll               6.1.7600.16385     C:\Windows\system32
74fd0000 RpcRtRemote.dll       6.1.7600.16385     C:\Windows\system32
74fe0000 profapi.dll           6.1.7600.16385     C:\Windows\system32
75020000 MSASN1.dll            6.1.7600.16415     C:\Windows\system32
75030000 KERNELBASE.dll        6.1.7600.16385     C:\Windows\system32
75110000 CFGMGR32.dll          6.1.7600.16385     C:\Windows\system32
75140000 DEVOBJ.dll            6.1.7600.16385     C:\Windows\system32
75160000 CRYPT32.dll           6.1.7600.16385     C:\Windows\system32
75280000 WINTRUST.dll          6.1.7600.16493     C:\Windows\system32
752b0000 urlmon.dll            8.0.7600.16723     C:\Windows\system32
753f0000 SETUPAPI.dll          6.1.7600.16385     C:\Windows\system32
75590000 USP10.dll             1.626.7600.16385   C:\Windows\system32
75630000 oleaut32.dll          6.1.7600.16567     C:\Windows\system32
756c0000 WLDAP32.dll           6.1.7600.16385     C:\Windows\system32
75710000 psapi.dll             6.1.7600.16385     C:\Windows\system32
75730000 WS2_32.dll            6.1.7600.16385     C:\Windows\system32
75770000 CLBCatQ.DLL           2001.12.8530.16385 C:\Windows\system32
75800000 msvcrt.dll            7.0.7600.16385     C:\Windows\system32
758b0000 GDI32.dll             6.1.7600.16385     C:\Windows\system32
75900000 LPK.dll               6.1.7600.16385     C:\Windows\system32
75910000 iertutil.dll          8.0.7600.16722     C:\Windows\system32
75b10000 RPCRT4.dll            6.1.7600.16385     C:\Windows\system32
75bf0000 ADVAPI32.DLL          6.1.7600.16385     C:\Windows\system32
75c90000 WININET.dll           8.0.7600.16723     C:\Windows\system32
75d90000 SHLWAPI.dll           6.1.7600.16385     C:\Windows\system32
75df0000 sechost.dll           6.1.7600.16385     C:\Windows\SYSTEM32
75e10000 kernel32.dll          6.1.7600.16481     C:\Windows\system32
75ef0000 NSI.dll               6.1.7600.16385     C:\Windows\system32
75f00000 ole32.dll             6.1.7600.16624     C:\Windows\system32
76060000 shell32.dll           6.1.7600.16644     C:\Windows\system32
76cb0000 USER32.dll            6.1.7600.16385     C:\Windows\system32
76d80000 comdlg32.dll          6.1.7600.16385     C:\Windows\system32
76e60000 ntdll.dll             6.1.7600.16695     C:\Windows\SYSTEM32
76fa0000 IMM32.DLL             6.1.7600.16385     C:\Windows\system32
76fc0000 MSCTF.dll             6.1.7600.16385     C:\Windows\system32

processes:
0000 Idle                     0 0   0
0004 System                   0 0   0
0100 smss.exe                 0 0   0
01a4 csrss.exe                0 0   0
01d8 wininit.exe              0 0   0
01e0 csrss.exe                1 0   0
0210 services.exe             0 0   0
0230 winlogon.exe             1 0   0
023c lsass.exe                0 0   0
0244 lsm.exe                  0 0   0
02b0 svchost.exe              0 0   0
02fc svchost.exe              0 0   0
0360 svchost.exe              0 0   0
039c svchost.exe              0 0   0
03bc svchost.exe              0 0   0
0408 audiodg.exe              0 0   0
0438 svchost.exe              0 0   0
0498 svchost.exe              0 0   0
0540 spoolsv.exe              0 0   0
055c svchost.exe              0 0   0
05c0 svchost.exe              0 0   0
0620 sqlservr.exe             0 0   0
06cc taskhost.exe             1 34  26  normal C:\Windows\system32
06e4 sqlbrowser.exe           0 0   0
075c sqlwriter.exe            0 0   0
07b8 Dwm.exe                  1 25  9   normal C:\Windows\system32
0074 Explorer.EXE             1 414 263 normal C:\Windows
0b68 SearchIndexer.exe        0 0   0
0c40 wmpnetwk.exe             0 0   0
0a00 svchost.exe              0 0   0
16c8 taskhost.exe             1 0   0
1f34 taskmgr.exe              1 130 104 high   C:\Windows\system32
0968 FlashUtil10l_ActiveX.exe 1 9   5   normal C:\Windows\system32\Macromed\Flash
1be8 Skype.exe                1 582 249 normal C:\Program Files\Skype\Phone
1f0c iexplore.exe             1 993 405 normal C:\Program Files\Internet Explorer
1b08 iexplore.exe             1 501 376 normal C:\Program Files\Internet Explorer
1480 skypePM.exe              1 463 694 normal C:\Program Files\Skype\Plugin Manager
0810 iexplore.exe             1 502 236 normal C:\Program Files\Internet Explorer
0e3c iexplore.exe             1 994 378 normal C:\Program Files\Internet Explorer
1bf0 iexplore.exe             1 496 203 normal C:\Program Files\Internet Explorer
1ac8 xSky.exe                 1 407 181 normal C:\Program Files\xSky Software LLC\xSky
16b4 OUTLOOK.EXE              1 502 255 normal C:\Program Files\Microsoft Office\Office12
1b88 WINWORD.EXE              1 272 80  normal C:\Program Files\Microsoft Office\Office12
0218 iexplore.exe             1 405 190 normal C:\Program Files\Internet Explorer

hardware:
+ Batteries
  - Microsoft AC Adapter
  - Microsoft ACPI-Compliant Control Method Battery
  - Microsoft Composite Battery
+ Computer
  - ACPI x86-based PC
+ Disk drives
  - ST9160412ASG ATA Device
+ Display adapters
  - Mobile Intel(R) 945 Express Chipset Family (driver 8.15.10.1930)
  - Mobile Intel(R) 945 Express Chipset Family (driver 8.15.10.1930)
+ IDE ATA/ATAPI controllers
  - ATA Channel 0
  - ATA Channel 1
  - Intel(R) ICH7-M Family Serial ATA Storage Controller - 27C4 (driver 9.1.1.1016)
+ Imaging devices
  - PC Camera
+ Keyboards
  - Standard PS/2 Keyboard
+ Mice and other pointing devices
  - PS/2 Compatible Mouse
+ Monitors
  - Generic PnP Monitor
+ Network adapters
  - 802.11n Wireless LAN Card (driver 3.0.11.0)
  - Realtek PCIe FE Family Controller (driver 7.6.820.2009)
+ Processors
  - Intel(R) Atom(TM) CPU N270   @ 1.60GHz
  - Intel(R) Atom(TM) CPU N270   @ 1.60GHz
+ Sound, video and game controllers
  - Realtek High Definition Audio (driver 6.0.1.5936)
+ Storage volume shadow copies
  - Generic volume shadow copy
  - Generic volume shadow copy
  - Generic volume shadow copy
  - Generic volume shadow copy
  - Generic volume shadow copy
  - Generic volume shadow copy
  - Generic volume shadow copy
  - Generic volume shadow copy
  - Generic volume shadow copy
  - Generic volume shadow copy
+ System devices
  - ACPI Fixed Feature Button
  - ACPI Lid
  - ACPI Power Button
  - ACPI Sleep Button
  - ACPI Thermal Zone
  - Composite Bus Enumerator
  - Direct memory access controller
  - File as Volume Driver
  - High Definition Audio Controller
  - High precision event timer
  - Intel(R) 82801 PCI Bridge - 2448
  - Intel(R) 82802 Firmware Hub Device
  - Intel(R) ICH7M/U LPC Interface Controller - 27B9 (driver 9.1.1.1016)
  - Intel(R) N10/ICH7 Family PCI Express Root Port - 27D0 (driver 9.1.1.1016)
  - Intel(R) N10/ICH7 Family PCI Express Root Port - 27D2 (driver 9.1.1.1016)
  - Intel(R) N10/ICH7 Family PCI Express Root Port - 27D4 (driver 9.1.1.1016)
  - Intel(R) N10/ICH7 Family SMBus Controller - 27DA (driver 9.1.1.1016)
  - Microsoft ACPI-Compliant Embedded Controller
  - Microsoft ACPI-Compliant System
  - Microsoft System Management BIOS Driver
  - Microsoft Virtual Drive Enumerator Driver
  - Microsoft Windows Management Interface for ACPI
  - Mobile Intel(R) 945GME Express Processor to DRAM Controller - 27AC
  - Motherboard resources
  - Motherboard resources
  - Motherboard resources
  - Numeric data processor
  - PCI bus
  - Plug and Play Software Device Enumerator
  - Programmable interrupt controller
  - System CMOS/real time clock
  - System timer
  - Terminal Server Keyboard Driver
  - Terminal Server Mouse Driver
  - UMBus Enumerator
  - UMBus Root Bus Enumerator
  - Volume Manager
+ Universal Serial Bus controllers
  - Intel(R) N10/ICH7 Family USB Universal Host Controller - 27C8 (driver 9.1.1.1016)
  - Intel(R) N10/ICH7 Family USB Universal Host Controller - 27C9 (driver 9.1.1.1016)
  - Intel(R) N10/ICH7 Family USB Universal Host Controller - 27CA (driver 9.1.1.1016)
  - Intel(R) N10/ICH7 Family USB Universal Host Controller - 27CB (driver 9.1.1.1016)
  - Intel(R) N10/ICH7 Family USB2 Enhanced Host Controller - 27CC (driver 9.1.1.1016)
  - USB Composite Device
  - USB Root Hub
  - USB Root Hub
  - USB Root Hub
  - USB Root Hub
  - USB Root Hub

cpu registers:
eax = 0165013d
ebx = 00f200d8
ecx = 002bc850
edx = 00000000
esi = 00b5dffd
edi = 0b7edfb8
eip = 280a264a
esp = 0012dbe8
ebp = 0012dbf0

stack dump:
0012dbe8  d8 00 f2 00 00 00 00 00 - 0c dc 12 00 0f 1d 0a 28  ...............(
0012dbf8  20 00 3c 0b 65 00 73 00 - d8 00 f2 00 6c 00 79 00  ..<.e.s.....l.y.
0012dc08  b0 20 72 07 b4 20 72 07 - 71 1a 00 28 20 00 3c 0b  ..r...r.q..(..<.
0012dc18  de 00 f2 00 65 00 73 00 - d8 00 f2 00 e4 ff ff ff  ....e.s.........
0012dc28  cc 20 72 07 98 1f 72 07 - 00 00 00 00 8c de 08 28  ..r...r........(
0012dc38  cc 20 72 07 00 00 00 00 - ff ff ff ff 0f 89 13 e7  ..r.............
0012dc48  07 00 00 00 18 0b e3 04 - 78 e9 12 00 00 00 00 00  ........x.......
0012dc58  70 dc 12 01 18 0b e3 04 - 01 02 00 00 00 00 70 07  p.............p.
0012dc68  d8 33 e0 00 10 00 00 00 - f0 00 00 00 00 00 00 00  .3..............
0012dc78  07 00 00 00 09 02 00 00 - 00 00 80 07 45 00 52 00  ............E.R.
0012dc88  53 00 00 00 11 00 00 00 - 00 00 00 00 07 00 00 00  S...............
0012dc98  00 00 00 00 bc 7d 72 07 - 09 00 20 00 00 00 00 00  .....}r.........
0012dca8  18 dd 12 00 0c 45 cc 76 - 02 00 00 00 07 00 00 00  .....E.v........
0012dcb8  78 5d 0f 28 eb 02 00 00 - c4 2f 0f 28 80 16 79 07  x].(...../.(..y.
0012dcc8  80 09 80 07 00 00 00 00 - c8 dc 12 00 cc dc 12 00  ................
0012dcd8  74 0f 80 07 00 00 00 00 - d8 dc 12 00 dc dc 12 00  t...............
0012dce8  00 00 00 00 00 00 00 00 - e8 dc 12 00 ec dc 12 00  ................
0012dcf8  30 98 c8 06 74 0f 80 07 - 03 00 00 00 74 07 15 00  0...t.......t...
0012dd08  ec 37 0f 28 00 00 00 00 - 01 00 00 00 00 00 00 00  .7.(............
0012dd18  01 02 00 00 06 00 00 00 - 00 00 00 00 00 00 00 00  ................

disassembling:
[...]
007b375d      mov     eax, [eax]
007b375f      mov     edx, [$771ba4]
007b3765      call    -$26359a ($5501d0)     ; Forms.TApplication.CreateForm
007b376a 49   mov     eax, [$7c6900]
007b376f      mov     eax, [eax]
007b3771    > call    -$263456 ($550320)     ; Forms.TApplication.Run
007b3776      jmp     loc_7b377e
007b3778 52   push    eax
007b3779      call    -$3a500e ($40e770)     ; Windows.SetForegroundWindow
007b377e 55   call    -$3acbff ($406b84)     ; System.@Halt0

编辑3:记录了每行代码后,我发现罪犯CreateChatWith.SendMessage这一行!你有什么建议?

编辑4:好的,通过拆分CreateChatWith和SendMessage,发现是SendMessage引起的问题!

谢谢!


1
你需要找出哪一行代码正在访问无效的内存地址。然后你需要弄清楚为什么这个内存地址是无效的。你知道哪一行代码正在访问无效的内存地址吗? - David Heffernan
2
你需要提供更多信息。考虑使用MadExcept(我相信你可以免费获取)构建你的应用程序,它应该提供完整的调用堆栈以及生成AV的确切行。 - Tim Sullivan
1
我正在使用线程来执行此操作,即使不使用线程,它仍会引发AV错误。(我一次只使用一个线程) --> 使用一个TThread仍然是在使用线程。不要认为使用一个TThread就是单线程。 - The_Fox
你是否单步调试过你的代码并检查了所有内容?如果没有,你应该学习如何做。这是一个缓慢而需要耐心的练习,但似乎你需要一些它。 - Warren P
@Tim - 我已经在使用MadExcept了,我回家后会上传一个Bug报告。 - Jeff
显示剩余43条评论
4个回答

5
您的异常信息可能是“访问地址XXXXXXX时发生违规操作。 Blablabla”。请记下该地址并在Execute方法中的某个地方设置断点。当执行停在该断点处时,从菜单中选择“查找错误”(在编辑或其他下),并输入地址。您现在将跳转到发生错误的代码。
如果它出现在Execute方法中的某个地方,请告诉我们它是哪一行。此外,我建议您使用类似MadExcept的工具记录异常,包括堆栈跟踪。 当您不知道如何使用Delphi调试器调试dll时 阅读您的帖子后,我怀疑您不知道如何使用Delphi调试dll(无意冒犯)。以下是您应该做的:
  • 退出Skype
  • 在项目选项中,设置“包含TD32信息”,设置“包含远程调试符号”(不确定这个,但这不会有任何损失)
  • 重新构建
  • 打开“调试器选项”,确保“停止Delphi异常”已选中
  • 打开“运行参数”
  • 将主机应用程序设置为Skype.exe
  • 按F9,Skype现在将启动
  • 当您的dll被Skype加载时,您的代码中将出现蓝色点。您也可以设置断点。
  • 当错误发生时,调试器将停在发生错误的行。

这个 DLL 不是我的,而是 Skype 的 - 我没有它的源代码。 :( - Jeff
@Jeff:我的错,我以为你正在开发使用com的插件。 - The_Fox
没关系,我想我需要更好地表达我的问题,对吧? - Jeff

1

由于没有足够的信息来具体了解,我要打个赌。我打赌AV是从本地变量User的这些访问中出现的:

ReceiverName    := User.DisplayName; // <------- Maybe here?
if Trim(ReceiverName) = '' then
  ReceiverName    := User.SkypeID; // <------- Maybe here?

我猜测 User 的类型是指针类型,这由类型声明所表示:
User          : PUser;

我猜测这个转换:

User := PUser(UserList.Items[I]);

类型转换是将不同类型的数据强制转换为另一种类型。在转换时,编译器不会对其进行验证,它会尝试将声明类型的结构层叠到指向的内存上。当您尝试引用该结构的成员时,实际存在于内存中的布局可能与所需布局不匹配,从而导致问题。

如果您可以逐步执行此代码并检查每个步骤中的数据,则应很容易找到错误,假设在I很小时已经发生了。

这里还有其他人能够比我更好地猜测。有人愿意接手吗?


也许在另一个线程中修改/删除了UserList中的项目。 - The_Fox
但实际上,当我没有使用线程时,我甚至没有使用包含PUser的TList - 我只是循环遍历VirtualTreeview节点。 - Jeff

1
编辑3:在记录了每一行代码之后,我发现罪犯是CreateChatWith.SendMessage这一行!你有什么建议吗?
我会将这一行拆分。
 SkypeThr.CreateChatWith(User.SkypeID).SendMessage(FullMessage);

拆分成两个或更多:

 SkypeThr.CreateChatWith(User.SkypeID);
 SkypeThr.SendMessage(FullMessage);

以进一步识别有问题的代码。


然后我会添加一些代码行来访问FullMessage属性(只是一些断言),然后将其传递给SendMessage函数。 - mjn

0
如果您已经三次检查了代码中的所有内容,那么请比较Skype DLL的Pascal头文件实现与C头文件,并查找头文件翻译中的错误。您通过SendMessage()发送的内容必须完全匹配它所期望的内容。

看起来你正在错误地使用COM DLL。你应该像这样尝试:http://developer.skype.com/skype4com-examples-delphi(特别是聊天示例:http://developer.skype.com/delphi-examples/chatmessages-pas),以及Dr Bob的Skype聊天示例:http://www.drbob42.com/examines/examin75.htm。 - avra
我真的不太看出有什么区别。 - Jeff

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接