How to declare and link to RoInitialize,RoUninitialize,RoGetActivationFactory and HSTRING Functions in Mingw Gcc

廉价感情. 提交于 2019-12-05 06:41:41

The import library for these functions is runtimeobject.lib (which the MSDN documentation fails to mention). It can be found in the Windows SDK for Windows 8.

The library you need to link against is windowsapp.lib (and only this lib, remove all others).

Windowsapp.lib is an "umbrella" lib that provides the exports for the UWP APIs. Linking to Windowsapp.lib will add to your app dependencies on dlls that are present on all Windows 10 device families.

https://msdn.microsoft.com/en-gb/windows/uwp/get-started/universal-application-platform-guide#writing-code

For delay loading, you will need to load api-ms-win-core-winrt-l1-1-0.dll. This is listed as a Windows 8.1 API set, however if you check the documentation for RoInitialize it says the minimum supported client is Windows 8. Assuming you use LoadLibrary and GetProcAddress, it shouldn't matter.
https://msdn.microsoft.com/en-us/library/windows/desktop/dn933214(v=vs.85).aspx

The actual DLL that the method is implemented in is combase.dll, but they use the new API DLLs as a level of indirection so that they are free to change or update these in the future.

For future reference, the API sets for Windows 10 (UWP) are listed on a separate page to the API sets for Windows 8 (and 8.1). The stub DLL (for delay loading) is the same. https://msdn.microsoft.com/library/windows/desktop/mt186421

If you don't have the import lib that contains RoInitialize, you'll need to use LoadLibrary/GetProcAddress to resolve the types.

Run-time link it like this:

#include <roapi.h>

namespace
{
    FARPROC LoadComBaseFunction(const char* function_name)
    {
        static HMODULE const handle = ::LoadLibraryA("combase.dll");
        return handle ? ::GetProcAddress(handle, function_name) : nullptr;
    }

    decltype(&::RoInitialize) GetRoInitializeFunction()
    {
        static decltype(&::RoInitialize) const function = reinterpret_cast<decltype(&::RoInitialize)>(LoadComBaseFunction("RoInitialize"));
        return function;
    }
}


HRESULT RoInitialize(RO_INIT_TYPE init_type)
{
    auto ro_initialize_func = GetRoInitializeFunction();
    if (!ro_initialize_func)
        return E_FAIL;

    return ro_initialize_func(init_type);
}

Source

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!