Error opening system DLL -- any ideas?

Everything else that doesn't fall into one of the other PB categories.
Hi-Toro
Enthusiast
Enthusiast
Posts: 269
Joined: Sat Apr 26, 2003 3:23 pm

Error opening system DLL -- any ideas?

Post by Hi-Toro »

This code causes an error when run on both Windows 2000 and XP:

Code: Select all


#TH32CS_SNAPHEAPLIST = $1
#TH32CS_SNAPPROCESS = $2
#TH32CS_SNAPTHREAD = $4
#TH32CS_SNAPMODULE = $8
#TH32CS_SNAPALL = (#TH32CS_SNAPHEAPLIST | #TH32CS_SNAPPROCESS | #TH32CS_SNAPTHREAD | #TH32CS_SNAPMODULE)
#TH32CS_INHERIT = $80000000

Structure PROCESSENTRY32
    dwSize.l
    cntUsage.l
    th32ProcessID.l
    th32DefaultHeapID.l
    th32ModuleID.l
    cntThreads.l
    th32ParentProcessID.l
    pcPriClassBase.l
    dwFlags.l
    szExeFile.b [#MAX_PATH]
EndStructure

CreateToolhelp32Snapshot_ (#TH32CS_SNAPPROCESS, 0)

; The error...

;---------------------------
;PureBasic180532712.exe - Bad Image
;---------------------------
;The application Or DLL C:\winnt\System32\TOOLHELP.DLL is not a valid Windows image. Please check this against your installation diskette. 
;---------------------------
;OK   
;---------------------------

Anyone got any idea what's wrong? The CreateToolhelp32Snapshot command is supported on all OSs according to MSDN. I get the same result with OpenLibrary/"toolhelp.dll"...
James Boyd
http://www.hi-toro.com/
Death to the Pixies!
midebor
User
User
Posts: 26
Joined: Fri Apr 25, 2003 10:22 pm
Location: Liege, Belgium

Post by midebor »

Hi James,

I recently discovered Dependencywalker a very powerfull freeware tool to analyze dll functionning and interaction both static and dynamic.
Have a look at http://www.dependencywalker.com/
Very instructive ...

Michel
Hi-Toro
Enthusiast
Enthusiast
Posts: 269
Joined: Sat Apr 26, 2003 3:23 pm

Yes

Post by Hi-Toro »

Hi Michel,

Yeah, I've had that before (though thanks for the reminder!) -- it integrates well with a cool program called ProcessExplorer, from www.sysinternals.com (they have lots of cool stuff like this). It looks like the problem may be a PB bug, though, as the function works when called from Blitz; I've now posted it in the Bug Reports forum...
James Boyd
http://www.hi-toro.com/
Death to the Pixies!
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Error opening system DLL -- any ideas?

Post by PB »

I'm getting the same error as Hi-Toro when parsing a DLL. Here is my code:

Code: Select all

If OpenLibrary(0,"C:\Program Files\Common Files\Acronis\Drivers\setup16.dll")
  SetErrorMode_(#SEM_FAILCRITICALERRORS) ; Doesn't suppress error prompt. :(
  If ExamineLibraryFunctions(0)
    While NextLibraryFunction() : Debug LibraryFunctionName() : Wend
  EndIf
  CloseLibrary(0)
  SetErrorMode_(0)
EndIf
And the MessageBox error prompt that comes up when using it:

Code: Select all

---------------------------
PureBasic_Compilation0.exe - Bad Image
---------------------------
The application or DLL C:\Program Files\Common Files\Acronis\Drivers\setup16.dll is
not a valid Windows image. Please check this against your installation diskette.
---------------------------
OK
---------------------------
[Edit] If I put CallDebugger before the OpenLibrary line, and step through
it, the OpenLibrary command is failing without returning 0. So this is actually
a PureBasic bug.
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Post by ABBKlaus »

SetErrorMode should be called first, this way it works fine.

Code: Select all

SetErrorMode_(#SEM_FAILCRITICALERRORS) ; Doesn't suppress error prompt. :( 
If OpenLibrary(0,"C:\Program Files\Common Files\Acronis\Drivers\setup16.dll") 
  If ExamineLibraryFunctions(0) 
    While NextLibraryFunction() : Debug LibraryFunctionName() : Wend 
  EndIf 
  CloseLibrary(0) 
EndIf 

SetErrorMode_(0) 
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Thanks ABBKlaus! :) I'm getting too old for this stuff.
Post Reply