我也再搞这个问题,我前3个全用null,后面是指针和长度,为什么 编译报告link error?

解决方案 »

  1.   

    rujor(rujor):
    如果你已经做了,就当我没说:)
    Import Library: Use netapi32.libbtw:NetMessageBufferSend我的没用过
      

  2.   

    我搞到一个源程序
    #include <windows.h>
    #include <lm.h>
    #include <stdio.h>
    #include <stdlib.h>
    #pragma hdrstop
    #pragma comment( lib, "netapi32.lib" )#define MAXLEN 256void enum_names( const wchar_t *server );int main( int argc, char *argv[] )
    {
    DWORD rc;
    wchar_t server[MAXLEN], name[MAXLEN], from[MAXLEN], msg[MAXLEN]; if ( argc != 5 && argc != 2 )
    {
    puts( "\nusage: nmbs \\\\server message-name from-name \"message\"" );
    puts( "       nmbs \\\\server\n" );
    puts( "First form: Sends the message to the <message-name> alias on <server>." );
    puts( "       Use whatever you like as <fromname>." );
    puts( "Second form: Lists <message-name>s on <server>. Note that not all of" );
    puts( "       them may work." ); return 1;
    } mbstowcs( server, argv[1], MAXLEN );
    server[MAXLEN - 1] = L'\0'; if ( argc == 2 )
    {
    enum_names( server );
    }
    else
    {
    mbstowcs( name, argv[2], MAXLEN );
    name[MAXLEN - 1] = L'\0';
    mbstowcs( from, argv[3], MAXLEN );
    from[MAXLEN - 1] = L'\0';
    mbstowcs( msg, argv[4], MAXLEN );
    msg[MAXLEN - 1] = L'\0'; printf( "\nTrying ... " );
    rc = NetMessageBufferSend( server, name, from, (LPBYTE *) &msg[0], wcslen( msg ) * 2 ); if ( rc != NERR_Success )
    {
    printf( "NMBS() returned %lu\n", rc );
    return 1;
    } puts( "Done." );
    } return 0;
    }void enum_names( const wchar_t *server )
    {
    MSG_INFO_1 *buf, *cur;
    DWORD read, total, resumeh, rc, i; printf( "\nAvailable message-names on server %S:\n", server );
    resumeh = 0;
    do
    {
    buf = NULL;
    rc = NetMessageNameEnum( server, 1, (BYTE **) &buf,
    512, &read, &total, &resumeh );
    if ( rc != ERROR_MORE_DATA && rc != ERROR_SUCCESS )
    break; for ( i = 0, cur = buf; i < read; ++ i, ++ cur )
    {
    // Note: the capital S in the format string will expect Unicode
    // strings, as this is a program written/compiled for ANSI.
    printf( "%S\n", cur->msgi1_name );
    } if ( buf != NULL )
    NetApiBufferFree( buf ); } while ( rc == ERROR_MORE_DATA ); if ( rc != ERROR_SUCCESS )
    printf( "NMNE() returned %lu\n", rc );
    }
              
      

  3.   


    Private Const NERR_Success As Long = 0&
    Private Declare Function NetMessageBufferSend Lib "NETAPI32.DLL" (Server As Any, yToName As Byte, yFromName As Any, yMsg As Byte,ByVal lSize As Long) As LongPublic Function Sendmsg(strTo As String, strFrom As String,strMessage As String) As Boolean
    Dim bytTo() As Byte
    Dim bytFrom() As Byte
    Dim bytMsg() As Byte
    bytTo = strTo & vbNullChar
    bytName = strFrom & vbNullChar
    bytMsg = strMessage & vbNullChar
    Sendmsg = (NetMessageBufferSend(ByVal 0&, yToName(0),ByVal 0&, yMsg(0), UBound(yMsg)) = NERR_Success)
    End Function