Page 1 of 1

OnErrorCall inside DLL

Posted: Fri Aug 14, 2020 3:21 pm
by ALAN-MHz
I know exist some posts already, but cannot find the right solution, i have a simple example code:

Code: Select all

Declare ErrorHandler()

ProcedureDLL AttachProcess ( Instance )
 OnErrorCall ( @ErrorHandler () )
 RaiseError(#PB_OnError_InvalidMemory)
 MessageRequester("3","4")
 ProcedureReturn #true
EndProcedure

ProcedureDLL DetachProcess ( Instance )
 ProcedureReturn #true
EndProcedure

ProcedureDLL AttachThread ( Instance )
 ProcedureReturn #true
EndProcedure

ProcedureDLL DetachThread ( Instance )
 ProcedureReturn #true
EndProcedure
  
ProcedureDLL DllInitialize ()
 ProcedureReturn #true
EndProcedure

Procedure ErrorHandler ()
 MessageRequester("1","2")
EndProcedure
If i compile this source as dll and call from an external program (openlibrary) i cannot see any messagerequester, what's wrong ?

Re: OnErrorCall inside DLL

Posted: Sun Dec 13, 2020 9:20 am
by juergenkulow
Hello ALAN-MHz,

Code: Select all

; Call ProcedureDLL AttachProcess
CompilerIf #PB_Compiler_Debugger 
  CompilerError "Compiler Optionen Debugger out."
CompilerEndIf
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
  DLLFile$="AttachProcess.dll" 
CompilerCase #PB_OS_Linux
  DLLFile$="/mnt/AttachProcess.so" ; Please adjust.  
CompilerCase #PB_OS_MacOS
  DLLFile$="AttachProcess.dylib" 
CompilerEndSelect
If OpenLibrary(0, DLLFile$) 
  CallFunction(0, "AttachProcess")
  CloseLibrary(0)
Else 
  MessageRequester("Error", "Missing File:"+DLLFile$)
EndIf

Code: Select all

CompilerIf #PB_Compiler_Debugger Or #PB_Compiler_ExecutableFormat<>#PB_Compiler_DLL
  CompilerError "Compiler Optionen Debugger out and Exeformat DLL/so/dylib"
CompilerEndIf

Declare ErrorHandler()

ProcedureDLL AttachProcess ( Instance )
 OnErrorCall ( @ErrorHandler () )
 RaiseError(#PB_OnError_InvalidMemory)
 MessageRequester("3","4")
 ProcedureReturn #True
EndProcedure

Procedure ErrorHandler ()
  Datei=OpenFile(#PB_Any,"ErrorFile.txt",#PB_File_Append)
  WriteStringN(Datei," ProcedureDLL AttachProcess Line:"+ErrorLine()+" "+ErrorMessage())
  CloseFile(Datei)
  MessageRequester("Error","ProcedureDLL AttachProcess Line:"+ErrorLine()+" "+ErrorMessage())
  ; End ; [08:30:24] [COMPILER] Zeile 19: The following command can't be used in a DLL: End.
  ;The ErrorHandler should terminate the program.
EndProcedure  

; ProcedureDLL AttachProcess Line:9 Segmentation violation