Re: A couple of NetApi questions.


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Re: A couple of NetApi questions.

Hybrid View

  1. #1
    Joe \Nuke Me Xemu\ Foster Guest

    Re: A couple of NetApi questions.

    "Mark Alexander Bertenshaw" <mark.bertenshaw@virgin.net> wrote in message <news:3d778b94$1@10.1.10.29>...

    > I have been writing a little utility which sends and catches those pop up
    > boxes you get in Win NT/2000 when some NET SENDs you. (The latter is done
    > by periodically doing FindWindowEx() where class is "#32770" and window text
    > is "Messenger Service ", and retrieving the text in the static control.).
    > To send messages, I use NetMessageBufferSend(). This works fine, but only
    > if I use vbNullString for servername and fromname. I would ideally like to
    > be able to a more useful name than my machine, but if I set fromname to
    > anything else, the function fails. Does anyone know how to do this?
    >
    > I have looked on the internet for clues on how to do this, but it seems that
    > the same solution is being used by everyone - and it doesn't seem to work.
    > For some reason, the Declare is:
    >
    > Private Declare Function NetMessageBufferSend Lib "NetApi32.dll" ( _
    > Byval servername As String, _
    > Byval msgname As String, _
    > ByVal fromname As String, _
    > ByVal buf As String _
    > ByVal buflen As Long _
    > ) As Long
    >
    > And when called, all the string parameters are passed as
    > StrConv(stringvalue, vbUnicode).


    I take it NetMessageBufferSend expects Unicode strings? The StrConv
    must be to defeat VB's automatic Unicode-to-ASCII conversions when
    calling into "ordinary" DLLs. I usually wrap such things in a small
    Sub or Function which passes strings using ByVal StrPtr(mystring) to
    ByRef As Any parameters and then attempts to convert Err.LastDllError
    codes to VB-ish errors. Who in their right mind wants to deal with
    the equivalent of K&R C's errno all the time?

    > After messing unsuccessfully with this for a couple of hours, I declared it
    > in a typelib, and it worked fine.


    Which worked fine, calling the typelib NetMessageBufferSend with or
    without overriding servername and fromname?

    --
    Joe Foster <mailto:jlfoster%40znet.com> Got Thetans? <http://www.xenu.net/>
    WARNING: I cannot be held responsible for the above They're coming to
    because my cats have apparently learned to type. take me away, ha ha!



  2. #2
    Mark Alexander Bertenshaw Guest

    Re: A couple of NetApi questions.

    "Joe "Nuke Me Xemu" Foster" <joe@bftsi0.UUCP> wrote in message
    news:3d77c038@10.1.10.29...

    Hi Joe -

    > > I have looked on the internet for clues on how to do this, but it seems

    that
    > > the same solution is being used by everyone - and it doesn't seem to

    work.
    > > For some reason, the Declare is:
    > >
    > > Private Declare Function NetMessageBufferSend Lib "NetApi32.dll" ( _
    > > Byval servername As String, _
    > > Byval msgname As String, _
    > > ByVal fromname As String, _
    > > ByVal buf As String _
    > > ByVal buflen As Long _
    > > ) As Long
    > >
    > > And when called, all the string parameters are passed as
    > > StrConv(stringvalue, vbUnicode).

    >
    > I take it NetMessageBufferSend expects Unicode strings?


    Yes - the whole API is Unicode-only.

    > The StrConv
    > must be to defeat VB's automatic Unicode-to-ASCII conversions when
    > calling into "ordinary" DLLs.


    Kind of. But I think this would only work in countries which use the
    default ANSI code page.

    > I usually wrap such things in a small
    > Sub or Function which passes strings using ByVal StrPtr(mystring) to
    > ByRef As Any parameters and then attempts to convert Err.LastDllError
    > codes to VB-ish errors. Who in their right mind wants to deal with
    > the equivalent of K&R C's errno all the time?


    Yeah - I now realise that ByVal StrPtr(mystring) would have been a lot
    simpler. But I don't get your reference to Err.LastDLLError - surely this
    would work regardless of what way you attempted to execute the API function?

    > > After messing unsuccessfully with this for a couple of hours, I declared

    it
    > > in a typelib, and it worked fine.

    >
    > Which worked fine, calling the typelib NetMessageBufferSend with or
    > without overriding servername and fromname?


    Using the typelib definition AND setting servernam = vbNullString, fromname
    = vbNullString. Servername is not that important, but I still want to be
    able to use a non-null fromname.

    --
    Mark Alexander Bertenshaw
    Programmer/Analyst
    Chordiant Software, Inc.
    Brentford
    UK




  3. #3
    Joe \Nuke Me Xemu\ Foster Guest

    Re: A couple of NetApi questions.

    "Mark Alexander Bertenshaw" <mark.bertenshaw@virgin.net> wrote in message <news:3d7885fe$1@10.1.10.29>...

    > "Joe "Nuke Me Xemu" Foster" <joe@bftsi0.UUCP> wrote in message
    > news:3d77c038@10.1.10.29...
    >
    > Hi Joe -
    >
    > > > I have looked on the internet for clues on how to do this, but it seems

    > that
    > > > the same solution is being used by everyone - and it doesn't seem to

    > work.
    > > > For some reason, the Declare is:
    > > >
    > > > Private Declare Function NetMessageBufferSend Lib "NetApi32.dll" ( _
    > > > Byval servername As String, _
    > > > Byval msgname As String, _
    > > > ByVal fromname As String, _
    > > > ByVal buf As String _
    > > > ByVal buflen As Long _
    > > > ) As Long
    > > >
    > > > And when called, all the string parameters are passed as
    > > > StrConv(stringvalue, vbUnicode).

    > >
    > > I take it NetMessageBufferSend expects Unicode strings?

    >
    > Yes - the whole API is Unicode-only.
    >
    > > The StrConv
    > > must be to defeat VB's automatic Unicode-to-ASCII conversions when
    > > calling into "ordinary" DLLs.

    >
    > Kind of. But I think this would only work in countries which use the
    > default ANSI code page.


    Has anyone told Randy?

    URL:http://mvps.org/vbnet/index.html?cod...buffersend.htm

    > > I usually wrap such things in a small
    > > Sub or Function which passes strings using ByVal StrPtr(mystring) to
    > > ByRef As Any parameters and then attempts to convert Err.LastDllError
    > > codes to VB-ish errors. Who in their right mind wants to deal with
    > > the equivalent of K&R C's errno all the time?

    >
    > Yeah - I now realise that ByVal StrPtr(mystring) would have been a lot
    > simpler. But I don't get your reference to Err.LastDLLError - surely this
    > would work regardless of what way you attempted to execute the API function?


    Yeah, but the wrapper will be the only thing that has to monkey
    with LastDllError. "errno" by any other name smells just as bad.

    > > > After messing unsuccessfully with this for a couple of hours, I declared

    > it
    > > > in a typelib, and it worked fine.

    > >
    > > Which worked fine, calling the typelib NetMessageBufferSend with or
    > > without overriding servername and fromname?

    >
    > Using the typelib definition AND setting servernam = vbNullString, fromname
    > = vbNullString. Servername is not that important, but I still want to be
    > able to use a non-null fromname.


    Start with Randy's code, then clean it up until it breaks?

    Here's another way, using byte arrays to avoid stepping in Unicrap:

    URL:http://internettrash.com/users/fdb/broadcas.htm

    --
    Joe Foster <mailto:jlfoster%40znet.com> DC8s in Spaace: <http://www.xenu.net/>
    WARNING: I cannot be held responsible for the above They're coming to
    because my cats have apparently learned to type. take me away, ha ha!



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center