zoukankan      html  css  js  c++  java
  • .Net互操作2

    1.C++创建Dll,Win32控制台,空项目,添加头文件NativeLib.h,NativeLib.cpp

    extern "C" __declspec(dllexport) void __stdcall PrintMsg(const char* msg);
    #include <stdio.h>
    #include "NativeLib.h"
    
    
    void __stdcall PrintMsg(const char* msg)
    {
        printf("%s
    ", msg);
        return;
    }

    2.C#创建控制台应用程序HelloWorld

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.InteropServices;
    
    namespace HelloWorld
    {
        class Program
        {
            [DllImport("NativeLib.dll")]
            static extern void PrintMsg(string msg);
            static void Main(string[] args)
            {
                PrintMsg("Hello world!");
                Console.ReadLine();
            }
        }
    }

    3.修改C++项目属性:配置属性->连接器->常规->输出文件

    修改C#项目属性:生成->输出->输出路径

    两个输出路径要一致即可(eg:F:试验exChapter 1x86DebugNativeLib.dll(C++Dll输出文件),F:试验exChapter 1x86Debug(C#输出路径))。

  • 相关阅读:
    选择排序
    快速排序
    希尔排序
    直接插入排序
    判断三角形的类型
    Unicode编码下: CString 转换为 string
    GDAL中GDALDataType中值与其在C++中数据类型对应
    ftell()
    fseek()
    fopen_s()
  • 原文地址:https://www.cnblogs.com/ccjcjc/p/3426017.html
Copyright © 2011-2022 走看看