locked
C# Adding Capabilities to a dll Visual studio RRS feed

  • Question

  • Hello I have a testprogram with smartcards made in c#, in order to get it working I needed to add

     <Capability Name="SharedUserCertificates" />

    in the projects Package.appxmanifest.

    The problem however is that I need this functionality inside a dll that is being imported by a c++ project. When I create a c#-project of type Class Library (Portable for Universal Windows 8.1) Which I believe is what I need, this project has no Package.appmanifest where I can add capabilities. Neither obviously has the c++ project. Anyone has any ideas about where and how to add this capability to this project.

    Friday, December 9, 2016 6:01 PM

All replies

  • Hi Johannes,

    Welcome to the MSDN forum.

    Refer to your description, your issue is about the development of UWP project. Since our forum is to discuss Visual Studio WPF/SL Designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System, and Visual Studio Editor, I will help you move it to the appropriate forum: Windows and Windows phone apps > Developing Universal Windows apps for dedicated information, you will get a more professional support from there, thank you for your understanding.

    Best regards,

    Sara


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 12, 2016 5:50 AM
  • @Johannes HC,

    You shouldn't add this capability in your class library. We always add the capability in our main project and import the code from class library. Can you make sure that the project which use your class library will use this capability?

    Best regards,

    Barry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Azat Tazayan Monday, December 12, 2016 6:55 AM
    Monday, December 12, 2016 6:02 AM
  • Hi ,

    I'm agree with Barry. Remember that the DLL's always loading to the application process  memory, therefore DLL's can only have the same access and "capabilities" which have consumed ".EXE" . Therefore the manifest apply only to EXE


    Make the community better together

    Monday, December 12, 2016 6:55 AM
  • Hello

    Thank you for your reply. I am not sure what you mean with "Can you make sure that the project which use your class library will use this capability?"

    What I want to do is this:
    I have this credential provider test: (in c++)
    https://code.msdn.microsoft.com/windowsapps/V2-Credential-Provider-7549a730

    I have managed to import c# dlls into my own test credential provider, however when I try to use a dll that uses the virtual smart card functionality ( a UWP dll? ). This does not work. Which I suppose makes sense, since I have not added the capability anywhere.
    If I understand you correctly the right place to add it should be in the c++-project which imports the smart card-dll then?

    I realize you may not be a c++ expert but do you have any idea about how to do this?

    The credential provider results in a dll, by the way, not sure if this matters.

    Thinking about it, maybe this question needs to be moved again.I think my main question is how to add references to the credential provider sample above.when I press add references there are no options there. I think I need to add a "windows"-reference.



    • Edited by Johannes HC Monday, December 12, 2016 10:21 AM
    Monday, December 12, 2016 8:51 AM
  • @Johannes HC,

    What I mean is like this:

    You have your own test credential provider and I need to know it's project type. As the base project we always add our capability there. Even it is C++/CX UWP app we still can add this capability in our app.

    I've checked your above sample, actually I can see that it is just a classic desktop app. So it is not a general purpose app which can use UWP capabilities.

    I can think about two ways for you:

    1. Develop a different app which is a UWP C++/CX app, it will have the capability file by default

    2. Consider convert your app. We have desktop bridge which can convert a exist installer(msi or exe) to an appx. After you convert your app you will be able to see a appmanifest.xml and you can see it add runfulltrust capability by default. You can use your capability there and if you have add your dll reference in your desktop app you will be able to run the above UWP code.

    Anyway, in the past Windows 8 time, we can config our main app to use some supported winrt API in our app, for which you can search for a blog called "Using Windows 8* WinRT API from desktop applications". You can see here about the supported api list:

    https://msdn.microsoft.com/en-us/library/windows/desktop/dn554295(v=vs.85).aspx

    I guess actually you mean you want to call these supported APIs from your project.

    PS: As for now, if you want to get the benefit from UWP. I recommend that you can consider using desktop bridge for your classic desktop apps.

    Best regards,

    Barry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Barry Wang Tuesday, December 13, 2016 2:22 PM
    Tuesday, December 13, 2016 2:21 PM
  • Thank you, you are a great help and I believe I have a good start now.
    I followed the instructions under C++ / CX Solution in:
    https://software.intel.com/en-us/articles/using-winrt-apis-from-desktop-applications

    I Now Have a testprogram with the following code and no compilation errors.

    #include "stdafx.h"

    #ifndef WIN32_NO_STATUS

    #include <ntstatus.h>

    #define WIN32_NO_STATUS#endif #include <unknwn.h> #using <Windows.winmd> #using <Platform.winmd> using namespace Windows::ApplicationModel; using namespace Platform; using namespace Windows::Devices::SmartCards; using namespace Windows::Foundation; using namespace Windows::Globalization::NumberFormatting; using namespace Windows::Storage::Streams; using namespace Windows::Security::Cryptography; using namespace Windows::Security::Cryptography::Core; using namespace Windows::UI::Xaml; using namespace Windows::UI::Xaml::Controls; [STAThread] int main() { try { Windows::Devices::SmartCards::SmartCardPinPolicy^ pinPolicy = ref new Windows::Devices::SmartCards::SmartCardPinPolicy(); pinPolicy->MinLength = 5; pinPolicy->MaxLength = 10; IBuffer^ newadminkey = CryptographicBuffer::GenerateRandom(124); SmartCardProvisioning::RequestVirtualSmartCardCreationAsync("test",newadminkey, pinPolicy); } catch (Exception^ ex) { MessageBoxW(NULL, ex->ToString()->Data(), NULL, MB_OK); }     return 0; }



    However I get Element not found on the line SmartCardProvisioning::RequestVirtualSmartCardCreationAsync("test",newadminkey, pinPolicy);

    Just to clarify I do get the offical smart card sample to register and list cards so it is enabled on my computer.

    Any ideas why I get element not found?


    One more question while I am at it.
    In the tutorial there is no mention of the package.appxmanifest, but it seems to me I while need this file in the desktop application project that is using UWP?
    Can I create such a file somehow?


    • Edited by Johannes HC Thursday, December 15, 2016 2:24 PM
    Wednesday, December 14, 2016 11:33 AM
  • @Johannes,

    For your first question:

    >>Just to clarify I do get the offical smart card sample to register and list cards so it is >>enabled on my computer.
    >>Any ideas why I get element not found?

    I've checked the class your used and compared it with support API in desktop and I see the following just from MSDN document:

    The class SmartCardProvisioning support store apps only however other class like Uri said it is supported on desktop at the bottom of MSDN page. So personally I think this API may not supported by your desktop app. However as I haven't tested it I cannot 100% sure about this. 

    >>In the tutorial there is no mention of the package.appxmanifest, but it seems to me I while need this file in the desktop application project that is using UWP?

    Actually the file is supported on all Winrt related apps. Such as windows 8 store app and also UWP apps. Other kind of apps does not need this package.appxmanifest. 

    Best regards,

    Barry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 16, 2016 6:56 AM
  • Hello

    Thank you again.
    But do I understand you correctly if I say it probably is not possible to get the smart card functionality into the sample credential provider then?

    That would be a shame since I dont think I have the skills to create my own credential provider from scratch.

    I really hope there is some way to take the existing one and use the smart card functionality in that one?

    Friday, December 16, 2016 3:34 PM
  • @Johannes HC,

    Yep maybe you cannot use this API in your desktop app. So why not use the classic desktop smartcard API instead of thinking about using the UWP API?

    Although I'm not familiar with this topic, I think this is more straightforward and will easy for your to integrate.

    Best regards,

    Barry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, December 20, 2016 8:05 AM
  • Hello

    Well that makes sense I suppose. The reason is probably just that I found that working sample and it seemed like a good place to start from.
    It feels easier to start working from code examples than just APIs, but I will look into that.

    You think this looks right?
    https://msdn.microsoft.com/en-us/library/windows/desktop/hh707160(v=vs.85).aspx

    I have to admit I do not understand how to use it. I need to donwload that Vscmgr.lib from somewhere? Or is it already on my computer?

    • Edited by Johannes HC Wednesday, December 21, 2016 9:26 AM
    Wednesday, December 21, 2016 8:27 AM
  • @Johannes HC,

    Hmm, for this desktop issue I cannot share you a reasonable suggestion. What you consult on a classic desktop forum or C++ forum. 

    For ITpmVirtualSmartCardManager, actually you don't need to do anything. You just need to add the following line in your project:

    #include "Tpmvscmgr.h"

    And then you will be able to use the things you want.

    Best regards,

    Barry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 23, 2016 1:56 AM