首页 > 编程语言 > 详细

C#嵌入C++

时间:2018-01-22 10:33:21      阅读:243      评论:0      收藏:0      [点我收藏+]

你的问题应该是怎么在C#里调用C++代码写成的后编译好的dll,对吗?

因为如果C#里直接嵌入C++是不会通过编译的。

下面是一个C#里调用C++代码写成的后编译好的dll 的例子:

C# 部分:

// Sample program to call unmanaged code

using System;

using System.Runtime.InteropServices;

 

class PInvoke1App

{

[DllImport("user32.dll")]

static extern int MessageBoxA(int hWnd, string strMsg, string strCaption, int iType);

 

public static void Main()

{

MessageBoxA(0, "Hello, World!", "This is called from a C# app!", 0);

}

}

C++部分,编译成user.dll

#include <windows.h>

 

BOOL __stdcall DllMain(HINSTANCE hInst, DWORD dwReason, LPVOID lpReserved) {

return TRUE;

}

 

__declspec(dllexport) void __stdcall Message(char* p_szMessage) {

MessageBox(NULL, p_szMessage, "Message from DLL", MB_OK);

}

 

C#嵌入C++

原文:https://www.cnblogs.com/pugongying123/p/8327572.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!