Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

NetMessageBufferSend (netapi32)
 
.
Summary
TODO - a short description

C# Signature:

[DllImport("netapi32.dll")]
static extern int NetMessageBufferSend(
    [MarshalAs(UnmanagedType.LPWStr)] string servername,
    [MarshalAs(UnmanagedType.LPWStr)] string msgname,
    [MarshalAs(UnmanagedType.LPWStr)] string fromname,
    [MarshalAs(UnmanagedType.LPWStr)] string buf,
    int buflen);

VB Signature:

Declare Function NetMessageBufferSend Lib "netapi32.dll" (TODO) As TODO

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

The Alerter service must be running for NetMessageBufferSend to function.

Sample Code:

C# Example code

This is a simple console program which lets you send messages (quite similar to the NET SEND command...).

Usage
sendnetmsg.exe srcName dstName message

For example you can use the name of your machine as srcName and dstName and the message will be sent to yourself https://www.pinvoke.net/emoticons/regular_smile.gif

using System;
using System.Runtime.InteropServices;

public class SendNetMsg
{
    const int NERR_Success         = 0;
    const int NERR_BASE        = 2100;
    const int NERR_NameNotFound    = (NERR_BASE+173); // The message alias could not be found on the network.
    const int NERR_NetworkError    = (NERR_BASE+36);  // A general network error occurred.
    const int ERROR_ACCESS_DENIED      = 5;
    const int ERROR_INVALID_PARAMETER  = 87;
    const int ERROR_NOT_SUPPORTED      = 50;

    [DllImport("netapi32.dll")]
    public static extern int NetMessageBufferSend(
        [MarshalAs(UnmanagedType.LPWStr)] string servername,
        [MarshalAs(UnmanagedType.LPWStr)] string msgname,
        [MarshalAs(UnmanagedType.LPWStr)] string fromname,
        [MarshalAs(UnmanagedType.LPWStr)] string buf,
        int buflen);

    public static void Main (String[] argv)
    {
        if (argv.Length < 3)
        {
        Console.WriteLine ("sendnetmsg.exe srcName dstName msg");
        return;
        }

        int retVal = NetMessageBufferSend (null, argv[1], argv[0], argv[2], argv[2].Length * 2);    

        if (retVal == NERR_NameNotFound)
        Console.WriteLine ("Error: NERR_NameNotFound") ;
        else if (retVal == NERR_NetworkError)
        Console.WriteLine ("Error: NERR_NetworkError") ;
        else if (retVal == ERROR_ACCESS_DENIED)
        Console.WriteLine ("Error: ERROR_ACCESS_DENIED") ;
        else if (retVal == ERROR_INVALID_PARAMETER)
        Console.WriteLine ("Error: ERROR_INVALID_PARAMETER") ;
        else if (retVal == ERROR_NOT_SUPPORTED)
        Console.WriteLine ("Error: ERROR_NOT_SUPPORTED") ;
        else if (retVal != 0)
        Console.WriteLine ("Unknown error returned.\nError code {0}", retVal) ;
    }
}

Alternative Managed API:

Do you know one? Please contribute it!

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions