-
Setup: I need to change the cursor as the user interacts with a Grid. I have sub-classed the Grid in order to provide access to its ProtectedCursor:
I have created a .res file containing cursors (.cur) in a separate C++ DLL project and added that resource file as a Win32Resouce to my Windows App SDK/WinUI 3 desktop application project. As a test, I am using the PointerPressed event from the subclassed Grid to change the cursor:
However, the effect of the code above is to simply load a built-in cursor. Indeed, as I play with the resource id value, setting it to values in the range [100, 118] I see a variety of 'standard' cursors including some that are not in the CoreCursorType enumeration. The same .res file works in a UWP application, so I know the problem is not with the resources... If I change the resource id of one of the cursors to, say, 200, recreate the .res file and try to create a CoreCursor using that resource Id, I get a System.Runtime,InteropServices.COMException: The Specified resource name cannot be found in the image file. Why when creating a new CoreCursor with CoreCursorType.Custom, and a uint resource Id am I seeing build-in cursors? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
I cannot even use Win32Resource in the .csproj to add a .res on my configuration (Windows 10 21H1, unpackaged) |
Beta Was this translation helpful? Give feedback.
-
Some resource IDs like 100, 101... are reserved by system resources (in the current executable module), which is why you see it loading syscursors at those IDs and failing with less generic IDs. When you call If you want to boil it down a little more, I'd suggest trying to load a resource from that linked DLL directly using LoadCursor, LoadResource, or a similar Win32 Resource API to deduce if the resources are properly linked to the project. Imo while resource linking works great in a C++ Proj, the flow of linking Win32 resources in a C# project is not particularly intuitive or consistent, and I've had similar frustrations 😞 You may be able to directly create an InputCursor from your resource by calling InputDesktopResourceCursor.CreateFromModule and passing the name of the DLL as the module. If the DLL is loaded, LoadCursor should be able to get the right resource from it. CreateFromCoreCursor is simply a convenience method that does nothing which InputCursor can't already do. |
Beta Was this translation helpful? Give feedback.
-
I had the same issue, my cursors refused to load, but I fixed it like this: First, To get the .res file in my c# dll, I specify Second, I have validated with ResourceHacker that a cursor with the expected id exists in the DLL. I set the cursor ID in the DLL outside of the 1xx range to avoid the system cursors. Third, instead of using CoreCursor, I call var cursor = InputDesktopResourceCursor.CreateFromModule("App1.dll", 217); That is all that it took for me, the cursor now shows as expected. |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for the solution |
Beta Was this translation helpful? Give feedback.
I had the same issue, my cursors refused to load, but I fixed it like this:
First, To get the .res file in my c# dll, I specify
<Win32Resource>MyResources.res</Win32Resource>
.And I removed the
<Manifest Include="$(ApplicationManifest)" />
and<ApplicationManifest>app.manifest</ApplicationManifest>
properties.To add the manifest back, I added the manifest to my MyResources.res file, via "Import", and set the type to "RT_MANIFEST".
On the res file I left the the Build Action as "None" and "Copy to Output Directory" as "Do not copy".
Second, I have validated with ResourceHacker that a cursor with the expected id exists in the DLL. I set the cursor ID in the DLL outside of the 1xx range to …