1. Larry Peters
  2. PowerBuilder
  3. Monday, 13 May 2024 10:45 AM UTC

A year ago I raised this issue but never did get any resolution. I'd like to test the community's patience by revisiting it.

Simply put, ReportEvent crashes when built in 64bit but works fine when built in 32bit. My sample code demonstrates this.

Any feedback is welcome as I can find nothing to help me past this impasse.

 

forward
global type w_eventlog from window
end type
type cb_1 from commandbutton within w_eventlog
end type
end forward

global type w_eventlog from window
integer width = 658
integer height = 348
boolean titlebar = true
string title = "Test Event Log"
boolean controlmenu = true
boolean minbox = true
boolean maxbox = true
boolean resizable = true
long backcolor = 67108864
string icon = "AppIcon!"
boolean center = true
cb_1 cb_1
end type
global w_eventlog w_eventlog

type prototypes
FUNCTION longptr RegisterEventSource (longptr lpUNCServerName, string lpSourceName) Library "advapi32.dll" Alias For "RegisterEventSourceW"
FUNCTION boolean ReportEvent (longptr hEventLog, uint wType, uint wCategory, ulong dwEventID, ulong lpUserSid, uint wNumStrings, ulong dwDataSize, string lpStrings[], ulong lpRawData) Library "advapi32.dll" Alias For "ReportEventW"
FUNCTION boolean DeregisterEventSource (ref longptr hEventLog) Library "advapi32.dll"
end prototypes

on w_eventlog.create
this.cb_1=create cb_1
this.Control[]={this.cb_1}
end on

on w_eventlog.destroy
destroy(this.cb_1)
end on

type cb_1 from commandbutton within w_eventlog
integer x = 96
integer y = 60
integer width = 402
integer height = 112
integer taborder = 10
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
string text = "Log Event"
end type

event clicked;integer li_type, li_category, li_NumStrings
string ls_event = "Test Log"
string ls_array[]
ulong lul_binsz, lul_bindata, lul_identifier, lul_SecId
longptr lptr_handle

li_NumStrings = 1
ls_array[1] = "Event Log Entry for : " + ls_event

lptr_handle = RegisterEventSource(0, ls_event)
IF IsNull(lptr_handle) THEN lptr_handle = -1
IF lptr_handle > 0 THEN
ReportEvent(lptr_handle, li_type, li_category, lul_identifier, &
lul_SecId, li_NumStrings, lul_binsz, ls_array, lul_bindata)
DeregisterEventSource(lptr_handle)
END IF
end event

 

Accepted Answer
Roland Smith Accepted Answer Pending Moderation
  1. Monday, 13 May 2024 13:57 PM UTC
  2. PowerBuilder
  3. # Permalink

I just tested the following in 64-bit and it works.

First, save this to a .reg file and change MyAppName to the name of your application. Double-click the file to apply to the registry.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Application\MyAppName]
"EventMessageFile"="%SystemRoot%\\System32\\wshext.dll"
"TypesSupported"=dword:0000001f

Then add the following external function declarations to an object:

Function longptr RegisterEventSource ( &
	longptr lpUNCServerName, &
	string lpSourceName &
	) Library "advapi32.dll" Alias For "RegisterEventSourceW"

Function boolean ReportEvent ( &
	longptr hEventLog, &
	uint wType, &
	uint wCategory, &
	ulong dwEventID, &
	longptr lpUserSid, &
	uint wNumStrings, &
	ulong dwDataSize, &
	string lpStrings[], &
	longptr lpRawData &
	) Library "advapi32.dll" Alias For "ReportEventW"

Function boolean DeregisterEventSource ( &
	longptr hEventLog &
	) Library "advapi32.dll"

Then add this function to the object (change MyAppName to match the registry entry above):

public subroutine writetoeventlog (icon eventtype, readonly string messagetext);// -----------------------------------------------------------------------------
// SCRIPT:     WriteToEventLog
//
// PURPOSE:    This function writes a message to the event log.
//
// DATE        PROG/ID		DESCRIPTION OF CHANGE / REASON
// ----------  --------		-----------------------------------------------------
// 03/23/2024	RolandS		Initial coding
// -----------------------------------------------------------------------------

Constant UInt EVENTLOG_SUCCESS          = 0 // Success event
Constant UInt EVENTLOG_ERROR_TYPE       = 1 // Error event
Constant UInt EVENTLOG_WARNING_TYPE     = 2 // Warning event
Constant UInt EVENTLOG_INFORMATION_TYPE	= 4 // Information event
Constant LongPtr NULL = 0

LongPtr llp_hEventLog
String ls_MessageText[]
UInt lui_EventType

choose case EventType
	case Information!
		lui_EventType = EVENTLOG_INFORMATION_TYPE
	case StopSign!
		lui_EventType = EVENTLOG_ERROR_TYPE
	case Exclamation!
		lui_EventType = EVENTLOG_WARNING_TYPE
	case Question!
		lui_EventType = EVENTLOG_ERROR_TYPE
	case None!
		lui_EventType = EVENTLOG_INFORMATION_TYPE
end choose

ls_MessageText[1] = MessageText

llp_hEventLog = RegisterEventSource(NULL, "MyAppName")
If Not llp_hEventLog = NULL Then
	ReportEvent(llp_hEventLog, lui_EventType, &
			0, 0, 0, 1, 0, ls_MessageText, 0)
	DeregisterEventSource(llp_hEventLog)
End If

end subroutine

Now you can call it like this:

WriteToEventLog(StopSign!, "Processing failed!")

 

Comment
  1. Arnd Schmidt
  2. Monday, 13 May 2024 14:13 PM UTC
Great stuff, Roland!
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Monday, 13 May 2024 11:53 AM UTC
  2. PowerBuilder
  3. # 1

Hi, Larry -

The purpose of the Q&A forum is to provide a means of asking questions about Appeon products and receiving advice from other members of the Community. Most of the responders here are not affiliated with Appeon. I cannot emphasize the following enough: This is not a Support portal. You may not have received resolution to your earlier post about this issue because it would appear that this is likely a technical support problem.

If you require Technical Support for any Appeon product to resolve a problem, my advice to you is to open a (free!) bug ticket so that the problem can be properly tracked and analyzed by Appeon. Here's the link to do so:

    https://www.appeon.com/standardsupport/newbug

Best regards, John

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Monday, 13 May 2024 13:44 PM UTC
  2. PowerBuilder
  3. # 2

Hi Larry ... John's advise is correct 

Comment
There are no comments made yet.
Larry Peters Accepted Answer Pending Moderation
  1. Monday, 13 May 2024 20:18 PM UTC
  2. PowerBuilder
  3. # 3

Wow Roland! Thanks a million! It's early morning so I'll try it out later today. Thanks again.

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.