I created a custom Credential Provider for Windows. The base DLL is in C++ and it loads a C# DLL trought a COM interface.
if (CoInitialize(NULL) != S_OK) {
hr = _authenticationManager.CreateInstance("{BAF984BD-0D41-42D1-AA49-4BC98EE6C4A1}");
std::stringstream stream;
stream << std::hex << (int)hr;
MessageBoxA(NULL, stream.str().c_str(), "", 0);
The class is registered like that :
REGEDIT4
[HKEY_CLASSES_ROOT\Record\{71C93A0D-861E-3195-A2D8-51DA34307BCA}\1.0.0.0]
"Class"="AuthenticationManager.BUTTON_TYPE"
"Assembly"="AuthenticationManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
"RuntimeVersion"="v4.0.30319"
[HKEY_CLASSES_ROOT\AuthenticationManager.AuthenticationManager]
@="AuthenticationManager.AuthenticationManager"
[HKEY_CLASSES_ROOT\AuthenticationManager.AuthenticationManager\CLSID]
@="{BAF984BD-0D41-42D1-AA49-4BC98EE6C4A1}"
[HKEY_CLASSES_ROOT\CLSID\{BAF984BD-0D41-42D1-AA49-4BC98EE6C4A1}]
@="AuthenticationManager.AuthenticationManager"
[HKEY_CLASSES_ROOT\CLSID\{BAF984BD-0D41-42D1-AA49-4BC98EE6C4A1}\InprocServer32]
@="mscoree.dll"
"ThreadingModel"="Both"
"Class"="AuthenticationManager.AuthenticationManager"
"Assembly"="AuthenticationManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
"RuntimeVersion"="v4.0.30319"
[HKEY_CLASSES_ROOT\CLSID\{BAF984BD-0D41-42D1-AA49-4BC98EE6C4A1}\InprocServer32\1.0.0.0]
"Class"="AuthenticationManager.AuthenticationManager"
"Assembly"="AuthenticationManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
"RuntimeVersion"="v4.0.30319"
[HKEY_CLASSES_ROOT\CLSID\{BAF984BD-0D41-42D1-AA49-4BC98EE6C4A1}\ProgId]
@="AuthenticationManager.AuthenticationManager"
[HKEY_CLASSES_ROOT\CLSID\{BAF984BD-0D41-42D1-AA49-4BC98EE6C4A1}\Implemented Categories\{62C8FE65-4EBB-45E7-B440-6E39B2CDBF29}]
The C# DLL delcaration looks like this :
[Guid("BAF984BD-0D41-42D1-AA49-4BC98EE6C4A1")]
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(IAuthenticationManager))]
public class AuthenticationManager : IAuthenticationManager
It works perfectly when using winlogon to log to the computer, when i log off, the provider loads, and the C# too, all is good
But, when i use it for an other purpose, it fails to load the COM component : CreateInstance returns 0x80040154 (REGDB_E_CLASSNOTREG).
Example of usage that does not works : SHIFT+RIGHT CLICK on a exe -> Execute as other user The provider is loaded, and the class is not found...
I heard on forums that 32 and 64 bits mixing can be the source of the problem, but both process (winlogon & explorer) are x64, and all my dlls (credential + authenticationManager) are x64 too.
Can you please help me, i have been stuck for 3 days....
Thank you very much.
Anymore, COM is a bad idea! Alternativelly, you can use Visual C++ CLI. CLI support is a bridge between native C++ and managed C#.NET libraries.
User contributions licensed under CC BY-SA 3.0