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
methodto get window handle, pass additional parameter into your library and use overloaded method
ShowDialog
.