1

我试图从这个答案中放入类 NativeBuffer但是当 windows.storage.streams.h 我有很多错误,比如:

Error   1   error C2872: 'AsyncStatus' : ambiguous symbol   c:\program files (x86)\windows phone kits\8.0\include\abi\asyncinfo.h   75
Error   2   error C2872: 'AsyncStatus' : ambiguous symbol   c:\program files (x86)\windows phone kits\8.0\include\abi\asyncinfo.h   76
Error   3   error C2872: 'AsyncStatus' : ambiguous symbol   c:\program files (x86)\windows phone kits\8.0\include\abi\asyncinfo.h   77
Error   4   error C2872: 'AsyncStatus' : ambiguous symbol   c:\program files (x86)\windows phone kits\8.0\include\abi\asyncinfo.h   78
Error   5   error C2371: 'IAsyncInfo' : redefinition; different basic types c:\program files (x86)\windows phone kits\8.0\include\abi\asyncinfo.h   108
Error   6   error C2872: 'AsyncStatus' : ambiguous symbol   c:\program files (x86)\windows phone kits\8.0\include\abi\asyncinfo.h   115
Error   7   error C2872: 'EventRegistrationToken' : ambiguous symbol    c:\program files (x86)\windows phone kits\8.0\include\abi\windows.foundation.collections.h  1185
Error   8   error C2872: 'EventRegistrationToken' : ambiguous symbol    c:\program files (x86)\windows phone kits\8.0\include\abi\windows.foundation.collections.h  1186
Error   9   error C2872: 'EventRegistrationToken' : ambiguous symbol    c:\program files (x86)\windows phone kits\8.0\include\abi\windows.foundation.collections.h  1224
Error   10  error C2872: 'EventRegistrationToken' : ambiguous symbol    c:\program files (x86)\windows phone kits\8.0\include\abi\windows.foundation.collections.h  1225
Error   11  error C3431: 'PropertyType' : a scoped enumeration cannot be redeclared as an unscoped enumeration  c:\program files (x86)\windows phone kits\8.0\include\abi\windows.foundation.h  3984
Error   12  error C2371: 'ABI::Windows::Foundation::PropertyType' : redefinition; different basic types c:\program files (x86)\windows phone kits\8.0\include\abi\windows.foundation.h  15298
Error   13  error C2872: 'EventRegistrationToken' : ambiguous symbol    c:\program files (x86)\windows phone kits\8.0\include\abi\windows.storage.search.h  4005
Error   14  error C2872: 'EventRegistrationToken' : ambiguous symbol    c:\program files (x86)\windows phone kits\8.0\include\abi\windows.storage.search.h  4008
Error   15  error C2872: 'EventRegistrationToken' : ambiguous symbol    c:\program files (x86)\windows phone kits\8.0\include\abi\windows.storage.search.h  4012
Error   16  error C2872: 'EventRegistrationToken' : ambiguous symbol    c:\program files (x86)\windows phone kits\8.0\include\abi\windows.storage.search.h  4015
Error   17  error C2872: 'EventRegistrationToken' : ambiguous symbol    c:\program files (x86)\windows phone kits\8.0\include\abi\windows.storage.h 10488
Error   18  error C2872: 'EventRegistrationToken' : ambiguous symbol    c:\program files (x86)\windows phone kits\8.0\include\abi\windows.storage.h 10491
Error   19  error C2039: 'RuntimeClass' : is not a member of 'Microsoft::WRL'   c:\users\sergey.fedortsov\documents\socialholdem\prj.ipoker\wp8\shared\platform\wp\nativebuffer.h   12
Error   20  error C2504: 'RuntimeClass' : base class undefined  c:\users\sergey.fedortsov\documents\socialholdem\prj.ipoker\wp8\shared\platform\wp\nativebuffer.h   12
Error   21  error C2143: syntax error : missing ',' before '<'  c:\users\sergey.fedortsov\documents\socialholdem\prj.ipoker\wp8\shared\platform\wp\nativebuffer.h   12
Error   22  error C2039: 'RuntimeClassFlags' : is not a member of 'Microsoft::WRL'  c:\users\sergey.fedortsov\documents\socialholdem\prj.ipoker\wp8\shared\platform\wp\nativebuffer.h   13
Error   23  error C3083: 'RuntimeClassType': the symbol to the left of a '::' must be a type    c:\users\sergey.fedortsov\documents\socialholdem\prj.ipoker\wp8\shared\platform\wp\nativebuffer.h   13
Error   24  error C2039: 'WinRtClassicComMix' : is not a member of 'Microsoft::WRL' c:\users\sergey.fedortsov\documents\socialholdem\prj.ipoker\wp8\shared\platform\wp\nativebuffer.h   13
Error   25  error C2039: 'FtmBase' : is not a member of 'Microsoft::WRL'    c:\users\sergey.fedortsov\documents\socialholdem\prj.ipoker\wp8\shared\platform\wp\nativebuffer.h   16

