GetVolumeInformation错误

时间:2012-02-07 01:16:53

标签: c++ c++-cli

所以我收到编译错误,我想要做的是使用GetVolumeInformation序列化驱动器,这对每个人来说都是唯一的。任何帮助将不胜感激。

这是我的代码:

#include "stdafx.h"
#include "Head.h"

using namespace System;
using namespace System::Collections::Generic;
using namespace System::ComponentModel;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Text;
using namespace System::Net;
using namespace System::Net::Sockets;
using namespace System::Windows::Forms;
using namespace System::IO;
using namespace System::Security::Cryptography;
using namespace System::Security::Principal;

namespace SE
{

    String ^Base::GetSerial(String ^strDriveLetter)
    {
        UInt32 serNum = 0;
        UInt32 maxCompLen = 0;
        StringBuilder ^VolLabel = gcnew StringBuilder(256); // Label
        UInt32 VolFlags = UInt32();
        StringBuilder ^FSName = gcnew StringBuilder(256); // File System Name
        strDriveLetter += ":\\"; // fix up the passed-in drive letter for the API call
        bool Ret = GetVolumeInformation(strDriveLetter, VolLabel, safe_cast<UInt32>(VolLabel->Capacity), serNum, maxCompLen, VolFlags, FSName, safe_cast<UInt32>(FSName->Capacity));
        return Convert::ToString(serNum);
    }
}

然后是我的Head.h:

#pragma once

using namespace System;
using namespace System::Collections::Generic;
using namespace System::ComponentModel;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Text;
using namespace System::Net;
using namespace System::Net::Sockets;
using namespace System::Windows::Forms;
using namespace System::IO;
using namespace System::Security::Cryptography;
using namespace System::Security::Principal;

namespace SE
{
    private ref class Base
    {
    private:
        static bool GetVolumeInformation(String ^PathName, StringBuilder ^VolumeNameBuffer, UInt32 VolumeNameSize, UInt32 %VolumeSerialNumber, UInt32 %MaximumComponentLength, UInt32 %FileSystemFlags, StringBuilder ^FileSystemNameBuffer, UInt32 FileSystemNameSize);
    };
}

然而,当我编译时,我得到了:

error LNK2022: metadata operation failed (80131187) : Inconsistent method declarations in duplicated types (types: SE.Base; methods: GetVolumeInformationA): (0x06000008).

我有什么不对吗?感谢

1 个答案:

答案 0 :(得分:0)

我不确定,但我认为问题可能是因为GetVolumeInformation函数是一个静态函数,所以你需要把它称为

    Base::GetVolumeInformation

在函数String ^ Base :: GetSerial中。请试一试,看看它是否有效。