In August 24, net send was finally available.

Source: Internet
Author: User

Today, I saw the article on computer programming skills and maintenance that I programmed to write LAN messages, which is to implement the net send function. The main part is to use netmessagebuffersend () in netapi32.dll () function, thinking that I had always wanted to compile a net send program last semester, now I have finally looked forward to it ,,
In flashback mode, first paste the written program, and then analyze it slowly.
# Include <stdio. h>
# Include <windows. h>
# Include <LM. h>

# Pragma comment (Lib, "netapi32.lib ")

// # Define Unicode
# Define maxlen 256

Int main (INT argc, char * argv [])
{
// Wsadata;
// Wsastartup (makeword (2, 2), & wsadata );
Dword rc;
Int I = 1;
Wchar_t server [maxlen], toname [maxlen], MSG [maxlen];
If (argc! = 4 & argc! = 5 ){
Printf ("/nusage: netsend /// servername tousername/" message/"/N ");
Return 1;
}
Mbstowcs (server, argv [1], maxlen );
Server [MAXLEN-1] = l'/0 ';
Mbstowcs (toname, argv [2], maxlen );
Toname [MAXLEN-1] = l'/0 ';
Mbstowcs (MSG, argv [3], maxlen );
MSG [MAXLEN-1] = l'/0 ';
If (argc = 5) I = atoi (argv [4]);

Printf ("/n here we go.../N ");
While (I --){
Rc = netmessagebuffersend (server, toname, null, MSG, maxlen );
}
If (RC! = Nerr_success)
{
Printf ("NMBS () returned % lu/N", RC );
Return 1;
}
Printf ("/n done./N ");
Return 0;

}

Okay, let's talk about the most depressing part. Read the information in the msdn documentation of netmessagebuffersend () and say that the header file lmmsg is used. after H adds this, there are three errors, all of which are in lmmsg. h Li, I called it for a long time. Later I commented out all the code and the three errors. It seems that it is not my problem ,, later I rummaged through a program using that function on the Internet and saw that he used the header file lm. h. I learned that the three errors are missing. The usage can be described in msdn.
# Define Unicode
# Define mesglen 50
Wchar awctoname [] = text ("domainname *");
Wchar awcfromname [] = text ("mycomputer ");
Wchar awcmesgbuffer [mesglen] = text ("This ia Test message ");
Net_api_status nasstatus;

Nasstatus = netmessagebuffersend (null,
Awctoname,
Awcfromname,
Awcmesgbuffer,
Mesglen );
But an error occurred. The type does not match. Isn't it possible to use wchar?
Winnt. h

# Ifndef _ Mac
Typedef wchar_t wchar; // WC, 16-bit Unicode Character
# Else
// Some Macintosh compilers don't define wchar_t in a convenient location, or define it as a char
Typedef unsigned short wchar; // WC, 16-bit Unicode Character
# Endif
//---------------------------------------------------------
Stdio. h

# Ifndef _ Mac
# Ifndef _ wchar_t_defined
Typedef unsigned short wchar_t;
# DEFINE _ wchar_t_defined
# Endif

It seems that wchar_t should be the same as wchar
I tried it later. There's no problem with both of them, so I used to be ?? Strange

Mbstowcs () is a function that converts ASCII characters into Unicode characters ,,
Mbstowcs (server, argv [1], maxlen );
Server [MAXLEN-1] = L '/0'; --> this sentence has never understood why,'/0' cannot be converted with mbstowcs?

The net send command only needs to provide the host name or IP address to be sent, and does not need to specify the user name on the host to be sent, while netmessagebuffersend must specify ,, the user name must also be specified. If a user exists, if it is null, the current user name is sent ..

In fact, I copied this program completely, but I still don't understand it. I also pay for the program on the Internet. The next step is to use netmessaenameenum () list the users on the machine and send them to all the users on the machine. Next, I want to use the packaging technology to directly simulate net send. I have tried this before ,, unfortunately, Halfway is stuck.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.