我有這樣的代碼我不有Windows體驗:在kernel32.dll中Windows錯誤的參數類型C編程
:
#include <windows.h>
#include <stdio.h>
typedef BOOL (WINAPI *P_GDFSE)(LPCTSTR, PULARGE_INTEGER,
PULARGE_INTEGER, PULARGE_INTEGER);
void main (int argc, char **argv)
{
BOOL fResult;
char *pszDrive = NULL,
szDrive[4];
DWORD dwSectPerClust,
dwBytesPerSect,
dwFreeClusters,
dwTotalClusters;
P_GDFSE pGetDiskFreeSpaceEx = NULL;
unsigned __int64 i64FreeBytesToCaller,
i64TotalBytes,
i64FreeBytes;
if (argc != 2)
{
printf ("usage: %s <drive|UNC path>\n", argv[0]);
printf ("\texample: %s C:\\\n", argv[0]);
return;
}
pszDrive = argv[1];
if (pszDrive[1] == ':')
{
szDrive[0] = pszDrive[0];
szDrive[1] = ':';
szDrive[2] = '\\';
szDrive[3] = '\0';
pszDrive = szDrive;
}
// FIRST ERROR kernel32.dll
pGetDiskFreeSpaceEx = (P_GDFSE)GetProcAddress (
GetModuleHandle ("kernel32.dll"),
"GetDiskFreeSpaceExA");
// SECOND ERROR pszDrive
if (pGetDiskFreeSpaceEx)
{
fResult = pGetDiskFreeSpaceEx (pszDrive,
(PULARGE_INTEGER)&i64FreeBytesToCaller,
(PULARGE_INTEGER)&i64TotalBytes,
(PULARGE_INTEGER)&i64FreeBytes);
if (fResult)
{
printf ("\n\nGetDiskFreeSpaceEx reports\n\n");
printf ("Available space to caller = %I64u MB\n",
i64FreeBytesToCaller/(1024*1024));
printf ("Total space = %I64u MB\n",
i64TotalBytes/(1024*1024));
printf ("Free space on drive = %I64u MB\n",
i64FreeBytes/(1024*1024));
}
}
else
{
// ERROR 3 pszDrive
fResult = GetDiskFreeSpace (pszDrive,
&dwSectPerClust,
&dwBytesPerSect,
&dwFreeClusters,
&dwTotalClusters);
if (fResult)
{
/* force 64-bit math */
i64TotalBytes = (__int64)dwTotalClusters * dwSectPerClust *
dwBytesPerSect;
i64FreeBytes = (__int64)dwFreeClusters * dwSectPerClust *
dwBytesPerSect;
printf ("GetDiskFreeSpace reports\n\n");
printf ("Free space = %I64u MB\n",
i64FreeBytes/(1024*1024));
printf ("Total space = %I64u MB\n",
i64TotalBytes/(1024*1024));
}
}
if (!fResult)
printf ("error: %lu: could not get free space for \"%s\"\n",
GetLastError(), argv[1]);
}
我得到這些錯誤(Visual Studio 2010的最終) :
pGetDiskFreeSpaceEx =(P_GDFSE)GetProcAddress的( 的GetModuleHandle( 「KERNEL32.DLL」), 「GetDiskFreeSpaceExA」);
錯誤:類型爲const char *的參數是與類型 「LPCWSTR」
在pszDrive的參數不相容:
fResult = pGetDiskFreeSpaceEx (pszDrive,
(PULARGE_INTEGER)&i64FreeBytesToCaller,
(PULARGE_INTEGER)&i64TotalBytes,
(PULARGE_INTEGER)&i64FreeBytes);
錯誤:char *類型的參數是與類型的參數不相容「LPCTSTR 「
在pszDrive:
fResult = GetDiskFreeSpace (pszDrive,
&dwSectPerClust,
&dwBytesPerSect,
&dwFreeClusters,
&dwTotalClusters);
錯誤:參數
非常感謝
嗨,謝謝它的作品,但沒有L「GetDiskFreeSpaceExW」只是「GetDiskFreeSpaceExW」 –
你說得很對。現在修復。 –