Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/128.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
LPCSTR在CLR项目中创建未声明的变量 我试图在一个DLL包装中创建一个C++函数,它将字符转换为LPCSTR,然后将其用作消息框中的变量。该函数和转换在原始类中工作正常,但当我尝试在CLR项目中使用该函数时,LPCSTR变量出现未声明的标识符错误_C++ - Fatal编程技术网

LPCSTR在CLR项目中创建未声明的变量 我试图在一个DLL包装中创建一个C++函数,它将字符转换为LPCSTR,然后将其用作消息框中的变量。该函数和转换在原始类中工作正常,但当我尝试在CLR项目中使用该函数时,LPCSTR变量出现未声明的标识符错误

LPCSTR在CLR项目中创建未声明的变量 我试图在一个DLL包装中创建一个C++函数,它将字符转换为LPCSTR,然后将其用作消息框中的变量。该函数和转换在原始类中工作正常,但当我尝试在CLR项目中使用该函数时,LPCSTR变量出现未声明的标识符错误,c++,C++,空项目类标题: #pragma once #include <stdexcept> using namespace std; class StringPass { public: void stringPass(char *inbound); }; CLR project.cpp文件: #pragma once #include "NewPrototypes.h" #include <Windows.h> void StringPass::stri

空项目类标题:

#pragma once

#include <stdexcept>
using namespace std;

class StringPass {
public:

    void stringPass(char *inbound);

};
CLR project.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);
}
#include "stdafx.h"

#include "NewPrototypesDll.h"

#include "C:\Users\Ryan\Documents\Visual Studio 2010\Projects\NewProtoClass\NewProtoClass\NewPrototypes.h"
#include "C:\Users\Ryan\Documents\Visual Studio 2010\Projects\NewProtoClass\NewProtoClass\NewPrototypes.cpp"

NewPrototypesDll::StringPassWrapper::StringPassWrapper()
{
    stringPassClass = new StringPass();
}

void NewPrototypesDll::StringPassWrapper::stringPassWrapper(char *inbound)
{
    stringPassClass->stringPass(inbound);
}
当我尝试构建DLL文件时,出现以下错误:

1>C:\Users\Ryan\Documents\Visual Studio 2010\Projects\NewProtoClass\NewProtoClass\NewPrototypes.cpp(11): error C2065: 'LinBound' : undeclared identifier

我已经尝试了一切,我已经将windows.h添加到项目中,但是这个错误不断出现。是的,我已经研究了关于未声明标识符错误的其他问题,但是没有一个是我的情况所独有的,并且没有一个解决方案有效。为什么它在项目的第一部分有效,而在另一部分无效?

TEXT()用于文本,而不是变量。请注意,错误消息显示“LinBound”--文本在Unicode模式下在其参数前面添加一个L,而CLR在Unicode模式下。直接调用MessageBoxA,或者使用MultiByteToWideChar转换为Unicode。

尝试将“\”替换为“\ \”,如
“C:\\Users\Ryan\\\…
。不,这不起作用,如果路径名出现语法问题,我会得到另一个错误。你能给我们看一下你的新原型吗?cpp?是的,第二个代码块关闭了。或者您正在请求“main()”文件?搜索
LinBound
并将其更改为
inBound
。似乎您错误地编写了
LinBound
。MessageBoxA产生了相同的错误,但我得到了所需的答案。与代码不兼容。我将寻找一种绕过它的方法,或者另一种方法来完成我的项目。谢谢。您是否也删除了变量名周围的TEXT()?这就是编译器错误的来源。你的意思是只放置变量?是的,我试过了,我得到了这个错误:C:\\Users\\Ryan\\Documents\\Visual Studio 2010\\Projects\\NewProtoClass\\NewProtoClass\\NewPrototype.cpp(11):错误C2664:“MessageBox”:无法将参数2从“LPCSTR”转换为“LPCTSTR”1>指向的类型不相关;转换需要重新解释_cast、C样式cast或函数样式cast。要解决这个问题,我必须在消息框A的两个文本参数上使用变量,谢谢您的帮助。它构建了DLL。
1>C:\Users\Ryan\Documents\Visual Studio 2010\Projects\NewProtoClass\NewProtoClass\NewPrototypes.cpp(11): error C2065: 'LinBound' : undeclared identifier