Answered by:
Metro Style App How to load Win32 dll?

Question
-
1.Metro Style App Whether the load Win32 dll?
2.if it can ,it will how to operate?
3.I use "LoadPackagedLibrary" always prompt specified module not found.
Friday, September 23, 2011 4:36 AM
Answers
-
LoadPackagedLibrary/GetProcAddress should work for classic dlls with exports too. You want to make sure that the code in the dll is compiled against the Metro SDK and the final dll passes the App certification since it's going to get packaged in inside your appx.
Marian Luparu
Visual C++- Marked as answer by DavidLambMicrosoft employee, Moderator Tuesday, October 25, 2011 5:00 PM
Tuesday, September 27, 2011 1:16 AM
All replies
-
1.Metro Style App Whether the load Win32 dll?
2.if it can ,it will how to operate?
3.I use "LoadPackagedLibrary" always prompt specified module not found.
Only a subset of the Win32 API is supported under WinRT.See http://msdn.microsoft.com/en-us/library/windows/apps/br205757
http://blog.voidnish.comFriday, September 23, 2011 12:33 PM -
Sandbox only allows Metro Style app to access files in the same folder where app resides.
LoadPackagedLibrary can load WinRT Component DLL ONLY.
LoadLibrary is not supported in Metro app.
Friday, September 23, 2011 5:29 PM -
LoadPackagedLibrary/GetProcAddress should work for classic dlls with exports too. You want to make sure that the code in the dll is compiled against the Metro SDK and the final dll passes the App certification since it's going to get packaged in inside your appx.
Marian Luparu
Visual C++- Marked as answer by DavidLambMicrosoft employee, Moderator Tuesday, October 25, 2011 5:00 PM
Tuesday, September 27, 2011 1:16 AM -
LoadPackagedLibrary/GetProcAddress should work for classic dlls with exports too. You want to make sure that the code in the dll is compiled against the Metro SDK and the final dll passes the App certification since it's going to get packaged in inside your appx.
Marian Luparu
Visual C++Hi, I just tried to link a win32 dll in metro app, however it always failed.
HINSTANCE LibHandle; LibHandle = LoadPackagedLibrary(L"Win32dll", 0); DWORD error = GetLastError();
I put the Win32dll.dll under metro app exe output folder, and it will failed with error code 126. "Specifed module not found".Anything additional need to be done? thx
- Edited by Dong, Yi Monday, October 31, 2011 5:58 AM
Monday, October 31, 2011 5:57 AM -
Hi Dong,
Keeping the Win32 DLL in the exe output folder will not suffice. When you create a Metro style app, your app (the exe and the associated stuff) gets packaged into an AppX package and is deployed by VS when you try to run the app.
You should try adding the Win32 DLL to the Application project (Right Click Project -> Add Existing Item)
And then try re-running your app.
Thanks
Raman, Visual C++- Proposed as answer by Raman Sharma Monday, October 31, 2011 6:13 AM
Monday, October 31, 2011 6:13 AM -
Hi Dong,
Keeping the Win32 DLL in the exe output folder will not suffice. When you create a Metro style app, your app (the exe and the associated stuff) gets packaged into an AppX package and is deployed by VS when you try to run the app.
You should try adding the Win32 DLL to the Application project (Right Click Project -> Add Existing Item)
And then try re-running your app.
Thanks
Raman, Visual C++
Hi raman, I tried to add the dll into metro project, pls see snapshot.you can see Win32dll.dll is already included in MetroTest project. However it still can't load it.
Can u help me on this? thx
- Edited by Dong, Yi Monday, October 31, 2011 7:06 AM
Monday, October 31, 2011 7:01 AM -
Can you share your VS solution with me?
sharma dot raman at microsoft
Monday, October 31, 2011 7:31 AM -
already sent to u, pls check, regardsMonday, October 31, 2011 8:01 AM
-
Dong: I was able to reproduce the problem you are seeing. The problem is that the DLL never gets added to the final app package. And as a result, at runtime the application process was not able to find the DLL.
This seems to be a bug and I have let the team know about this.
Thanks
RamanMonday, October 31, 2011 11:12 PM -
>> The problem is that the DLL never gets added to the final app package. And as a result, at runtime the application process was not able to find the DLL.
Any work-around to this issue?
Jennifer
Thursday, November 10, 2011 11:38 PM -
Yes. Please look at the project here.
The workaround is to copy the DLL right next to the C++ project file, add it to the project from VS and then in the properties, set "content=true".
Thanks
Raman Sharma | Program Manager, Visual C++ | @rasharm_msft
(if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others)- Proposed as answer by Raman Sharma Friday, November 11, 2011 3:27 PM
Friday, November 11, 2011 1:40 AM -
Thanks!
Yes, it works. I was using the VS2011 preview express only and got strange errors when adding the DLL. The vs11 exp did not even load the win32 dll.
But after installing the ultimate, it works now.
Another question about the sample - you have used the "LoadPackagedLibrary()",is it necessary? For desktop app, as long as the .dll is on the path, it can be found and load automatically.
thanks again.
Jennifer
btw "propose as Answer" is not available under your posting. Looks like a forum bug.
JenniferFriday, November 11, 2011 10:27 PM -
For metro style apps, you cannot call LoadLibrary on DLLs from random locations on the disk. Instead you have to LoadLibraryPackage only for the DLLs that you have explicitly added to your app's package.
Thanks
Raman Sharma | Program Manager, Visual C++ | @rasharm_msft
(if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others)Friday, November 11, 2011 10:51 PM -
btw "propose as Answer" is not available under your posting. Looks like a forum bug.
Jennifer
That's because it's already been proposed as an answer.
http://blog.voidnish.comFriday, November 11, 2011 11:10 PM -
My dll is built with older VS (probably vs2005 or 2008). When adding it to the metro C++ project, I got the following errors:
1>MakePri : error 0x80004005: Processing Resources 1>MakePri : error 0x80004005: MakePri with error: Unspecified error
So I can not use any existing dll built from previous VS.
JenniferSaturday, November 12, 2011 12:35 AM -
My dll is built with older VS (probably vs2005 or 2008). When adding it to the metro C++ project, I got the following errors:
What kind of DLL is this?
1>MakePri : error 0x80004005: Processing Resources
1>MakePri : error 0x80004005: MakePri with error: Unspecified error
In general it has never been possible to mix modules created wirh different versions of the compiler (except for COM DLL's, and DLL's with a simple C interface).
David Wilkinson | Visual C++ MVPSunday, November 13, 2011 11:58 AM -
my dll is the later: simple C interface DLL.
If I linked it using the static .lib, it works. But the .dll version does not. I could not add it to the package.
JenniferMonday, November 14, 2011 7:26 PM -
Update to this error:
1>MakePri : error 0x80004005: Processing Resources
1>MakePri : error 0x80004005: MakePri with error: Unspecified errorI used the sane "MetroTest" on a different directory, after adding myMath.dll, the error does not happen any more.
But ... now the cert tool (wslkui.exe) can not find the MetroTest app any more. It is a known issue - cert-tool bug.
Jennifer
Wednesday, November 16, 2011 6:21 PM -
Hello Raman
Sorry to trouble you but as im learning few things with windows ,so coming from linux/android background.i need some help.
I tried the project from above link to open in VS 2011 ultimate Beta with .Net 4.5...and while building it is giving me the following error.
2>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.Targets(1546,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "windows.ui.xaml". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
2>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.Targets(1546,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "windows.web.atompub". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
2>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.Targets(1546,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "windows.web.syndication". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
2> pch.cpp
2>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstring(100): error C2857: '#include' statement specified with the /Ycstdafx.h command-line option was not found in the source file
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Can you please help to resolve the issue.
Thursday, May 10, 2012 9:18 PM -
Shashikant,
The project Raman posted was a designed for the Windows 8 Developer Preview. It will not build or run in the Windows 8 Consumer Preview.
--Rob
- Proposed as answer by Shashikant Kale Thursday, May 10, 2012 10:46 PM
Thursday, May 10, 2012 10:40 PMModerator