NULL pointer given, Win32API

Hi all,

Windows XP
Ruby 1.8.1

How do I pass a straight-up string to a function in the Win32API? I
understand how to pad a buffer store a value in a buffer, but not how to
convert a Ruby string to an LPCTSTR, for example. I’m guessing that I
pack’d it wrong.

require "Win32API"
module Win32
CloseEventLog = Win32API.new(“advapi32”,“CloseEventLog”,“p”,“i”)

OpenEventLog  = Win32API.new("advapi32","OpenEventLog","pp","p")
class EventLog
	def initialize(source,machine=0)
		lpSource = [source].pack("p")
		unless 0 == machine
			lpMachine = [machine].pack("p")
		end
		@h = OpenEventLog.call(source,machine)
		return @h
	end
	
	def close
		CloseEventLog.call(@h)
	end
end

end

if $0 == FILE
e = EventLog.new(“Application”) # results in "NULL pointer given"
e.close
end

This is part of an effort to provide pure-ruby versions of the
win32utils code. Please help.

Regards,

Dan

Hi,

OpenEventLog = Win32API.new(“advapi32”,“OpenEventLog”,“pp”,“p”)

def initialize(source,machine=0)

@h = OpenEventLog.call(source,machine)

It seems that the parameters of the API are passed in wrong order.

HANDLE OpenEventLog(
LPCTSTR lpUNCServerName, // pointer to server name
LPCTSTR lpSourceName // pointer to source name
);

e = EventLog.new(“Application”) # results in “NULL pointer given”

I don’t know why this error message is claimed, although it is
certain that the message claims for a return value of zero.
Needless to say, zero means a failure of API call because of
wrong ordered parameters.

The work-around of this problem is to declare ‘HANDLE’ as “l” or “i”
instead of “p”.

But, I think there should be more reasonable solution.

···

On Thu, 15 Jan 2004 10:27:50 -0600 “Berger, Daniel” djberge@qwest.com wrote:


Shusaku tsyk@yk.rim.or.jp