2
我在.dll項目中創建了對話框。現在我想通過點擊按鈕從WPF應用程序打開該對話框。以下是對話的代碼:它通過調用創建對話的對象,然後打開該對話框如何從WPF應用程序打開MFC對話框?
#include "stdafx.h"
#include "MFCDll.h"
#include "TestDialog.h"
#include "afxdialogex.h"
IMPLEMENT_DYNAMIC(CTestDialog, CDialogEx)
CTestDialog::CTestDialog(CWnd* pParent /*=NULL*/)
: CDialogEx(CTestDialog::IDD, pParent)
{
}
CTestDialog::~CTestDialog()
{
}
void CTestDialog::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CTestDialog, CDialogEx)
END_MESSAGE_MAP()
我已經創建了導出功能:
TestDialog.h:
class CTestDialog : public CDialogEx
{
DECLARE_DYNAMIC(CTestDialog)
public:
CTestDialog(CWnd* pParent = NULL); // standard constructor
virtual ~CTestDialog();
// Dialog Data
enum { IDD = 1000 };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
};
TestDialog.cpp DoModel()函數。
extern "C" void PASCAL EXPORT ShowDialogFromDLL()
{
CTestDialog dlg;
theApp.m_pMainWnd = &dlg;
dlg.DoModal();
}
之後,我從WPF窗體調用此導出函數以下是WPF窗體的代碼。
MainWindow.xaml.vb:
namespace MainApp
{
public partial class MainWindow : Window
{
[DllImport("MFCDll.dll", CharSet = CharSet.Auto, SetLastError = false)]
public static extern void ShowDialogFromDLL();
public MainWindow()
{
InitializeComponent();
}
private void btnShow_Click(object sender, RoutedEventArgs e)
{
ShowDialogFromDLL();
}
}
}
但現在當我打電話ShowDialogFromDLL();點擊button.It會拋出異常我作爲
Microsoft Visual C++ Debug Library
Debug Assertion Failed!
Program: E:\EDR1\Test\MainApp\bin\Debug\MainApp.vshost.exe
File: f:\dd\vctools\vc7libs\ship\atlmfc\include\afxwin1.inl
Line: 24
For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
後,當我打電話dlg.DoModal();
方法上面的錯誤來了。
+1:這就是答案。 – ceztko