Page 1 of 1

ExamineLibrary : Invalid Access Memory

Posted: Tue Apr 11, 2006 9:12 am
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

Posted: Tue Apr 11, 2006 9:23 am
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.. :?:

Posted: Tue Apr 11, 2006 9:41 am
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...

Posted: Tue Apr 11, 2006 5:28 pm
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.

Posted: Tue Apr 11, 2006 5:50 pm
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...

Posted: Tue Apr 11, 2006 5:57 pm
by Fred
This function rely on very lowlevel access, so if there is something corrupted in the dll, the function will probably crash :?.

Posted: Tue Apr 11, 2006 6:14 pm
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

Posted: Fri Sep 12, 2008 12:19 am
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 ;).

Posted: Sun Nov 02, 2008 1:11 pm
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.