Today, I saw the article on which I have programmed a write-to-spot network issuance information, it is the function of NET Send, and the main part is the NetMessageBuffersend () function in NetApi32.dll, think of yourself. I have always wanted to edit NET Send's procedure. Now I have finally hoped huh, I use an inverted way, first write a good program, then slowly analyze #include
#pragma comment (Lib, "Netapi32.lib")
// # Define unicode # define maxlen 256
INT Main (int Argc, char * argv []) {// wsadata 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 = netMessageBuffersnd (Server, Toname, NULL, MSG, Maxlen);}} (rc! = NERR_SUCCESS) {Printf ("NMBS () returned% lu / n", rc); Return 1;} printf ("/ n done./N"); return 0;
}
Ok, let's talk about the most depressed, see NetMessageBuffersnd () MSDN information, saying that it is to use the header file lmmsg.h to add this, it is 3 mistakes, all in lmmsg.h, It took a long time, and later took all the code, it was still that three mistakes, it seems not my problem, then turn it back to a program with that function, see the header of his use. Is LM.H. I have learned, that three mistakes are not, I can introduce 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 type mismatch error ,, ,, WCHAR do not use it? Winnt.h
#ifndef _MACtypedef wchar_t WCHAR; // wc, 16-bit UNICODE character # else // some Macintosh compilers do not define wchar_t in a convenient location, or define it as a chartypedef unsigned short WCHAR; // wc, 16-bit UNICODE Character # endif // --------------------------------- ------------ stdio.h
#ifndef _MAC # ifndef _wchar_t_definedTypedEf unsigned short wchar_t; #define_wchar_t_defined # Endif
It seems that Wchar_T should be the same as Wchar, I tried it, and two have nothing wrong, then I used to previous? ? 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 In this way, do '/ 0' can not be converted with MBSTOWCS ()?
The NET Send command only needs to give the host name or IP to be sent. It does not need to indicate the username on the host to be sent, and NetMessageBuffersend must be pointed out, and its username must also be specified, and if it is true The existing user, sends the current username when null..