locked
how to debug a native dll linked to a metro app

    Question

  • I have built a metro app using VS 2011 Express edition. This app is linked to a native dll. Is it possible to debug the native DLL?


    Wednesday, March 28, 2012 6:29 AM

Answers

  • > Will the VS2011 project allow the usage of blacklisted Win32 APIs in the DLL or will it list them as errors at compile time?

    That depends on the project type. Metro projects create with the project wizards in Dev11 have a preprocessor definition: WINAPI_FAMILY=WINAPI_FAMILY_APP. Windows 8 SDK header files ifdef Win32 functions so that this define excludes API that aren't compatible with Metro.

    If you are using an older native project, add this define and the compiler will tell you if you are using a non-Metro compatible API.

    If this doesn't resolve your error, please post the callstack along with the error message.

    Friday, March 30, 2012 8:00 PM
    Moderator

All replies

  • Hello,

    If you have access to the source of the dll or at least the symbols then you should be able to debug the dll. Was the Dll built for metro as well?

    I may need more information befor providing any additional input.

    Thank You,
    Best Regards,

    Joseph

    Wednesday, March 28, 2012 10:27 AM
  • Hi Joseph,

    Thanks for the info! 

    This is actually a DLL thats required to be ported for metro apps as it uses some of the blacklisted win32 APIs. Currently, I am able to load it through my metro app. However, certain function calls of the DLL fail (return error code) probably because they are internally calling Win32 APIs (not sure).

    Since this is a huge dll, its difficult to identify the list of blacklisted APIs being used, so we thought debugging it would help us. It would be good to have your views on this.

    Finally, I do have access to the source and will try to debug it.

    Thanks Again!

    Wednesday, March 28, 2012 11:26 AM
  • Hello,

    I guess you could use Dependency Walker to track the function that are called by the Dll:

    http://www.dependencywalker.com/

    From the following document you can extrapolate a list of the APIs that are allowed in Metro Style applications:

    http://msdn.microsoft.com/en-us/library/windows/apps/br205757.aspx

    Hope this helps.

    Thank You,

    Joseph

    • Proposed as answer by Joseph Viola Wednesday, March 28, 2012 11:40 AM
    • Unproposed as answer by Ups_Sfnt Thursday, March 29, 2012 10:51 AM
    Wednesday, March 28, 2012 11:40 AM
  • Hi again,

    I forgot to mention that, is also able to catch exceptions if they occur.

    Also, I you manage to convert the project of the DLL to VS11, stepping through it will be a lot easier, but it isn't necessary.

    Thank You,

    Joseph

    Wednesday, March 28, 2012 11:46 AM
  • Hi Joseph,

    Thanks a lot for the detailed info.

    What catches exceptions (Some text  is missing in your sentence above)?

    Also, I could not understand why and how stepping through a DLL built using VS11 proj would be easier? Will the VS2011 project allow the usage of blacklisted Win32 APIs in the DLL or will it list them as errors at compile time?

    I would like to share that I have used exactly the same method mentioned by you (dependency walker along with MSDN listing) to identify the blacklisted APIs. We have realized that we will need to block some of the functionality provided by the native DLL as certain blacklisted Win32 APIs do not have any alternatives.

    Thanks again!

    Wednesday, March 28, 2012 12:10 PM
  • Hi Joseph,

    I tried to debug the native DLL using its debug version. However, on adding the debug version of the dll, its raises an exception

    "System.DllNotFoundException: Unable to load DLL 'ABC.dll': Invalid access to memory location. (Exception from HRESULT: 0x800703E6)"

    Please note that the release version of this DLL loads sucessfully.

    Can you please help?

    Regards,

    Upasana


    • Edited by Ups_Sfnt Thursday, March 29, 2012 10:50 AM
    Thursday, March 29, 2012 5:00 AM
  • > Will the VS2011 project allow the usage of blacklisted Win32 APIs in the DLL or will it list them as errors at compile time?

    That depends on the project type. Metro projects create with the project wizards in Dev11 have a preprocessor definition: WINAPI_FAMILY=WINAPI_FAMILY_APP. Windows 8 SDK header files ifdef Win32 functions so that this define excludes API that aren't compatible with Metro.

    If you are using an older native project, add this define and the compiler will tell you if you are using a non-Metro compatible API.

    If this doesn't resolve your error, please post the callstack along with the error message.

    Friday, March 30, 2012 8:00 PM
    Moderator