I have a bunch of VB.NET programs that have a general purpose logging function to log events, errors, exceptions, etc. It looks like this:
I wrote a few VB.NET DLLs that contain classes used my my VB.NET programs. In thoses DLL classes, I would like to also trap some events, errors, exceptions, etc. But I want them to be logged using my main LogMe function. Here is some pseudo-code of what I was looking for:Code:Sub LogMe(Msg as string) LstLog.items.add(now.tostring & " " & Msg) End Sub
Code:' Main program code imports MyLib ' Initialize program Private Sub FrmMain() FrmMain.Show FrmMain.LstLog.Clear MyLib.InitCallBack(Address_of_LogMe) End Sub ' Log message to ListBox Sub LogMe(Msg as string) LstLog.items.add(now.tostring & " " & Msg) End SubI assume I will need to define Delegates to save my LogMe fonction pointer, but after a lot of Googling, I was not able to figure out how to code this.Code:' DLL library code Public Module Globals Private PointerLogMe as ??? = nothing ' Initialize Call Back function by main program Public Sub InitCallBack(AddressLogMe as ???) PointerLogMe = AddressLogMe End Sub ' Local logging function that actually does the CallBack to the main program Private Sub LocalLogMe(Msg as string) If not PointerLogMe is nothing Then Call_function_stored_inPointerLogMe_with_Msg_as_a_parameter End if End Sub ... LocalLogMe("An exception was detected in function XXX") ... End Module
Thanks




Reply With Quote