阅读:1747回复:5
测试FREE硬盘空间的程序,显示too many arguments错误,请指教,付源程序
我写了一个测试FREE硬盘空间的程序,总是报错。
显示的错误:error C2197: 'FARPROC' : too many arguments for call through pointer-to-function BOOL GetDiscFreeSpace(LPCTSTR lpszPath, DWORDLONG* pnFree) { BOOL bRet = FALSE; // We need to determine whether GetDiskFreeSpaceEx is available by calling LoadLibrary // or LoadLibraryEx, to load Kernel32.DLL, and then calling the GetProcAddress to // obtain an address for GetDiskFreeSpaceEx. FARPROC lpfnDLLProc = NULL; lpfnDLLProc = GetProcAddress(GetModuleHandle("kernel32.dll"), "GetDiskFreeSpaceExA"); if(lpfnDLLProc) // If we got an address to the function { ULARGE_INTEGER nTotalBytes, nTotalFreeBytes, nTotalAvailable; lpfnDLLProc(lpszPath, &nTotalAvailable, &nTotalBytes, &nTotalFreeBytes); *pnFree = nTotalAvailable.QuadPart; bRet = TRUE; } if(!bRet) // We have to try and use GetDiskFreeSpace() { ULONG secpercluster, bytespersec, nooffreeclusters, totalnoofclusters; GetDiskFreeSpace(lpszPath, &secpercluster, &bytespersec,&nooffreeclusters, &totalnoofclusters); *pnFree = (nooffreeclusters * secpercluster * bytespersec); bRet = TRUE; } return bRet; } |
|
沙发#
发布于:2004-12-08 12:55
应该使用这种方法引用函数
http://www.driverdevelop.com/forum/viewthread.php?tid=82029 |
|
|
板凳#
发布于:2004-12-08 17:12
没有用的,我在.NET的VC++下面编译通过不了.GetProcAddress本身就是FARPROC型的.强制转换不了.
|
|
地板#
发布于:2004-12-08 18:08
没有用的,我在.NET的VC++下面编译通过不了.GetProcAddress本身就是FARPROC型的.强制转换不了. 谁说的? #include <windows.h> typedef BOOL (*LPGETDISKFREESPACEEXA)( LPCTSTR, // directory name PULARGE_INTEGER, // bytes available to caller PULARGE_INTEGER, // bytes on disk PULARGE_INTEGER// free bytes on disk ); BOOL GetDiscFreeSpace(LPCTSTR lpszPath, DWORDLONG* pnFree) { BOOL bRet = FALSE; // We need to determine whether GetDiskFreeSpaceEx is available by calling LoadLibrary // or LoadLibraryEx, to load Kernel32.DLL, and then calling the GetProcAddress to // obtain an address for GetDiskFreeSpaceEx. LPGETDISKFREESPACEEXA lpfnDLLProc = NULL; lpfnDLLProc = (LPGETDISKFREESPACEEXA)GetProcAddress(GetModuleHandle("kernel32.dll"), "GetDiskFreeSpaceExA"); if(lpfnDLLProc) // If we got an address to the function { ULARGE_INTEGER nTotalBytes, nTotalFreeBytes, nTotalAvailable; lpfnDLLProc(lpszPath, &nTotalAvailable, &nTotalBytes, &nTotalFreeBytes); *pnFree = nTotalAvailable.QuadPart; bRet = TRUE; } if(!bRet) // We have to try and use GetDiskFreeSpace() { ULONG secpercluster, bytespersec, nooffreeclusters, totalnoofclusters; GetDiskFreeSpace(lpszPath, &secpercluster, &bytespersec,&nooffreeclusters, &totalnoofclusters); *pnFree = (nooffreeclusters * secpercluster * bytespersec); bRet = TRUE; } return bRet; } void main() { DWORDLONG dlSize=0; GetDiscFreeSpace(NULL,&dlSize); } |
|
|
地下室#
发布于:2004-12-08 18:09
在vc6.0下编译通过,没装.net应该可以的
|
|
|
5楼#
发布于:2004-12-09 19:51
在NET上编译过不了,*pnFree = nTotalAvailable.QuadPart;出错。我修改了pnFree为__int64也过不了。报错:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention. 前面的那个倒是没有问题的了。谢谢。请问您知道硬盘的扇区怎么读写吗,在WIN32下面。 |
|