标签: c++-cli

为什么我无法从 resx 文件加载图像资源?

我有一个控件库,我已将 .resx 文件添加到其中(ImageResources.resx)。它包含两个我随后添加的 .png 图像。

在同一个库中,我有一个控件,可以加载几个图像来进行一些自定义绘图,但我似乎无法加载资源:

void GTableLayoutPanel::SetBorderImagesFromManifest(String^ topLeftCornerImageName, String^ topImageName)
{
    // Grab the assembly this is being called from
    Assembly^ assembly = Assembly::GetExecutingAssembly();

    // Grab the images from the assembly
    Stream^ stream = assembly->GetManifestResourceStream(topLeftCornerImageName);
    Image^ topLeftImage = System::Drawing::Image::FromStream(stream);
    stream = assembly->GetManifestResourceStream(topImageName);
    Image^ topImage = System::Drawing::Image::FromStream(stream);

    // Update the internal store from the supplied images
    SetBorderImages(topLeftImage, topImage);
}
Run Code Online (Sandbox Code Playgroud)

...给我错误抱怨为stream空,这表明我的呼叫GetManifestResourceStream失败。

图像被调用group_box_top.pnggroup_box_top_left.png并且我调用图像加载器,如下所示:

SetBorderImagesFromManifest("group_box_top_left.png", "group_box_top.png");
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

SetBorderImagesFromManifest("group_box_top_left", "group_box_top");
Run Code Online (Sandbox Code Playgroud)

...因为文件出现在 .resx 文件中,没有 .png 扩展名,但这会产生相同的错误。

我在这里错过了一步吗? …

.net resources resx c++-cli manifest

1
推荐指数
1
解决办法
5048
查看次数

为什么我的程序只能在调试模式下运行?

我正在使用 Visual Studio 2008,带有 .net 框架、C++/CLI。我的程序仅在调试模式下运行(即使从资源管理器运行) - 但在发布模式下它说程序已停止工作。(但如果我在释放模式时按 F5,它运行正常)所有设置都是相同的。会是什么呢?请问有人有什么建议吗?

.net c++-cli

1
推荐指数
1
解决办法
7348
查看次数

为什么我不能在 C++/CLI 中使用 STAThread 属性?

我想在程序的主线程上使用 STAThread 属性。但是,Visual Studio 表示找不到它。我已经尝试引用必要的程序集并使用正确的命名空间,但它只是找不到它。

编辑:

在使用 ApartmentState 到 STA 手动创建线程后,我已经能够成功工作。我认为这相当于设置线程,无论是主线程,但不完全是因为我正在创建另一个线程。任何人都有其他方法可以做到这一点。

这是代码:

void threadStart ()
{
    Application::Run (gcnew GraphicsForm());
}
[System::STAThread] // This will not work!
int main(array<System::String ^> ^args)
{
    Thread ^t = gcnew Thread(gcnew ThreadStart (threadStart));
    t->ApartmentState = ApartmentState::STA;
    t->Start();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++-cli visual-studio

1
推荐指数
1
解决办法
6939
查看次数

IEnumerable 返回类型 C# C++

我有一个带有如下方法签名的 C# 接口:

IEnumerable<string> Myfun();
Run Code Online (Sandbox Code Playgroud)

在 C++/CLR 中,接收返回字符串的数据类型是什么?

我努力了

IEnumerable<std::string> ^abc = myObject.Myfun();
Run Code Online (Sandbox Code Playgroud)

我收到此错误:错误 C3225:“T”的泛型类型参数不能是“std::string”,它必须是值类型或引用类型的句柄

c# ienumerable c++-cli return-type

1
推荐指数
1
解决办法
595
查看次数

确定数组是否包含全零

我像这样创建以下数组:

array<UInt16>^ temp = gcnew array<UInt16>(1000);
Run Code Online (Sandbox Code Playgroud)

如何确定整个数组是否已填充为零。

我想我可以使用TrueForAll(T)但我不确定。

.net c# c++-cli

1
推荐指数
1
解决办法
2994
查看次数

关于“IServiceProvider”的大量错误

奇怪的问题...

这是使用 VisualStudio Community 2017 并且是一个 C++CLI WinForms 项目。

BGStatsInterface.cpp

#include "BGStatsInterface.h"

using namespace System;
using namespace System::Windows::Forms;

[STAThreadAttribute]
void Main(array<String^>^ args) {
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);
    BattlegroundStats::BGStatsInterface form;
    Application::Run(%form);

}
Run Code Online (Sandbox Code Playgroud)

BGStatsInterface.h

#pragma once
#include <windows.h>
#include "LuaReader.h"


namespace BattlegroundStats {

    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    using namespace System::IO;

