OnErrorCall inside DLL

Just starting out? Need help? Post your questions and find answers here.
ALAN-MHz
User
User
Posts: 68
Joined: Fri Jul 29, 2005 11:47 am

OnErrorCall inside DLL

Post 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 ?
juergenkulow
Enthusiast
Enthusiast
Posts: 555
Joined: Wed Sep 25, 2019 10:18 am

Re: OnErrorCall inside DLL

Post 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
Post Reply