我正在尝试链接使用/ MDd标志构建的库(libcef_wrapper_dll.lib).我的应用程序是使用/ MDd和/ CLR构建的,因此应该兼容.该项目编译得很好但是在链接时我得到了下面非常无益的错误:
Error 1 fatal error LNK1318: Unexpected PDB error; OK (0) '' c:\Projects\Cef\CefSharp\libcef_dll_wrapper.lib 1 CefSharp
Run Code Online (Sandbox Code Playgroud)
我没有.LIB的.PDB文件,我需要一个吗?
在C++/CLI项目中,我在本机C++类中有一个方法,我想检查or 的gcroot引用.我该怎么做呢?以下所有内容似乎都不起作用:NULLnullptr
void Foo::doIt(gcroot<System::String^> aString)
{
// This seems straightforward, but does not work
if (aString == nullptr)
{
// compiler error C2088: '==': illegal for struct
}
// Worth a try, but does not work either
if (aString == NULL)
{
// compiler error C2678: binary '==' : no operator found
// which takes a left-hand operand of type 'gcroot<T>'
// (or there is no acceptable conversion)
}
// Desperate, but same result as above …Run Code Online (Sandbox Code Playgroud) 我有使用这样的数组的C++/CLI代码(例如):
array<String^>^ GetColNames() {
vector<string> vec = impl->getColNames();
array<String^>^ arr = gcnew array<String^>(vec.size());
for (int i = 0; i < vec.size(); i++) {
arr[i] = strConvert(vec[i]);
}
return arr;
}
Run Code Online (Sandbox Code Playgroud)
它正在编译,直到我将库"array"添加到项目中:
#include <array>
Run Code Online (Sandbox Code Playgroud)
然后我不知道如何使用托管CLI数组,因为编译器认为所有声明的数组都是std::array.
错误示例:
array<String^>^ arr
// ^ Error here: "too few arguments for class template "std::array""
gcnew array<String^>(vec.size())
// ^ Error: "Expected a type specifier"
Run Code Online (Sandbox Code Playgroud)
怎么解决这个?我尝试using namespace std从该文件中删除,但它没有任何区别.我应该从项目中的每个其他C++文件中删除它吗?
我正在使用C++/CLI项目,该项目在Visual Studio 2012中包装C++本机库.
我的C++/CLI项目有一个AssemblyInfo.cpp.我在那里设置了所有字段,其中包括"AssemblyVersionAttribute".但是,当我在Windows资源管理器中构建项目并检查其属性时,版本信息为空.
这是我的第一个C++/CLI项目,我一直在查看项目属性中的所有选项,但我找不到任何可用于设置版本的选项.
如何设置C++/CLI项目的版本?
更新
我将添加AssemblyInfo.cpp的内容.我刚刚填写了现有的字段,这是在我创建项目时自动生成的.
using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::CompilerServices;
using namespace System::Runtime::InteropServices;
using namespace System::Security::Permissions;
[assembly:AssemblyTitleAttribute("MyTitle")];
[assembly:AssemblyDescriptionAttribute("")];
[assembly:AssemblyConfigurationAttribute("")];
[assembly:AssemblyCompanyAttribute("")];
[assembly:AssemblyProductAttribute("MyProduct")];
[assembly:AssemblyCopyrightAttribute("Copyright © 2014")];
[assembly:AssemblyTrademarkAttribute("Inc")];
[assembly:AssemblyCultureAttribute("")];
[assembly:AssemblyVersionAttribute("3.9.0")];
[assembly:ComVisible(false)];
[assembly:CLSCompliantAttribute(true)];
[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)];
Run Code Online (Sandbox Code Playgroud) 我正在使用Windows 7上的Visual Studio 2015开发一个应用程序.该应用程序有一个C#前端,一个C++ CLR包装器和C++本机代码.
我的应用程序在使用C++本机代码初始化函数作用域的静态变量时因访问冲突而崩溃.但仅限于Windows Server 2003 Enterprise SP2而不是Windows 7或Windows Server 2012.我知道Windows Server 2003不受支持,但我必须将该平台再定位几个月,Visual Studio 2015提供了一个平台工具集来定位它.
我创建了一个可重复的小例子,你可以在最后找到它.
崩溃只发生在涉及的所有三个部分(C#,C++ CLR,C++).如果我删除任何,崩溃就消失了.
崩溃只发生在定义的自定义构造函数上.如果我删除了构造函数,崩溃就消失了.
我不是汇编专家,但对我而言,崩溃是由检查是否需要静态初始化的代码引起的.甚至没有调用构造函数.
我的问题是:为什么它在Windows Server 2003上崩溃?我错过了一些重要的项目设置吗?
Unhandled exception at 0x1000167E (Native.dll) in Managed.exe.dmp: 0xC0000005: Access violation reading location 0x00000000.
Run Code Online (Sandbox Code Playgroud)
// Target framework: .NET Framework 4
// Platform target: x86
using System;
namespace Managed
{
class Program
{
static void Main(string[] args)
{
Console.Write("Press enter to start test...");
Console.ReadLine();
Native.Wrapper wrapper = new Native.Wrapper();
Console.WriteLine("Test was successful");
Console.Write("Press …Run Code Online (Sandbox Code Playgroud) 我们可以使用Visual Studio在C++中定义接口吗?
如果是,那么在C++中定义接口的例子是什么?
首先,我想说清楚一点都是C++的新手,所以这可能是一个简单而且有点明显的问题.在我正在阅读的C++书中,我称之为C++ Primer,一个类是通过编写来定义的:
class classname{
public:
private:
};
Run Code Online (Sandbox Code Playgroud)
但是,在VS2008中,编译器并不喜欢这样.但是在课前添加公共引用,如:
public ref class classname{
Run Code Online (Sandbox Code Playgroud)
它在编译器中经历了.任何人都可以解释只定义类和公共ref类之间的区别是什么?我真的很感激.
在C#中,有三种使用指令:
using System; // Specify Namespace
using Diag = System.Diagnostics; // Specify Namespace Alias
using DBG = System.Diagnostics.Debug; // Specify Class Alias
Run Code Online (Sandbox Code Playgroud)
在C++/CLI中,我知道前两个的等价物:
using namespace System;
namespace Diag = System::Diagnostics;
Run Code Online (Sandbox Code Playgroud)
有没有办法在C++/CLI中做第三个?
做的namespace DBG = System::Diagnostics::Debug;给error C2879: 'System::Diagnostics::Debug' : only an existing namespace can be given an alternative name by a namespace alias definition
我提出的唯一的交替是#define DBG System::Diagnostics::Debug,但我更喜欢正确的使用指令,如果可用的话.
#using <mscorlib.dll>
#using <System.dll>
using namespace System;
using namespace System::Text;
using namespace System::IO;
using namespace System::Net;
using namespace System::Net::Sockets;
using namespace System::Collections;
Run Code Online (Sandbox Code Playgroud)
错误:IntelliSense:"#using"需要启用C++/CLI ....
如何解决这个问题!?
我希望我的C++/CLI标头即使在另一个平台下也能编译.当然我不期望编译它们但只是忽略它们.
这是否合适?(_MSC_VER)
#ifdef _MSC_VER
using namespace System;
namespace ENMFP {
public ref struct Data {
};
}
#endif
Run Code Online (Sandbox Code Playgroud)
谢谢 !