我有一个无人管的C++类,我用无人的dll编写.我有一个托管的dll引用了非托管的dll.托管dll中的类可以从非托管类派生吗?
使用Visual Studio 2008
-----你好,世界2.cpp -----
// Hello, World 2.cpp : main project file.
#include "stdafx.h"
#include "hello.h"
#include <string>
using namespace System;
using namespace std;
int main(array<System::String ^> ^args)
{
hello hi = new hello("Bob", "Blacksmith");
Console::WriteLine(L"Hello, " + hi.getName + "!");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
----- hello.h -----
#include <string>
using namespace std;
#ifndef HELLO_H
#define HELLO_H
class hello
{
private:
string _fname;
string _lname;
//hello() { } // private default constructor
public:
hello(string fname, string lname);
void SetName(string fname, string lname);
string …Run Code Online (Sandbox Code Playgroud) 我知道如何使用C++编写控制台程序,但现在我想编写带有Windows界面的程序.使用拖放设计系统编写C++ Windows应用程序时,MS VS 2010简化了操作.(.net Framework)但是,Visual Studio似乎使用的是C++/CLI,我对此并不熟悉.
是否只有使用C++的IDE?是否有一个易于使用的GUI设计师的好IDE,或者我可以调整VS 2010以不使用C++/CLI?
我们收到了这段代码作为一项任务,在花了很多时间解决问题之后,我最终得到了一个syntax error : identifier 'String'.我在网上看到的每个人都在使用std::string,但这不是代码所指的内容,因为使用String对象从C#项目调用该函数.
这是宣言:
int findWindow(String ^CaptionText,IntPtr ^%phWnd,
int %left,int %top,int %right,int %bottom);
Run Code Online (Sandbox Code Playgroud)
我不知道如何解决这个问题.还有其他错误,例如
error C2062: type 'int' unexpected
...
error C2065: 'IntPtr' : undeclared identifier
error C2065: 'String' : undeclared identifier
...
Run Code Online (Sandbox Code Playgroud)
等等
任何帮助赞赏.
我是否应该提到这些错误与作业无关?
假设我有一个用C++/CLI编写的NUnit测试项目,用/clr交换机构建.也就是说,它可以引用和使用本机代码,它不是纯粹的托管程序集.
NUnit可以运行这样的项目,但可以使用Resharper从Visual Studio中完成吗?我有R#5.x,我不能(甚至看不到R#代码窗口左边的图标来启动测试).最新版本可以R#这样做吗?
考虑以下课程:
public ref class Workspace
{
protected:
Form^ WorkspaceUI;
SplitContainer^ WorkspaceSplitter;
AvalonEditTextEditor^ TextEditor;
ScriptOffsetViewer^ OffsetViewer;
SimpleTextViewer^ PreprocessedTextViewer;
ListView^ MessageList;
ListView^ FindList;
ListView^ BookmarkList;
ListView^ VariableIndexList;
TextBox^ VariableIndexEditBox;
Label^ SpoilerText;
ToolStrip^ WorkspaceMainToolBar;
ToolStripButton^ ToolBarNewScript;
ToolStripButton^ ToolBarOpenScript;
ToolStripButton^ ToolBarPreviousScript;
ToolStripButton^ ToolBarNextScript;
ToolStripSplitButton^ ToolBarSaveScript;
ToolStripDropDown^ ToolBarSaveScriptDropDown;
ToolStripButton^ ToolBarSaveScriptNoCompile;
ToolStripButton^ ToolBarSaveScriptAndPlugin;
ToolStripButton^ ToolBarRecompileScripts;
ToolStripButton^ ToolBarCompileDependencies;
ToolStripButton^ ToolBarDeleteScript;
ToolStripButton^ ToolBarNavigationBack;
ToolStripButton^ ToolBarNavigationForward;
ToolStripButton^ ToolBarSaveAll;
ToolStripButton^ ToolBarOptions;
ArbitraryCustomClass^ CustomClassInstance;
public:
Workspace()
{
WorkspaceUI = gcnew Form();
WorkspaceSplitter = gcnew SplitContainer();
// ...
Form->Controls->Add(WorkspaceSplitter);
// ...
WorkspaceUI->Show(); …Run Code Online (Sandbox Code Playgroud) garbage-collection destructor idisposable c++-cli delete-operator
是否可以检查用户何时在模态窗口外单击?我想以某种方式绕过模态逻辑,因为如果窗口没有显示为模态,它将不会显示在活动窗口的顶部,而且,目前,这是正确显示它的唯一方法.我还没有找到合适的方法(因为"停用"事件将不再被触发..)
Visual Studio 2010(C++)中的C++ CLR.
我有这个结构:
value struct Triangle{
static array<int>^ v = gcnew array<int>(3);
static array<int>^ t = gcnew array<int>(3);
static array<int>^ n = gcnew array<int>(3);
};
Run Code Online (Sandbox Code Playgroud)
我在课堂的"私人"部分声明了以下内容:
static array<Triangle^>^ triangles = gcnew array<Triangle>(MAX_POLYGONS);
Run Code Online (Sandbox Code Playgroud)
我得到这个错误,我不知道它意味着什么(因为它似乎自相矛盾):
error C2440: 'initializing' : cannot convert from 'cli::array<Type> ^' to 'cli::array<Type> ^'
with
[
Type=Triangle
]
Run Code Online (Sandbox Code Playgroud)
显然它不喜欢结构.我应该使用ref而不是value吗?这产生了很多指针.任何推进正确的方向将不胜感激.
我正在尝试使用字符串参数打开文件,但是我收到以下错误:
error C2664: 'void std::basic_ifstream<_Elem,_Traits>::open(const wchar_t *,std::ios_base::openmode,int)' : cannot convert parameter 1 from 'System::String ^' to 'const wchar_t *'
Run Code Online (Sandbox Code Playgroud)
你怎么转换System::String ^成const wchar_t *?
如何将'String ^'转换为'const char*'?
String^ cr = ("netsh wlan set hostednetwork mode=allow ssid=" + this->txtSSID->Text + " key=" + this->txtPASS->Text);
system(cr);
Run Code Online (Sandbox Code Playgroud)
错误:
1 IntelliSense: argument of type "System::String ^" is incompatible with parameter of type "const char *"
Run Code Online (Sandbox Code Playgroud) c++-cli ×10
visual-c++ ×2
c# ×1
c++ ×1
destructor ×1
idisposable ×1
managed-c++ ×1
nunit ×1
resharper ×1
string ×1
struct ×1
unmanaged ×1
widechar ×1
wpf ×1