zoukankan      html  css  js  c++  java
  • 使用变参函数实现pwd命令

    #include "stdafx.h"
    #include <Windows.h>

    #define DIRNAME_LEN (MAX_PATH+2)

    BOOL PrintStrings(HANDLE hOut,...)
    {
      DWORD msgLen,count;
      LPCTSTR pMsg;
      va_list pMsgList;
      va_start(pMsgList,hOut);

      while((pMsg=va_arg(pMsgList,LPCTSTR))!=NULL){
        msgLen=_tcslen(pMsg);
      if(!WriteConsole(hOut,pMsg,msgLen,&count,NULL)
        && !WriteFile(hOut,pMsg,msgLen * sizeof(TCHAR),
        &count,NULL))
      va_end(pMsgList);
      return FALSE;
    }
      va_end(pMsgList);
      return TRUE;
    }
    BOOL PrintMsg(HANDLE hOut,LPCTSTR pMsg){
      return PrintStrings(hOut,pMsg,NULL);
    }

    int _tmain(int argc, LPTSTR argv[])
    {
      CHAR pwdBuffer[DIRNAME_LEN];
      DWORD lenCurDir;

      lenCurDir=GetCurrentDirectory(DIRNAME_LEN,pwdBuffer);
      PrintMsg(GetStdHandle(STD_OUTPUT_HANDLE),pwdBuffer);

      system("pause");
      return 0;

    }

  • 相关阅读:
    记一次MD5妙用
    go执行外部应用
    Go语言中的HTTP
    Go语言中的UDP应用
    Go学习
    Element-ui学习使用
    Vue学习
    BootCDNApi使用记录
    jquery.easypiechart.js简介
    jquery.gritter.js简介
  • 原文地址:https://www.cnblogs.com/duyy/p/3603524.html
Copyright © 2011-2022 走看看