110,567
社区成员
发帖
与我相关
我的任务
分享
void Func(CWnd *pParent);
//MainWindow.xaml.cs 文件
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.Navigation;
using System.Windows.Shapes;
namespace WpfApp
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}
//App.xaml.cs文件
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Runtime.InteropServices;
namespace WpfApp
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
[DllImport("xxx.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public extern static void CreatUSBDLG([In, Out] IntPtr pParent); //CWnd* pParent
static MainWindow MWnd = new MainWindow();
static int size = Marshal.SizeOf(MWnd);
IntPtr pWnd = Marshal.AllocHGlobal(size);
public void init()
{
Marshal.StructureToPtr(this, pWnd, true);
Func(pWnd);
}
protected override void OnStartup(StartupEventArgs e)
{
init();
}
}
}
public partial class App : Application
{
[DllImport("xxx.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public extern static void Func([In, Out] IntPtr pParent); //CWnd* pParent
static MainWindow MWnd = new MainWindow();
IntPtr pHandle = new WindowInteropHelper(MWnd).Handle;
IntPtr pWnd = Marshal.AllocHGlobal(4);
public void init()
{
Marshal.StructureToPtr(pHandle, pWnd, true);
Func(pWnd);
}
protected override void OnStartup(StartupEventArgs e)
{
init();
}
}