为什么我得到'CA2W':找不到标识符
for(DWORD i = 0; i < numMaterials; i++) // for each material...
{
material[i] = tempMaterials[i].MatD3D; // get the material info
material[i].Ambient = material[i].Diffuse; // make ambient the same as diffuse
USES_CONVERSION; // allows certain string conversions
// if there is a texture to load, load it
D3DXCreateTextureFromFile(d3ddev,
CA2W(tempMaterials[i].pTextureFilename),
&texture[i]);
texture[i] = NULL; // if there is no texture, set the texture to NULL
}
发布于 2010-10-10 13:17:06
编辑:
OP刚刚告诉我Visual Studio2010学习版是用来编译代码的。这就解释了为什么找不到CA2W
,因为Express版本没有包含整个ATL/MFC库。因此,我最初的回答与OP无关。
这个故事的寓意是:在问这些问题时,一定要准确地提到你所处的环境。
您可以不使用CA2W
,而是使用MultiByteToWideChar()
-此函数实际上是CA2W
用来转换字符串的函数,因此您将得到基本相同的结果。
Here's a usage example of MultiByteToWideChar()
in an answer to another Stack overflow question。它用于从std::string
到LPCWSTR
的转换,但它基本上是相同的过程。
原始答案:
根据the documentation for ATL and MFC String Conversion Macros的说法,你必须包括:
#include <atlbase.h>
#include <atlconv.h>
int main()
{
// Explicitly qualified the CA2W identifier
ATL::CA2W("Hello World!"); // Test to see if this compiles
}
我认为这段代码之前不能工作的原因是因为你在#include <atlbase.h>
之前的某个地方#define
'd _ATL_NO_AUTOMATIC_NAMESPACE
。
发布于 2010-10-10 12:17:22
给我们看你的代码,否则我们无能为力。
你得到的错误是:“CA2W到底是什么?”
这意味着您正在使用标识符CA2W,但尚未将其声明为任何内容。
发布于 2010-10-10 12:47:25
因此,尝试这样做-创建一个Win32控制台项目,然后用下面的代码替换给定的代码,它对我来说编译得很好。如果这不能为你编译,我被难住了--也许重新安装Visual Studio?似乎有多个人可以正确地编译它,那么您的Visual Studio安装可能出了什么问题?
// testconv.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <atlconv.h>
#include <atlbase.h>
#include <atlstr.h>
int _tmain(int argc, _TCHAR* argv[])
{
USES_CONVERSION;
WCHAR *pChar = CA2W(NULL);
return 0;
}
https://stackoverflow.com/questions/3898999
复制相似问题