ExamineLibrary : Invalid Access Memory

Windows specific forum
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

ExamineLibrary : Invalid Access Memory

Post by Flype »

On WinXP, if i try to parse the functions of this dll, PB crash...

Code: Select all

If OpenLibrary(0, "msw3prt.dll")
  
  If ExamineLibraryFunctions(0)
    
    While NextLibraryFunction()
      
      func$ = LibraryFunctionName() : Debug func$
      
    Wend
    
  EndIf
  
  CloseLibrary(0)
  
EndIf
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

Post by walker »

Strange... crashes here on Closelibrary()..
but with a delay(1) before the CloseLibrary() all runs well :?

Code: Select all

If OpenLibrary(0, "msw3prt.dll")
  If ExamineLibraryFunctions(0)
    While NextLibraryFunction()
      func$ = LibraryFunctionName() : Debug func$
    Wend
  EndIf
 Delay(1)
CloseLibrary(0)
 
EndIf
Btw.: @Fred: IMHO should the CloseLibrary() command contain the number of the opened Library like CloseLibrary(0) to be conform with all other PB-Commands.. :?:
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

just tried with PB3.94 - exactly the same behaviour.
maybe it's the dll itself that is strange (?)

@walker
agree, i was also thinking of this.

NextLibraryFunction(#library)
LibraryFunctionName(#library)
LibraryFunctionAddress(#library)

to be more consistent and safer...
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

From the help file:
Syntax

CloseLibrary(#Library)
As the NextLibraryFunction(), LibraryFunctionName() and LibraryFunctionAddress() are all subordinate to the ExamineLibraryFunctions(#Library) command, repeating it for them would be redundant typing. The other Examine... command that takes a parameter also treats its subordinate commands this way - ExamineDirectory(#Directory)... followed by NextDirectoryEntry() etc.
BERESHEIT
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

not really netmaestro.

now NextDirectoryEntry() is NextDirectoryEntry(#Directory)

and when ExamineLibraryFunctions() is called from multiples threads what's happened ? There might be a conflict. But those are really rare cases... I never be myself in such case...
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Fred
Administrator
Administrator
Posts: 18360
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

This function rely on very lowlevel access, so if there is something corrupted in the dll, the function will probably crash :?.
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

does it crash for you to with this windows built-in dll ?

is it normal that the OnErrorGosub doesn't catch it ?

Code: Select all

Procedure ErrorHandler()
  MessageRequester("Crash","Crash")
EndProcedure

OnErrorGosub(@ErrorHandler())

If OpenLibrary(0, "msw3prt.dll")
  If ExamineLibraryFunctions(0)
    While NextLibraryFunction()
      func$ = LibraryFunctionName() : Debug func$
    Wend
  EndIf
  CloseLibrary(0)
EndIf
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Fred
Administrator
Administrator
Posts: 18360
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

I looked closely to this problem and it seems to be the fault of the DLL as even an API only PB code crash:

Code: Select all

a = LoadLibrary_("msw3prt.dll")
If a
  FreeLibrary_(a)
  MessageBox_(0, "ok", "", 0)
EndIf
It crashes after the display of the MessageBox(). To be sure it wasn't a PureBasic problem, i tested it in VisualC++ 2005 with the following code, and it keeps crashing.

Code: Select all

#include <Windows.h>


int main(int argc, TCHAR* argv[])
{
  HMODULE a = LoadLibrary("msw3prt.dll");
  if (a)
  {
    FreeLibrary(a);
    MessageBox(NULL, "ok", "", MB_ICONINFORMATION);
  }

  return 0;
}
My guess is the library has something wrong in its freeing code, may be it should be reported to Microsoft, as it's very unlikely to be a coding fault here ;).
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

hi fred, yes you are right.
it works as i said before with a Delay(1) before freeing the library (initializations delay ?), so in a real use there's no problem.

win32 code, tested ok.

Code: Select all

#include "Windows.h"

int _tmain(int argc, TCHAR* argv[])
{
  HMODULE a = LoadLibrary("msw3prt.dll");
  
  if (a)
  {
	  Sleep(1);
	  FreeLibrary(a);
	  MessageBox(NULL, "ok", "", MB_ICONINFORMATION);
  }

  return 0;
}
api pb code, tested ok.

Code: Select all

a = LoadLibrary_("msw3prt.dll")
If a
  Sleep_(1)
  FreeLibrary_(a)
  MessageBox_(0, "ok", "", 0)
EndIf
pb only, tested ok.

Code: Select all

If OpenLibrary(0,"msw3prt.dll")
  Delay(1)
  CloseLibrary(0)
  MessageRequester("", "ok")
EndIf
So, no purebasic bug here.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Post Reply