本文根据/detail/l250178301/5647347创建,并加上自己的一些实际情况·
首先,新建一个wpf项目
然后
把app.xaml和那个窗口删掉!!!!!
否则会报错
将输出类型从exe->类库
此处为Windows1.xaml.cs的代码,Class_wpf用作调用接口
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Shapes;namespace dll_sample{/// <summary>/// Window1.xaml 的交互逻辑/// </summary>public partial class Window1 : Window{public Window1(){InitializeComponent();}private void button_Click(object sender, RoutedEventArgs e){}}public class Class_wpf{public void classdlg(){Window1 win1 = new Window1();win1.ShowDialog();}}}
然后生成dll
放到C++文件的目录下(\debug 这个文件内必须要有dll,还有一个随缘,我直接把他扔进C++内)
C++项目改为 无公共语言运行时支持->公共语言运行时支持(/clr)
#include <iostream>#using "dll_sample.dll"using namespace std;using namespace dll_sample;int main(){Class_wpf ^ win = gcnew Class_wpf;win->classdlg();system("pause");return 0;}
tips:如果有提示要安装程序集的话全部安装
然后Finish