-1

So I have a board running Windows 10 IoT and using a UWP application for it. I have the drivers for the board specific IO running on the board, but now I am looking to use the library provided to access and use these IO. If you wish to also see the library that was provided find it here (https://www.rtd.com/software/CM/CR/aDIO_windows_v05.04.00.zip)

Since I am more familiar with just adding a .dll file as a reference and going on my way, I tried that first. Got an error about COM components or something like that. So I contacted the board manufacturer about how I should proceed with installing this library. They sent me to this page (https://learn.microsoft.com/en-us/cpp/porting/how-to-use-existing-cpp-code-in-a-universal-windows-platform-app?view=vs-2019#targetText=Porting%20a%20C%2B%2B%20Library%20to%20a%20Windows%20Runtime%20Component&targetText=You%20can%20use%20it%20in,app%20code%2C%20regardless%20of%20language) which makes sense because the drivers are in c++ library.

I followed the To port a native DLL to the UWP without creating a new project section. I got to step 6 without and issues. When rebuilding after step 6, I got an error saying Using static version of the C++ runtime library is not support (http://prntscr.com/pazh69). Looked it up and it said I needed to change an additional setting.

So I did Right-Click on Project>Properties>C/C++>Code Generation and switch RunTime Library to /MDd. That seemed to resolve that error. Tried rebuilding again.

Next I was getting an issue about the .c source files not being able to be used with the /ZW flag I enabled earlier from the microsoft guide. I therefore went in to each of the source files and removed the /ZW flag from just them.

Finally, rebuilt again and got this error: http://prntscr.com/pazidr

the unresolved external symbol error. I have not been able to find an effective solution for this, and because this is obviously not my library, am very confused at where to start to even try and debug that.

I guess my overall question is: 1. Is it possible to convert this library for use in UWP? 2. Is is an issue that the source files are .c files and not .cpp files? 3. Is there a fix to this particular problem that allow me to have a working UWP library? 4. Is there a different/better process for doing what I am trying to accomplish?

Thank you so much in advance, I know its a hefty question.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
BWhelan
  • 378
  • 1
  • 5
  • 16
  • 1
    Possible duplicate of [How to access registry key in a UWP app?](https://stackoverflow.com/questions/48899692/how-to-access-registry-key-in-a-uwp-app) – Richard Critten Sep 25 '19 at 21:20
  • UWP is Microsoft's effort to provide an OS api that's going to last for the next 30 years. Bad old practices in the winapi that caused relentless misery to programmers and users alike were thoroughly eliminated, the registry was near the top of that list. – Hans Passant Sep 25 '19 at 22:48

1 Answers1

4

UWP apps do not support the registry APIs, and cannot use them. You need to remove those when building for UWP. Consider something like:

#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP) 
// Do stuff that calls Reg* APIs
#endif

UWP apps don't use CreateFile which actually does a lot of things besides file operations. If you are using it to open files on disk you have access to as a UWP, then you can use something like:

// Reading a file
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
   HANDLE file = CreateFile2(fileName, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, nullptr);
#else
   HANDLE file = CreateFileW(fileName, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
#endif

// Creating a file for writing
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
    HANDLE file = CreateFile2(fileName, GENERIC_WRITE | DELETE, 0, CREATE_ALWAYS, nullptr);
#else
    HANDLE file = CreateFileW(fileName, GENERIC_WRITE | DELETE, 0, nullptr, CREATE_ALWAYS, 0, nullptr);
#endif

You are still subject to the UWP file access restrictions. See File access permissions

If you are using CreateFile to access a device, then that's not supported for UWP apps. There are some limited scenarios where you can access a device driver from UWP, but you'll need to write a different implementation using Windows Runtime APIs in any case. See Device Access API

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81