Page 1 of 1

Error opening system DLL -- any ideas?

Posted: Mon Jul 28, 2003 10:06 pm
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"...

Posted: Wed Jul 30, 2003 12:05 am
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

Yes

Posted: Wed Jul 30, 2003 1:05 am
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...

Re: Error opening system DLL -- any ideas?

Posted: Sun Jul 20, 2008 2:15 pm
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.

Posted: Mon Jul 21, 2008 4:45 pm
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) 

Posted: Mon Jul 21, 2008 9:50 pm
by PB
Thanks ABBKlaus! :) I'm getting too old for this stuff.