偶用来给局域网的终端发送消息的
如果终端没有开机,或不存在会返回什么消息?

解决方案 »

  1.   

    如何使用WinNT/Win2000的信史服务给别人发信息呢?用一个API就可以搞定!-NET_API_STATUS NetMessageBufferSend( LPWSTR servername,                                      LPWSTR msgname,                                     LPWSTR fromname,                                      LPBYTE buf,                                      DWORD buflen );     看看MSDN,可能还是有些地方不明白。尤其是第一个参数,其实它不是你发信息的目标计算机名,而是执行此函数的计算机名。第二个参数才是你发信息的目标计算机名。还有buf这个参数,MSDN里写的是LPBYTE型,很含糊,实际上这也是要Unicode码的。而最后那个buflen又是buf所占的字节数,如Unicode编码的"hello"占字节数是10。    写个小例子吧。#include <windows.h>
    #include <lm.h>
    #include <lmmsg.h>#pragma comment(lib,"netapi32.lib")int main()
    {
    WCHAR msg[]=L"hello.";         //所发的信息
    WCHAR serv[]=L"nowcan-do-it";  //目标计算机名,如果要给一个工作组广播消息,要在工作组名后面加个"*",如"workgroup*"
    WCHAR from[]=L"NowCan";        //你的名字,可以是NULL(这时默认用你的登陆名)
    NetMessageBufferSend(NULL,serv,from,(unsigned char *)msg,14);
    return 0;
    }
    或者#define _UNICODE  //程序全部使用Unicode
    #define UNICODE#include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <wchar.h>
    #include <windows.h>
    #include <locale.h>
    #include <lm.h>#pragma comment(lib,"netapi32.lib")int wmain(int argc, wchar_t *argv[])//这里是个问题,我用BCB怎么也无法链接,说 [Linker Error] Unresolved external '_main' referenced from C:\PROGRAM FILES\BORLAND\CBUILDER5\LIB\C0X32.OBJ,我一直不知道怎么解决,谁有解决方案可要告诉我。
    {
    wchar_t *wtarget, *wfrom, *buffer;
    DWORD dwReturn;
    if(argc < 4)
    {
    printf("Usge: MsgSend <Target> <From> <Message>");
    return 0;
    }
    wtarget = argv[1];
    wfrom = argv[2];
    buffer = argv[3];dwReturn = NetMessageBufferSend(NULL, wtarget, wfrom, (LPBYTE)buffer, 2*lstrlen(buffer));//注意这里要对得出的长度乘2才是字节数,否则是字符数(一个Unicode字符占2字节)
    if(dwReturn == NERR_Success)
    {
    printf("Send Success!");
    }
    else 
    {
    printf("Error!");
    }
    return 0;
    }
        还有一个小问题,你知道怎么得到Unicode吗?用AnsiString的一些成员函数--WideChar打头的函数都是与Unicode相关的。-*-*-PATCH-*-*-    上面那个wmain的问题已经得到解答。直接用命令行bcc32,如下。bcc32 -WU -WC netmsg.cpp-WU 指定使用Unicode-WC 指定为控制台应用程序-*-*-PATCH-*-*-
      

  2.   

    Private Declare Function NetMessageBufferSend Lib "NETAPI32.DLL" (Server As Any, yToName As Byte,
    yFromName As Any, yMsg As Byte, ByVal lSize As Long) As Long
      

  3.   

    Private Declare Function NetMessageBufferSend Lib _
      "NETAPI32.DLL" (yServer As Any, yToName As Byte, _
      yFromName As Any, yMsg As Byte, ByVal lSize As Long) As Long
    Private Const NERR_Success As Long = 0&
    Public Function SendMessage(RcptToUser As String, _
       FromUser As String, BodyMessage As String) As Boolean
     
       Dim RcptTo() As Byte
       Dim From() As Byte
       Dim Body() As Byte   RcptTo = RcptToUser & vbNullChar
       From = FromUser & vbNullChar
       Body = BodyMessage & vbNullChar   If NetMessageBufferSend(ByVal 0&, RcptTo(0), ByVal 0&, _
            Body(0), UBound(Body)) = NERR_Success Then
         SendMessage = True
       End IfEnd Function
    Private Sub Form_Load()    Dim RetVal As Boolean
        RetVal = SendMessage("目标机器名", "本机器名", "消息")
    End Sub
      

  4.   

    http://www.csdn.net/cnshare/soft/16/16015.shtm
      

  5.   

    sworddx(.:RNPA:. 剑宇潇湘·秋叶原) 的回复下了我一跳,我以为我机器出了什么毛病,跑到C语言这里来了!汗~~~~~~~~~~~~~