    public ref class BGStatsInterface : public System::Windows::Forms::Form
    {
    public:
        BGStatsInterface(void)
        {
            InitializeComponent();
            this->MinimizeBox = false;
            this->MaximizeBox = false;
        }

        static …
Run Code Online (Sandbox Code Playgroud)

c++-cli winforms visual-studio-2017

1
推荐指数
2
解决办法
2253
查看次数

包装 C++ 共享库时在 C++/CLI 项目中出现链接错误

我正在尝试将 C++ 库包装到托管项目可以使用它。我使用的第三方库是共享库。它的目的是在加载时链接。我有头文件、.lib 文件(DLL 导入库)和 .DLL 文件。

这是我到目前为止所做的:- 1. 创建 CLR 项目。2. 在C/C++->常规->附加包含目录中添加头文件路径。 3. 在链接器->常规中设置“附加库目录”。4.在Linker->Input->Additional Dependency中添加lib名称

执行此操作后,我收到 LNK2005 链接错误,然后收到 LNK1169。创建项目后我做的唯一一件事就是包含我试图包装的 C++ 库中的头文件。我究竟做错了什么?

错误 LNK2005:“public:virtual char const * __cdecl std::exception::what(void)const ” (?what@exception@std@@UEBAPEBDXZ) 已在...中定义 致命错误 LNK1169:一个或多个多重定义的符号成立

c++ native c++-cli word-wrap

1
推荐指数
1
解决办法
1592
查看次数

C++/CLI中的事件处理

我有一个函数singleFrameEventHandler,我希望在某个事件OnNewFrame发生时调用它.在做了一些研究之后,在我看来,处理事件的函数具有void返回类型并且采用包含事件的类型的参数.从我在网上找到的,这是这样做的:

功能声明:

void singleFrameEventHandler(IAFrame ^ frame);
Run Code Online (Sandbox Code Playgroud)

分配函数以处理事件时:

iaframe->OnNewFrame += &singleFrameEventHandler;
Run Code Online (Sandbox Code Playgroud)

当我尝试编译包含上述段的代码时,我收到以下错误:

error C2664: 'Spiricon::BeamGage::Automation::Interfaces::IAFrame::OnNewFrame::add' : cannot convert parameter 1 from 'void (__clrcall *)(Spiricon::BeamGage::Automation::Interfaces::IAFrame ^)' to 'Spiricon::BeamGage::Automation::Interfaces::newFrame ^'
No user-defined-conversion operator available, or
There is no context in which this conversion is possible
Run Code Online (Sandbox Code Playgroud)

OnNewFrame的类型是Spiricon :: BeamGage :: Automation :: Interfaces :: newFrame,遗憾的是,它没有被描述为"当新帧可用时调用的事件"之外的文档.

在对象浏览器中,我可以找到一些有关它的信息:

public delegate newFrame:
    public System.IAsyncResult BeginInvoke(System.AsyncCallback callback, System.Object object)
    public System.Void EndInvoke(System.IAsyncResult result)
    public System.Void Invoke()
    public newFrame(System.Object object, System.IntPtr method)
Run Code Online (Sandbox Code Playgroud)

newFrame构造函数(?)似乎是最好的选择,因为它似乎采用了方法指针,但当我尝试使用它时:

iaframe->OnNewFrame += gcnew newFrame(iaframe, &singleFrameEventHandler);
Run Code Online (Sandbox Code Playgroud)

我收到以下错误: …

.net events c++-cli event-handling

0
推荐指数
1
解决办法
2873
查看次数

为什么"候选功能无法访问",尽管已公布

candidate function(s) not accessible在调用某些成员时遇到编译错误,尽管我将它们声明为public.当涉及来自vtk的某个类(作为返回类型或参数)并且要调用的类与调用代码不在同一个VS项目中时,我只得到错误.我也试过其他vtk类型没有运气:(

这是一些测试代码:

// A.h, in a seperate class library
#include <vtkActor.h>
public ref class A
{
public:
    A(void);

    void test1(vtkActor* actor);
    vtkActor* test2();
    void test3(char* actor);
    char* test4();
};


// B.h, Same as A but in the same project as the calling code 
#include <vtkActor.h>
ref class B
{
public:
    B(void);

    void test1(vtkActor* actor);
    vtkActor* test2();
    void test3(char* actor);
    char* test4();
};
Run Code Online (Sandbox Code Playgroud)

我试着从同一个项目中调用函数B是这样的:

// calls to class library
A^ …
Run Code Online (Sandbox Code Playgroud)

.net c++-cli vtk visual-c++

0
推荐指数
1
解决办法
3552
查看次数

C++公共语言运行时支持[.Net?]

嗨,大家好!
这不是一个大问题,但是,我想知道当你启用选项"公共语言运行时支持(/ clr)"时它是否需要".net框架"?

c++ clr c++-cli

0
推荐指数
1
解决办法
1245
查看次数