⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nspinstall.cpp

📁 《Windows网络编程技术》附书源码源码. 运行环境:9x/Me/NT/2000/XP/ 源码语言:简体中文 第十四章
💻 CPP
字号:
// Module: nspinstall.c
//
// Description:
//    This program install and removes our custom namespace
//    provider (mynsp.dll). This is done via the WSCInstallNameSpace
//    and WSCUninstallNameSpace functions.
//
// Compile:
//    cl nspinstall.c ws2_32.lib
//
// Command Line Arguments/Parameters
//    nspinstall.exe install|remove
//
#define UNICODE
#define _UNICODE

#include <winsock2.h>
#include <ws2spi.h>

#include <stdlib.h>
#include <stdio.h>

#include "mynsp.h"

//
// Function: usage
//
// Description:
//    Print usage information.
//
void usage(char *progname)
{
    printf("usage: %s install | remove\n", progname);
    ExitProcess(-1);
}

//
// Function: main
//
// Description:
//    This function parses the command line and executes the
//    appropriate command - either install or remove our name
//    space provider.
//
int main(int argc, char **argv)
{
    WSADATA        wsd;
    char          *ptr; 
    int            ret;

    // Check for the appropriate number of arguments.
    //
    if (argc != 2)
    {
        usage(argv[0]);
        return -1;
    }
    if (WSAStartup(MAKEWORD(2,2), &wsd) != 0)
    {
        printf("WSAStartup() failed: %d\n", GetLastError());
        return -1;
    }
    // Convert any arguments to lower case
    //
    ptr = argv[1];
    while (*ptr)
        *ptr++ = tolower(*ptr);
    //
    // Install the name space provider
    //
    if (!strncmp(argv[1], "install", 6))
    {
        // Pnstall the provider
        //
        ret = WSCInstallNameSpace(L"Custom Name Space Provider",
                L"%SystemRoot%\\System32\\mynsp.dll", NS_MYNSP, 1, &MY_NAMESPACE_GUID);
        if (ret == SOCKET_ERROR)
        {
            printf("Failed to install name space provider: %d\n",
                WSAGetLastError());
        }
        else
        {
            printf("Successfully installed name space provider\n");
        }
    }
    // Remove the name space provider
    //
    else if (!strncmp(argv[1], "remove", 6))
    {
        ret = WSCUnInstallNameSpace(&MY_NAMESPACE_GUID);
        if (ret == SOCKET_ERROR)
        {
            printf("Failed to remove provider: %d\n", WSAGetLastError());
        }
        else
        {
            printf("Successfully removed name space provider\n");
        }
    }
    else
    {
        usage(argv[0]);
    }

    WSACleanup();
    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -