标签: c++-cli

将.pfx证书附加到exe文件

我必须将软件部署到n个客户端,这些客户端将安装证书并使用它.我不想只部署两个文件(.pfx和exe)(包含.pfx的.exe).

我现在正在做的是从一个位置导入证书.

X509Certificate2^ x509 = gcnew X509Certificate2;
x509->Import( "C:\\Tmp\\certficate.pfx" );
Run Code Online (Sandbox Code Playgroud)

可能吗 ?

exe c++-cli certificate x509certificate2 visual-studio

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

无法从const char []转换为std:string*

在visual c ++ cli项目文件中,我创建了以下类(c ++类型).无法解析适合名称变量的字符串或char类型.

#include <vector>
#include <string.h>
using namespace std ;

class MyClass 
{
public :
int x;
int y;
string * name;

void foo() { name = "S.O.S" ;}
};
Run Code Online (Sandbox Code Playgroud)

Ps.型铸造错误

c++ c++-cli visual-c++

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

如何使用MonthCalender在文本框中插入日期?

我有一个textBox1Windows窗体.我想用它来获取用户的日期.我想显示MonthCalender1一旦用户将光标放入textbox1,然后textbox1自动设置日期,然后日历将消失.我如何使用C#或C++/CLI来做到这一点?

.net c# c++-cli monthcalendar

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

什么对应C++\CLI中的string []

我想询问并了解string[]C++\CLI中与C#类型相对应的内容?

.net c# c++-cli

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

在C++/CLI代码中从std :: stringstream读取std :: string的问题

我有一段代码来读取构建日期和月份.这__DATE__是在预定义宏中定义的

const char* BUILD_DATE = __DATE__;
std::stringstream ss(BUILD_DATE);
std::string month;
size_t year;
ss >> month;
ss >> year;
ss >> year;

char buffer[1024];
sprintf(buffer, "Read year=[%d] month=[%s] date=[%s]", year,month.c_str(),BUILD_DATE);
Run Code Online (Sandbox Code Playgroud)

当它正常工作时,通常是缓冲区

读取年份= [2013]月= [3月]日期= [2013年3月9日]

但在某些运行中它是

读取年份= [0]月= [M]日期= [2013年3月9日]

要么

读取年份= [2013]月= [3月]日期= [2013年3月9日]

基本上年份是0或月份有额外的空间.

该项目是在Windows 7上使用Microsoft Visual Studio 2010 SP1的x64/CLR版本.

我很难过为什么偶尔会发生这种情况.我是否正确使用stringstream?

c++ c++-cli stringstream

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

将托管类成员传递给c ++方法

我有一个C++ DLL与以下方法:

//C++ dll method (external)
GetServerInterface(ServerInterface* ppIF /*[OUT]*/)
{
//The method will set ppIF
}

//ServerInterface is defined as:
typedef void *  ServerInterface;
Run Code Online (Sandbox Code Playgroud)

为了从C#项目访问dll,我创建了一个C++/CLI项目并声明了一个托管类,如下所示:

public ref class ComWrapperManager
{
//
//
ServerInterface _serverInterface;
void Connect();
//
//
}
Run Code Online (Sandbox Code Playgroud)

我使用Connect()方法调用GetServerInterface,如下所示.第一次通话有效,第二次通话无效.有人可以解释原因吗?我需要将该指针持久化为托管类中的成员变量.有更好的方法吗?

    void Connect()
    {
    ServerInterface localServerInterface;
    GetServerInterface(&localServerInterface); //THIS WORKS

    GetServerInterface(&_serverInterface); //THIS DOESNT

    //Error 1   error C2664: 'ServerInterface ' : 
    //cannot convert parameter 1 from //'cli::interior_ptr<Type>' 
    //to 'ServerInterface *'


    }
Run Code Online (Sandbox Code Playgroud)

pointers c++-cli

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

c ++/cli程序集加载一个产生多个CLR线程的C#组件; 如何阻止这些线程重新进入C++/CLI入口点?

我有一个使用以下组件构建的C/C++应用程序

  1. 本机C/C++应用程序(单线程消息泵,典型的Win32 UI应用程序),静态链接(2)
  2. 本机C/C++ Lib/DLL,它在运行时动态加载(3)
  3. 用/ clr编译的C++/CLI DLL包装C#程序集(4)
  4. AC#assembly使用TPL并具有后台定时器,全部通过静态单例方法公开

我的问题是:C#assembly产生异步I/O线程以响应来自父应用程序的调用,并在后台使用一对System.Threading.Timer实例.

这些线程继续附加本机C/C++应用程序(1)并引起一些副作用,例如COM初始化问题.

这是C#组件运行时输出窗口的样子,我可以看到这些线程在运行时附加到C++/CLI DLL(3)入口点.

C#线程退出本机C/C++应用程序

我的问题是:如何从C/C++应用程序中防火这些C#线程?我不希望这些线程能够继续调用加载它的本机代码的入口点.

到目前为止,我们能够提出的最好的解决方法是运行所有在他们自己的独立Win32线程(可以工作)中调用C++/CLI/C#dlls(3和4)的代码,但我会很感激任何其他建议!

c# winapi multithreading c++-cli

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

将System :: String转换为UTF8中的std :: string,稍后将其转换为char*作为c_str

我有一个System::String^C++代码变量.应将此变量转换std::string为稍后转换为const char*via的变量c_str.

// original string
System::String^ path = ...;

// convert to std::string
msclr::interop::marshal_context context;
std::string filename(context.marshal_as<std::string>(path));

// call API function that internally connects to sqlite3 using sqlite3_open as
//   sqlite3_open(filename.c_str())
// https://www.sqlite.org/c3ref/open.html - 
//  const char *filename,   /* Database filename (UTF-8) */
doCalculation(filename)
Run Code Online (Sandbox Code Playgroud)

它适用于ASCII路径,但如果路径包含非拉丁字符,则会失败.

所以我需要将marshalled std :: string从当前实现(ASCII?)转换为UTF8.

我试过了

    std::wstring dbPath(context.marshal_as<std::wstring>(path));
    std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> convert;
    std::string dbPathU8 = convert.to_bytes(dbPath);
Run Code Online (Sandbox Code Playgroud)

但它不起作用.

c++-cli

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

C++/CLI中的"long"类型与C#有什么区别?

C++/CLI项目中,我有方法void DoSomething(long x);.如果我想在用C#编写的任何单元测试中使用它,则方法参数x显示为类型int.

为什么我必须更改签名才能在单元测试(C#)中void DoSomething(long long x);使用类型参数long

c# types c++-cli long-integer

0
推荐指数
2
解决办法
1258
查看次数

如何将字符串转换为Guid?

我有字符串类型值"e2ddfa02610e48e983824b23ac955632".我需要添加 - 在此代码中意味着转换为Guid.

EntityKey = "e2ddfa02610e48e983824b23ac955632";
Id = (Guid)paymentRecord.EntityKey;
Run Code Online (Sandbox Code Playgroud)

c# c++-cli

0
推荐指数
2
解决办法
4446
查看次数