English 中文(简体)
如何进口和使用/经营一个C++,然后再进入另一个C#项目?
原标题:How to import and use/run a C++ dll into another C# project?

I ve created a C# application. Within this application I would like to use/run a C++ API from another project(the API is written in macro coding). I tried import the dll of that C++ project and tried to call a functions which belongs to that API. The problem is that it throws "unable to find method" error.

我如何在C#项目中开展C++项目?

最佳回答

你可以增加一个本地的DLL,作为管理项目的一个参考。 你有三个主要选择:

  1. Make the native functions available with p/invoke.
  2. Expose the native code through COM.
  3. Compile the native code as a managed C++ assembly.

对于任何严重的法典,选项3是最有成效和最有效的方法。

问题回答

If by "running", you mean a separate process:

Use the class System.Diagnostics.Process available in .NET:

myProcess.StartInfo.FileName = "notepad.exe";
myProcess.StartInfo.CreateNoWindow = false;
myProcess.Start();

如果你指使用C++中开发的批号,你可使用<代码>。 平台:

using System;
using System.Runtime.InteropServices;

class PlatformInvokeTest
{
    //First param is of course either in your PATH, or an absolute path:
    [DllImport("msvcrt.dll", EntryPoint="puts", CallingConvention=CallingConvention.Cdecl)]
    public static extern int PutString(string c);
    [DllImport("msvcrt.dll", CallingConvention=CallingConvention.Cdecl)]
    internal static extern int _flushall();

    public static void Main() 
    {
        PutString("Test");
        _flushall();
    }
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签