Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从DLL打开一个对话框 我有一个Visual Studio 2008解决方案,有两个项目:C语言窗口窗体应用程序和C++ DLL。DLL将打开一个自定义CFILE对话框。下面是一个演示问题的玩具版本,其中C#应用程序只是启动对话框的按钮和显示结果的标签:_C#_C++_Windows_Visual Studio - Fatal编程技术网

从DLL打开一个对话框 我有一个Visual Studio 2008解决方案,有两个项目:C语言窗口窗体应用程序和C++ DLL。DLL将打开一个自定义CFILE对话框。下面是一个演示问题的玩具版本,其中C#应用程序只是启动对话框的按钮和显示结果的标签:

从DLL打开一个对话框 我有一个Visual Studio 2008解决方案,有两个项目:C语言窗口窗体应用程序和C++ DLL。DLL将打开一个自定义CFILE对话框。下面是一个演示问题的玩具版本,其中C#应用程序只是启动对话框的按钮和显示结果的标签:,c#,c++,windows,visual-studio,C#,C++,Windows,Visual Studio,DialogApp.cs: ... public partial class Form1 : Form { ... [DllImport("DialogDll.dll")] static extern int OpenDialog(); ... private void button1_Click(object sender, EventArgs e) { int r = OpenDialog(); label1.Text

DialogApp.cs:

...
public partial class Form1 : Form {
    ...
    [DllImport("DialogDll.dll")]
    static extern int OpenDialog();
    ...
    private void button1_Click(object sender, EventArgs e) {
        int r = OpenDialog();
        label1.Text = r.ToString();
    }
}
DialogDll.h:

extern "C" {
    __declspec(dllexport) int __cdecl OpenDialog();
}
DialogDll.cpp:

#include <afxdlgs.h>
#include "DialogDll.h"

extern int __cdecl OpenDialog() {
    CFileDialog d(TRUE, NULL, NULL, OFN_HIDEREADONLY, _T("All Files (*.*)|*.*||"), NULL);
    if (d.DoModal() == IFOK) {
        return 4;
    } else {
        return 9;
    }
}

好悲伤!我走的方向对吗?我已经做了多年的编程工作,但我对Windows平台还是相当陌生的。我想在完成了所有这些工作之后,我的问题仍然很简单:如何从我的dll中打开CFileDialog?

请参阅上面的评论,但我建议作为我的答案:

改用或


使用

你可能正朝着正确的方向前进。我假设您希望/需要在DLL中使用MFC

WinApp和MANAGE_STATE的建议很好

你在任何C++源文件中抛出/CLR或CLR:纯?为什么?您的C++ DLL是否将托管代码和本机代码混合在一起? 这个小应用的修复方法是不抛出/clr。这将使所有C++代码原生,并确保您不必从加载程序锁调用托管静态初始化器。
Martyn

如果您将对AFX\u MANAGE\u STATE的呼叫添加到您的DllMain中,可能会将其删除?被调用的托管代码很可能是一个C窗口的事件处理程序,通过在某个消息循环中调用DispatchMessage来调用。我还没有编写DLMIN。保罗,你找到了解决这个问题的方法吗?@ SZELLINSKI:我确信有C++ Windows UI经验的人可以解决这个问题。但我最终还是放弃了,用C实现了所有东西。现有的用于打开对话框的C函数不适合我。我需要访问我自己的C++实现。
LoaderLock was detected:
Attempting managed execution code inside OS Loader Lock. Do not attempt to run
managed code inside a DllMain or image initialization function since doing so
can cause the application to hang.