注册 登录
编程论坛 C++教室

自学API的遇到的问题

JackyZhang 发布于 2011-03-27 22:03, 872 次点击
下面是书上的代码,为什么用vs2010编译通不过?
#include<Windows.h>
#include<stdlib.h>
#include<stdio.h>
#define BUFSIZE 1024
BOOL GetDirverInfo(LPSTR szDrive);
void main(void)
{
    CHAR szLogicalDriveStrings[BUFSIZE];
    PCHAR szDrive;
    ZeroMemory(szLogicalDriveStrings,BUFSIZE);
    GetLogicalDriveStrings(BUFSIZE-1,szLogicalDriveStrings);
    szDrive=(PCHAR)szLogicalDriveStrings;
    do
    {
        if(!GetDirverInfo(szDrive))
        {
            printf("\nGet Volume Information Error:%d",GetLastError());

        }
        szDrive +=(lstrlen(szDrive)+1);
    }
    while(*szDrive!='\x00');
}




错误提示:

1>------ 已启动全部重新生成: 项目: getdriverstring, 配置: Debug Win32 ------
1>生成启动时间为 2011/3/27 21:54:39。
1>_PrepareForClean:
1>  正在删除文件“Debug\getdriverstring.lastbuildstate”。
1>InitializeBuildStatus:
1>  正在对“Debug\getdriverstring.unsuccessfulbuild”执行 Touch 任务。
1>ClCompile:
1>  main.cpp
1>main.obj : error LNK2019: 无法解析的外部符号 "int __cdecl GetDirverInfo(char *)" (?GetDirverInfo@@YAHPAD@Z),该符号在函数 _main 中被引用
1>E:\Visual Studio 2010\Projects\getdriverstring\Debug\getdriverstring.exe : fatal error LNK1120: 1 个无法解析的外部命令
1>
1>生成失败。
1>
1>已用时间 00:00:02.25
========== 全部重新生成: 成功 0 个,失败 1 个,跳过 0 个 ==========
2 回复
#2
yuccn2011-03-28 09:26
那个函数是自定义的。
网上找到一段代码,不知是否合适你
BOOL GetDirverInfo(LPSTR szDrive)
{
        UINT uDriveType;
        DWORD dwVolumeSerialNumber;
        DWORD dwMaximumComponentLength;
        DWORD dwFileSystemFlags;
        CHAR szFileSystemNameBuffer[BUFSIZE];
        CHAR szDirveName[MAX_PATH];
        printf("\n%s\n",szDrive);
        uDriveType = GetDriveType(szDrive);
        switch(uDriveType)
        {
        case DRIVE_UNKNOWN:
                printf("The drive type cannot be determined. ");
                break;
        case DRIVE_NO_ROOT_DIR:
                printf("The root path is invalid, for example, no volume is mounted at the path. ");
                break;
        case DRIVE_REMOVABLE:
                printf("The drive is a type that has removable media, for example, a floppy drive or removable hard disk. ");
                break;
        case DRIVE_FIXED:
                printf("The drive is a type that cannot be removed, for example, a fixed hard drive. ");
                break;
        case DRIVE_REMOTE:
                printf("The drive is a remote (network) drive. ");
                break;
        case DRIVE_CDROM:
                printf("The drive is a CD-ROM drive. ");
                break;
        case DRIVE_RAMDISK:
                printf("The drive is a RAM disk. ");
                break;
        default:
                break;
        }
        if (!GetVolumeInformation(
                szDrive,
                szDirveName,
                MAX_PATH,
                &dwVolumeSerialNumber,
                &dwMaximumComponentLength,
                &dwFileSystemFlags,
                szFileSystemNameBuffer,
                BUFSIZE
                ))
        {
                return FALSE;
        }
        if(0!=lstrlen(szDirveName))
        {
                printf ("\nDrive Name is %s\n",szDirveName);
        }

        printf ("\nVolume Serial Number is %u",dwVolumeSerialNumber);
        printf ("\nMaximum Component Length is %u",dwMaximumComponentLength);
        printf ("\nSystem Type is %s\n",szFileSystemNameBuffer);

        if(dwFileSystemFlags & FILE_SUPPORTS_REPARSE_POINTS)
        {
                printf ("The file system does not support volume mount points.\n");
        }
        if(dwFileSystemFlags & FILE_VOLUME_QUOTAS)
        {
                printf ("The file system supports disk quotas.\n");
        }
        if(dwFileSystemFlags & FILE_CASE_SENSITIVE_SEARCH)
        {
                printf ("The file system supports case-sensitive file names.\n");
        }



        printf("...\n");
        return TRUE;
}
#3
_Unsolved2011-03-28 18:31
你这个是工程配置问题....检查一下工程设置里该包含的库包含了没有
1