access .NET thread to get Principal / Identity ?

  • Thread starter Thread starter hazz
  • Start date Start date
hazz said:
is that possible from a C++ app?
thank you.

It is not all that clear what you want to do. Which thread are you talking
about?

Both dialects of C++ (managed and unmanaged) have no trouble calling
functions of the Win32 API. In particular, calling GetUserName() and
LookupAccountName() might take you where you want to go.

Regards,
Will
 
Thank you for responding Will. Sorry for not offering more detail.

I have the following .NET C# code using .NET System.Security.Principal;

m_iIdnt = new System.Security.Principal.GenericIdentity(t.UserName,"custom
authentication");
m_iPrincipal = new
System.Security.Principal.GenericPrincipal(m_iIdnt,roles);
System.Threading.Thread.CurrentPrincipal=m_iPrincipal;

What I would like to do is access the Identity from what happened above, but
from a C++ app rather than the following .NET app;

IPrincipal currentPrincipal = Thread.CurrentPrincipal;
IIdentity currentIdentity = currentPrincipal.Identity;
string authtype = currentIdentity.AuthenticationType;
if (currentIdentity.IsAuthenticated) .........

thank you,
Greg
 
The FCL classes are only usable in a managed C++ application, native C++
cannot use managed classes.

Willy.
 
Sure, you can expose your C# class as COM object and use COM interop,
question is why would you do that when simply calling the Win32 API's gives
you the same information.

Willy.
 
Thanks Willy for helping me out here. One more outrageous question. Can I
access the .NET runtime thread using Win32 API's. (which contains the
Principal and Identity that I want) thx. -greg the newbie
 
hazz said:
Thanks Willy for helping me out here. One more outrageous question. Can I
access the .NET runtime thread using Win32 API's. (which contains the
Principal and Identity that I want) thx. -greg the newbie

<note>
I am not passing on your design strategy, simply answering the question that
you asked.
</note>

You can mix unmanaged C++ and Managed Extensions fro C++ (soon to be called
C++/CLI) in the same module. So one option is to have functions free
functions in an unmanaged module call on member functions in an MC++ class
which call on the requisite functions in your C# class. This works best when
you think in terms of interfaces. Don't think of sharing managed types with
unmanaged code.

Regards,
Will
 
The light bulb is beginning to flicker.
.... and I acknowledge there are larger design issues here, even if I don't
understand them yet.
I am still looking for keywords and keynote concepts in the answers to my
questions.
I realize I am not asking the right questions yet.
Is CLI common language interface?

Thanks Will.
 
Back
Top