我的代码:

    #ifndef NATIVE_BUFFER_H
#define NATIVE_BUFFER_H


#include <robuffer.h>
#include <wrl.h>
#include <wrl/implements.h>
#include <wrl\client.h>
#include <windows.storage.streams.h>


/// <summary>
/// The purpose of this class is to transform byte buffers into an IBuffer
/// </summary>
class NativeBuffer : public Microsoft::WRL::RuntimeClass<
    Microsoft::WRL::RuntimeClassFlags< Microsoft::WRL::RuntimeClassType::WinRtClassicComMix >,
    ABI::Windows::Storage::Streams::IBuffer,
    Windows::Storage::Streams::IBufferByteAccess,
    Microsoft::WRL::FtmBase>
{

public:
    virtual ~NativeBuffer()
    {
        if (m_pBuffer && m_bIsOwner)
        {
            delete[] m_pBuffer;
            m_pBuffer = NULL;
        }
    }

    STDMETHODIMP RuntimeClassInitialize(UINT totalSize)
    {
        m_uLength = totalSize;
        m_uFullSize = totalSize;
        m_pBuffer = new BYTE[totalSize];
        m_bIsOwner = TRUE;
        return S_OK;
    }

    STDMETHODIMP RuntimeClassInitialize(BYTE* pBuffer, UINT totalSize, BOOL fTakeOwnershipOfPassedInBuffer)
    {
        m_uLength = totalSize;
        m_uFullSize = totalSize;
        m_pBuffer = pBuffer;
        m_bIsOwner = fTakeOwnershipOfPassedInBuffer;
        return S_OK;
    }

    STDMETHODIMP Buffer( BYTE **value)
    {
        *value = m_pBuffer;
        return S_OK;
    }

    STDMETHODIMP get_Capacity(UINT32 *value)
    {
        *value = m_uFullSize;
        return S_OK;
    }

    STDMETHODIMP get_Length(UINT32 *value)
    {
        *value = m_uLength;
        return S_OK;
    }

    STDMETHODIMP put_Length(UINT32 value)
    {
        if(value > m_uFullSize)
        {
            return E_INVALIDARG;
        }
        m_uLength = value;
        return S_OK;
    }

    static Windows::Storage::Streams::IBuffer^ GetIBufferFromNativeBuffer(Microsoft::WRL::ComPtr<NativeBuffer> spNativeBuffer)
    {
        auto iinspectable = reinterpret_cast<IInspectable*>(spNativeBuffer.Get());
        return reinterpret_cast<Windows::Storage::Streams::IBuffer^>(iinspectable);
    }
    static BYTE* GetBytesFromIBuffer(Windows::Storage::Streams::IBuffer^ buffer)
    {
        auto iinspectable = (IInspectable*)reinterpret_cast<IInspectable*>(buffer);
        Microsoft::WRL::ComPtr<Windows::Storage::Streams::IBufferByteAccess> spBuffAccess;
        HRESULT hr = iinspectable->QueryInterface(__uuidof(Windows::Storage::Streams::IBufferByteAccess), (void **)&spBuffAccess);
        UCHAR * pReadBuffer;
        spBuffAccess->Buffer(&pReadBuffer);
        return pReadBuffer;
    }
private:
    UINT32 m_uLength;
    UINT32 m_uFullSize;
    BYTE* m_pBuffer;
    BOOL m_bIsOwner;
};


#endif

这可能是什么原因?

4

1 回答 1

5

最可能的原因是您using namespace在头文件中!

例如。

// Header
using namespace System;
using namespace std;

// Your class declaration

从标头中删除所有名称空间包含。使用明确的类包含,例如

using System::Int32;
using std::vector;

由于您将此标头包含在其他标头中,然后包含标准标头 - 所有内容都进入(或被视为)全局名称空间。它引起了歧义。您不能更改标准标头(通过前缀::或其他命名空间)。

于 2013-04-02T17:26:19.670 回答