【发布时间】:2016-10-03 00:44:12
【问题描述】:
我已经用 c++ 和 c# 编写了代码。从我的 c++ 代码中,我通过调用我的 c# 函数。我只发送了一部分 C++ 代码。
txtPath 包含文本文件的位置。 C++代码:
CoInitialize(NULL);
IMyClassPtr obj3;
obj3.CreateInstance(__uuidof(Program));
obj3->Validation(txtPath);
CoUninitialize();
Validation() 是我的 c# 函数。 我的 C# 代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using word = Microsoft.Office.Interop.Word;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace ABC
{
[ComVisible(true)]
public interface IMyClass
{
void Validation(string txtp);
}
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
public class Program : IMyClass
{
private string replace_string(string text)
{
return text.Replace("\r\a", "");
}
public void Validation(string txtp)
{
string[] textValidate = File.ReadAllLines(txtp);
string textpath = txtp;
//validation starts here
foreach (string line in textValidate)
{
string[] strsplit = line.Split(new string[] { "," }, StringSplitOptions.None);
string task = strsplit[0];
string sign = strsplit[1];
string person = strsplit[2];
string routing = strsplit[3];
if (String.IsNullOrEmpty(task) || String.IsNullOrEmpty(sign) || String.IsNullOrEmpty(person))
{
//if the txt file is invalid
MessageBox.Show("Signature.txt is incomplete or has invalid input!!!");
}
}
}
}
}
我已经在 c# 中完成了所有必需的设置。C# settings snapshot C# 项目是一个类库。我的代码在 32 位机器上运行良好。我通过 regasm.exe 注册它在其他系统中使用生成的 tlb。
c++ 代码在 64 位机器上工作,但是当 c# 链接代码被命中时,执行停止而没有抛出任何错误。我正在使用 64 位机器并使用相同的代码创建了一个新项目。请帮忙
【问题讨论】:
标签: c# c++ com-interop regasm tlb