🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #14511

NetSend Problems

#14511
From: Colin Maharaj
Date: Sat, 09 Aug 2003 12:16
95 lines
3733 bytes
Hi all, 
I wrote a netsend routine (with snippets from previous postings) that
works on my local machine and to another PC on the same domain ONLY but
not to another 2000/XP Pro machine on the same sub-network (not in a
domain)...

BUT if I netsend via command line to the said machine that I am trying
to netsend to via code...I am able to do it successfully..

Is there a way I can do a netsend, via code, to a machine on the same
network (i.e. I can ping it) but not necessarily on the same domain.

Here is the routine i am using..

//-------------------------------------------------------------------------------------------

AnsiString NetSend(const AnsiString & message,
                   const AnsiString & UserFrom ,
                   const AnsiString & UserTo)

{
    AnsiString ErrorStr="";

    typedef DWORD (WINAPI *lpNetMessageBufferSendA)( LPCWSTR,  LPCWSTR, 
LPCWSTR, LPBYTE, DWORD);
    lpNetMessageBufferSendA pNetMessageBufferSend;
    HMODULE hDLL = LoadLibrary ("netapi32");

    if (hDLL == NULL)
    {
       ErrorStr = "NETAPI32.DLL cound not be loaded!!";
       return ErrorStr;
    }

    pNetMessageBufferSend = (lpNetMessageBufferSendA) GetProcAddress
    (hDLL,"NetMessageBufferSend");

    if (pNetMessageBufferSend != NULL)
    {

      WideString wsText2Send = WideString(message);
      DWORD NetErrorCode;

      NetErrorCode = pNetMessageBufferSend(NULL,//WideString("*"),
//NULL,
                      WideString(UserTo), //NULL,
                      WideString(UserFrom),
                      (unsigned char* )wsText2Send.c_bstr(),
                      wsText2Send.Length() * sizeof(wchar_t)
                      );

      switch(NetErrorCode)
      {
          case ERROR_ACCESS_DENIED:
               ErrorStr = "ERROR: You do not have access to the
requested function!";
               break;

          case ERROR_INVALID_PARAMETER:
               ErrorStr = "ERROR: One of the passed parameters is
invalid!";
               break;

          case ERROR_NOT_SUPPORTED:
               ErrorStr = "ERROR: This network request is not
supported!";
               break;

          case NERR_NameNotFound:
               ErrorStr = "The user name could not be found or is not
logged in!";
               break;

          case NERR_NetworkError:
               ErrorStr = "A general failure occurred in the network
hardware!";
               break;

          case NERR_Success:
               break;

          default:
              ErrorStr = "ERROR " + IntToStr(NetErrorCode) + " : Unknown
error!!";

              break;
      }
    }
    FreeLibrary (hDLL);
    if (ErrorStr.Length() > 0)
    {
      ShowMessage ( ErrorStr );
    }
    return ErrorStr;
}
Technical Details
Message-ID: <3F34E601.607325FE@cablenett.net>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-05!sn-xit-08!supernews.com!priapus.visi.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,9f3cb6d07c87c356,start
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-08-09 05:27:35 PST
Message-ID: <3F34E601.607325FE@cablenett.net>
Date: Sat, 09 Aug 2003 08:16:01 -0400
From: Colin Maharaj <cbm@cablenett.net>
Reply-To: cbm@cablenett.net
X-Mailer: Mozilla 4.78 [en] (Windows NT 5.0; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: NetSend Problems
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 196.32.37.75
X-Trace: newsgroups.borland.com 1060431404 196.32.37.75 (9 Aug 2003 05:16:44 -0700)
Lines: 95
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-05!sn-xit-08!supernews.com!priapus.visi.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail