vc++ プロジェクトまたはライブラリ内で c# dll を呼び出す方法を教えてください。これは正常に動作している私の c# dll コードです。この dll フォーム vc++ プロジェクトを呼び出したいだけですが、vc++ からこの dll を呼び出すと、応答がありません。
私のC#DLLコードは -
namespace MyInterop
{
[Guid("3E0E2EB2-CC13-40fb-9346-34809CB2418C")]
public interface IMyDotNetInterface
{
void NewFile(string a, string b);
}
[ClassInterface(ClassInterfaceType.None)]
[Guid("3A13EB34-3930-4e06-A3EB-10724CCC2F4B")]
public class MyDotNetClass:IMyDotNetInterface
{
public MyDotNetClass ()
{
}
public void NewFile(string a, string b)
{
string c= a + b;
string fileName = @"D:\file.txt";
try
{
// Check if file already exists. If yes, delete it.
if (File.Exists(fileName))
{
File.Delete(fileName);
}
// Create a new file
using (FileStream fs = File.Create(fileName))
{
// Add some text to file
TextWriter tsw = new StreamWriter(@"D:\Hello.txt");
//Writing text to the file.
tsw.WriteLine(c);
tsw.Close();
}
}
catch (Exception Ex)
{
}
}
そして私のvc++コードは-
BSTR param1 = L"hello";
BSTR param2 = L"World";
CoInitialize(NULL);
MyInterop::IMyDotNetInterfacePtr pDotNetCOMPtr;
HRESULT hRes = pDotNetCOMPtr.CreateInstance(MyInterop::CLSID_MyDotNetClass);
if (hRes == S_OK)
{
pDotNetCOMPtr->NewFile(param1,param2);
}
私に提案してください