简体   繁体   中英

Form not displaying in credential provider

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();
}

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
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM