LPCSTR 在 CLR 项目中创建未声明的变量
LPCSTR creates undeclared variable in CLR project
我正在尝试在dll包装器中创建一个c ++函数,该包装器采用char *,将其转换为LPCSTR,然后将其用作MessageBox中的变量。该函数和转换在原始类中工作正常,但是当我尝试在 CLR 项目中使用该函数时,使用 LPCSTR 变量出现未声明标识符错误。
空项目类标头:
#pragma once
#include <stdexcept>
using namespace std;
class StringPass {
public:
void stringPass(char *inbound);
};
空项目类.cpp文件:
#pragma once
#include "NewPrototypes.h"
#include <Windows.h>
void StringPass::stringPass(char *inbound)
{
LPCSTR inBound = inbound;
MessageBox(NULL, TEXT(inBound), TEXT("Succesful Test"), MB_OK);
}
当我将其作为独立项目运行时,它可以完美运行。
CLR 项目标头:
#pragma once
#include "C:UsersRyanDocumentsVisual Studio 2010ProjectsNewProtoClassNewProtoClassNewPrototypes.h"
#include "C:UsersRyanDocumentsVisual Studio 2010ProjectsNewProtoClassNewProtoClassNewPrototypes.cpp"
using namespace System;
namespace NewPrototypesDll {
public ref class StringPassWrapper
{
public:
StringPassWrapper();
void stringPassWrapper(char *inbound);
private:
StringPass *stringPassClass;
// TODO: Add your methods for this class here.
};
}
CLR 项目.cpp文件:
#include "stdafx.h"
#include "NewPrototypesDll.h"
#include "C:UsersRyanDocumentsVisual Studio 2010ProjectsNewProtoClassNewProtoClassNewPrototypes.h"
#include "C:UsersRyanDocumentsVisual Studio 2010ProjectsNewProtoClassNewProtoClassNewPrototypes.cpp"
NewPrototypesDll::StringPassWrapper::StringPassWrapper()
{
stringPassClass = new StringPass();
}
void NewPrototypesDll::StringPassWrapper::stringPassWrapper(char *inbound)
{
stringPassClass->stringPass(inbound);
}
当我尝试构建DLL文件时,出现错误:
1>C:UsersRyanDocumentsVisual Studio 2010ProjectsNewProtoClassNewProtoClassNewPrototypes.cpp(11): error C2065: 'LinBound' : undeclared identifier
我已经尝试了所有方法,我已经将 windows.h 添加到项目中,但此错误不断弹出。是的,我已经查看了有关未声明标识符错误的其他问题,但没有一个是我的情况所独有的,并且没有一个解决方案有效。为什么它在项目的第一部分有效,而在另一部分不起作用?
TEXT() 用于文字,而不是变量。请注意,错误消息显示"LinBound"——TEXT 在 Unicode 模式下在其参数的前面添加一个 L,而 CLR 处于 Unicode 模式。直接调用 MessageBoxA,或使用 MultiByteToWideChar 转换为 Unicode。
相关文章:
- 对类 (C++) 中的私有变量使用未声明的标识符
- 未声明的标识符错误,但变量定义正确 (?)
- 奇怪的未声明变量编译器错误
- 为什么我可以在 C++ 的可变 lambda 中捕获未声明的变量
- 运行时错误,使用未声明的变量,C++
- 在此范围C 中未声明字符串和char变量
- 错误:非静态数据成员的使用无效,在此范围内未声明变量
- 创建二次公式求解器-范围中未声明的变量
- 在Visual C++中,未声明的变量未标记为错误
- 动态变量上的c++MACRO未声明标识符
- C++向量练习未声明的变量
- 在此作用域中未声明条件变量函数
- 在类范围中未声明的标题中声明的变量
- 编译器说传递的变量是未声明的
- 未在构造函数的默认构造对象中声明变量
- 函数调用c++中未声明的变量
- 未在此范围中声明变量-Mingw w64
- 未在此范围内声明变量gcc错误
- 稍后在程序中使用if-else构造内部声明的变量会导致未声明的标识符错误
- 类中未声明变量成员函数