我想存储从命令行传递到我的程序中的参数,然后将它们转发给一个函数,它需要所有的字符串都是wchar_t数据格式。在下面的程序中,我已经对函数进行了注释,并使用printf来测试程序,但下面的函数并没有工作。问题出在哪里。
int main(int argc, TCHAR* argv[])
{
TCHAR* cp_UserName[MAX_PATH];
TCHAR* cp_DomainName[MAX_PATH];
TCHAR* cp_HashNtlm[MAX_PATH];
TCHAR* cp_ComputerName[MAX_PATH];
DnPthIconSetup();
DnPthInitialization(TRUE);
int counter = argc;
if (argc > 4)
{
for (size_t i = 1; i < argc; i++)
{
if (!_tcsnccmp(argv[i], L"user:", 5))
{
*cp_UserName = _tcschr(argv[i], L':') + 1;
}
if (!_tcsnccmp(argv[i], L"domain:", 7))
{
*cp_DomainName = _tcschr(argv[i], L':') + 1;
}
if (!_tcsnccmp(argv[i], L"pc:", 3))
{
*cp_ComputerName = _tcschr(argv[i], L':') + 1;
}
if (!_tcsnccmp(argv[i], L"ntlm:", 5))
{
*cp_HashNtlm = _tcschr(argv[i], L':') + 1;
}
}
wprintf("%s\n", *cp_UserName);
wprintf("%s\n", *cp_DomainName);
wprintf("%s\n", *cp_ComputerName);
wprintf("%s\n", *cp_HashNtlm);
system("PAUSE");
// ParametricCredentialDispatcher(cp_UserName, cp_DomainName, cp_HashNtlm, cp_ComputerName);
}
else if (argc == 1)
{
InteractiveMode();
}
else
{
printf("\nUsage: ./program user:[] domain:[] pc:[] ntlm:[]\n");
system("PAUSE");
}
return 0;
}
试试像这样的程序吧。
int wmain(int argc, wchar_t* argv[])
{
wchar_t* cp_UserName = NULL;
wchar_t* cp_DomainName = NULL;
wchar_t* cp_HashNtlm = NULL;
wchar_t* cp_ComputerName = NULL;
DnPthIconSetup();
DnPthInitialization(TRUE);
int counter = argc;
if (argc > 4)
{
for (size_t i = 1; i < argc; i++)
{
if (!wcsncmp(argv[i], L"user:", 5))
{
cp_UserName = argv[i] + 5;
}
else if (!wcsncmp(argv[i], L"domain:", 7))
{
cp_DomainName = argv[i] + 7;
}
else if (!wcsncmp(argv[i], L"pc:", 3))
{
cp_ComputerName = argv[i] + 3;
}
else if (!wcsncmp(argv[i], L"ntlm:", 5))
{
cp_HashNtlm = argv[i] + 5;
}
}
wprintf(L"%s\n", cp_UserName);
wprintf(L"%s\n", cp_DomainName);
wprintf(L"%s\n", cp_ComputerName);
wprintf(L"%s\n", cp_HashNtlm);
system("PAUSE");
// ParametricCredentialDispatcher(cp_UserName, cp_DomainName, cp_HashNtlm, cp_ComputerName);
}
else if (argc == 1)
{
InteractiveMode();
}
else
{
wprintf(L"\nUsage: ./program user:[] domain:[] pc:[] ntlm:[]\n");
system("PAUSE");
}
return 0;
}
这是一个指针数组
TCHAR* cp_UserName[MAX_PATH];
我肯定你指的是一个字符数组,也就是所谓的
TCHAR cp_UserName[MAX_PATH];