Form not displaying in credential provider

馋奶兔 提交于 2019-12-24 00:45:03

问题


I have a function in C# that displays a form. I have exposed the function using Unmanaged Exports and calling it from C++ in credential provider sample on a command link. The form does not display (nothing happens). However, when I call the same C# form using C++ console application, the form displays without any issue. What could be the difference that C++ console application is loading it but C++ credential provider code is not loading it?

C++ Code:

using CSharpForm = void(__stdcall *)(wchar_t* message);
int _tmain(int argc, _TCHAR* argv[])
{
HMODULE mod = LoadLibraryA("CSharp.dll");
CSharpForm form = reinterpret_cast<CSharpForm>(GetProcAddress(mod, "form1"));
form(L"This is a c# form");
getchar();
return 0;
}

C# Code:

[DllExport(ExportName = "form1", CallingConvention = CallingConvention.StdCall)]
public static void showForm([MarshalAs(UnmanagedType.LPWStr)]string message)
{
    Form_Test form = new Form_Test();
    form.Text = message;
    form.ShowDialog();
}

回答1:


Try this out:

Call ICredentialProviderCredentialEvents::OnCreatingWindow method

HRESULT OnCreatingWindow(
    HWND *phwndOwner
);

to get window handle, pass additional parameter into your library and use overloaded method ShowDialog.

public DialogResult ShowDialog(
    IWin32Window owner
);


来源:https://stackoverflow.com/questions/52083206/form-not-displaying-in-credential-provider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!