在 DLL 中为类创建实例
creating instance for a class in a dll
如何在 c# dll 中为在 c++ 项目中导入的类创建实例?我已按照此处给出的说明将 c# 库导入 c++。我可以使用公共接口调用函数。
[编辑]我想通过 c++ 为 c# dll 中的类属性设置值,并将其传递给 dll。这样我就可以跳过 c# dll 中的许多设置函数。如果我可以为类创建对象,我将使用该对象设置值并将对象传递给 c# dll。
在您提供的链接中,在 c++ 客户端代码说明中
// CPPClient.cpp: Defines the entry point for the console application.
// C++ client that calls a managed DLL.
#include "stdafx.h"
#include "tchar.h"
// Import the type library.
#import "..ManagedDLLbinDebugManagedDLL.tlb" raw_interfaces_only
using namespace ManagedDLL;
int _tmain(int argc, _TCHAR* argv[])
{
// Initialize COM.
HRESULT hr = CoInitialize(NULL);
// Create the interface pointer.
ICalculatorPtr pICalc(__uuidof(ManagedClass));
long lResult = 0;
// Call the Add method.
pICalc->Add(5, 10, &lResult);
wprintf(L"The result is %dn", lResult);
// Uninitialize COM.
CoUninitialize();
return 0;
}
指针的创建,pICalc
几乎是类对象的创建。 在行中创建 ICalculatorPtr pICalc(__uuidof(ManagedClass));
相关文章:
- 在C++中为链表类创建实例
- 在 C++ 中在堆栈上创建实例时如何保持多态性?
- 如何使用Qt在D-Bus上创建/实例化配对代理
- 共创建实例消耗高 CPU
- 从与"this"相同的模板创建实例?
- 如何在不创建实例的情况下获取类的方法成员的类型?
- 创建实例化所有其他类和子系统的类的目的是什么
- 我怎么可能从尚未定义某些成员方法的类创建实例?(C++)
- godot的NetSocket如何创建实例?
- VULKAN创建实例vk_out_of_host_memory
- 如何推动在LUA脚本上使用的现有/创建/实例化类对象
- 为什么不能在不创建实例的情况下使用多态类
- 共同创建实例在 32 位上崩溃
- 创建实例时静态变量的地址
- 使用虚拟函数创建实例,为什么
- ADO 连接创建实例在 Windows Server 2003 上失败
- 使用函数中的复制构造函数创建实例的副本,该函数获取作为基对象传递的实例
- 如何从字符串中存储的类型创建实例
- ccomptr _appdomain 创建实例返回系统找不到指定的文件
- 创建实例化类数组 - 语法