locked
How to load Win32 dll for Metro style App

    Question

  • I have several win32 dlls, which are written in native c++ but don't invoke any win32 API. These dlls implement the core logic for my application. Now I want to create a new Metro style App, which need to invoke the api exposed from these existing Win32 dlls. I know I need to compile these Win32 dlls with VS2012.

    Before I porting these dlls to VS2012, I create a simplest Win32 dll for testing. This dll just exposed a Add() api like this:

    extern "C" _declspec(dllexport) int Add(int x,int y);

    And I create a Windows store App, which load the Win32 dll and invoke the Add() function like below:

    extern "C" _declspec(dllimport) int Add(int x,int y);
    #pragma comment(lib,"E:\\Test_proj\\win8\\JCFHelloWorldTest\\Debug\\JCFHelloWorldTest\\Win32DllTest.lib")
    
    using namespace JCFHelloWorldTest;
    //
    
    int JCFTest::AddTest()
    {
    	HINSTANCE handle;
    	//handle = LoadPackagedLibrary(L"E:\\Test_proj\\win8\\JCFHelloWorldTest\\Debug\\JCFHelloWorldTest\\Win32DllTest.dll",0);
    	int result = Add(9,0);
    	return result;
    }

    The Metro App build successfully. When run this App, I get this error.

    So my here are my questions:

    Q1: Can I load Win32 dll in the Metro style App?

    Q2: If yes, What is the right way to load Win32 dll for Metro App?

    Q3: If no, do I need to rewrite my Win32 dll with c++/cx?

    Can any Microsoft people answer my quetion? Thank you in advance!

    Eason.

    Monday, October 29, 2012 9:44 AM

Answers

  • Hi EasonHoo,

    Most probably, Win32DllTest.dll (which you are trying to load)  depends on other dll/dlls which is not available in the desired directory.

    Please check by using Dependency Walker   whether every component is available and compatible.

    Please check the debug window of your apps for more specification of this error. Check handle is NULL or not. If NULL please see the last error ( GetLastError() )

    HINSTANCE DLLHandler; DLLHandler = LoadPackagedLibrary(L"Test.dll", 0); DWORD error = GetLastError(); OutputDebugStringW( error.ToString()->Data() );


    Finally you should add the dll in following way,

    Right click on your project solution explorer and go Add -> Existing item -> add dll from your desired directory.

    Right click on your dll file and set Content = Yes.

    See whether your dll is available or not in Appx directory under debug/release folder.





    Wednesday, October 31, 2012 2:45 AM

All replies

  • There is nearly no difference in building and linking dynamic libraries (.dll) between Metro app and traditional win32 app. In building .dll, you should check "Windows Store support".
    Monday, October 29, 2012 10:19 AM
  • This is an English language forum. It would help if you would translate the error into English.

    That said, did you mark the DLL as Content to be copied into the app package when the package is built? LoadPackagedLibrary loads custom DLLs which are included in the app's package. The app cannot use an explicit path to load a DLL from elsewhere.

    --Rob

    Monday, October 29, 2012 5:27 PM
    Owner
  • Thanks for your reply.

    The error message is "The application is not started".

    And how to mark the DLL as Content to be copied into the app package?

    Regards,

    Eason

    Tuesday, October 30, 2012 5:09 AM
  • You can mark that in the item's properties in the Solution Explorer.

    Tuesday, October 30, 2012 5:36 AM
    Owner
  • Hi EasonHoo,

    Most probably, Win32DllTest.dll (which you are trying to load)  depends on other dll/dlls which is not available in the desired directory.

    Please check by using Dependency Walker   whether every component is available and compatible.

    Please check the debug window of your apps for more specification of this error. Check handle is NULL or not. If NULL please see the last error ( GetLastError() )

    HINSTANCE DLLHandler; DLLHandler = LoadPackagedLibrary(L"Test.dll", 0); DWORD error = GetLastError(); OutputDebugStringW( error.ToString()->Data() );


    Finally you should add the dll in following way,

    Right click on your project solution explorer and go Add -> Existing item -> add dll from your desired directory.

    Right click on your dll file and set Content = Yes.

    See whether your dll is available or not in Appx directory under debug/release folder.





    Wednesday, October 31, 2012 2:45 AM
  • Hi Eason

    I met with a similar problem as yours. Have you fixed it yet? Could you pls explain how?

    Thanks very much

    Tuesday, November 13, 2012 6:41 AM