NULL pointer given, Win32API

Discussion in 'Ruby' started by Berger, Daniel, Jan 15, 2004.

  1. 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
     
    Berger, Daniel, Jan 15, 2004
    #1
    1. Advertising

  2. Berger, Daniel

    Shusaku Guest

    Hi,

    On Thu, 15 Jan 2004 10:27:50 -0600
    "Berger, Daniel" <> wrote:

    > 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.

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

    > 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.

    --
    Shusaku <>
     
    Shusaku, Jan 15, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    26,689
    Mike Schilling
    Mar 29, 2006
  2. Lord0
    Replies:
    1
    Views:
    571
    Thomas Weidenfeller
    Apr 19, 2006
  3. aneuryzma
    Replies:
    3
    Views:
    714
    Jim Langston
    Jun 16, 2008
  4. tahir rauf
    Replies:
    12
    Views:
    737
    Keith Thompson
    Apr 30, 2011
  5. Christopher
    Replies:
    4
    Views:
    445
    Ruben Safir
    Jul 9, 2011
Loading...

Share This Page