gpt4 book ai didi

c++ - 我无法从 DirectWrite 获取此示例以在 V2015 中运行

转载 作者:太空宇宙 更新时间:2023-11-04 16:05:41 24 4
gpt4 key购买 nike

我从这个 page 得到了下面的例子在 MS 中,但由于此消息,代码未链接:

错误 LNK2019:未解析的外部符号 __imp__DWriteCreateFactory@12 在函数 _wmain 中引用

我重复下面的代码以方便阅读:

#include <dwrite.h>
#include <string.h>
#include <stdio.h>
#include <new>

// SafeRelease inline function.
template <class T> inline void SafeRelease(T **ppT)
{
if (*ppT)
{
(*ppT)->Release();
*ppT = NULL;
}
}

void wmain()
{
IDWriteFactory* pDWriteFactory = NULL;

HRESULT hr = DWriteCreateFactory(
DWRITE_FACTORY_TYPE_SHARED,
__uuidof(IDWriteFactory),
reinterpret_cast<IUnknown**>(&pDWriteFactory)
);

IDWriteFontCollection* pFontCollection = NULL;

// Get the system font collection.
if (SUCCEEDED(hr))
{
hr = pDWriteFactory->GetSystemFontCollection(&pFontCollection);
}

UINT32 familyCount = 0;

// Get the number of font families in the collection.
if (SUCCEEDED(hr))
{
familyCount = pFontCollection->GetFontFamilyCount();
}

for (UINT32 i = 0; i < familyCount; ++i)
{
IDWriteFontFamily* pFontFamily = NULL;

// Get the font family.
if (SUCCEEDED(hr))
{
hr = pFontCollection->GetFontFamily(i, &pFontFamily);
}

IDWriteLocalizedStrings* pFamilyNames = NULL;

// Get a list of localized strings for the family name.
if (SUCCEEDED(hr))
{
hr = pFontFamily->GetFamilyNames(&pFamilyNames);
}

UINT32 index = 0;
BOOL exists = false;

wchar_t localeName[LOCALE_NAME_MAX_LENGTH];

if (SUCCEEDED(hr))
{
// Get the default locale for this user.
int defaultLocaleSuccess = GetUserDefaultLocaleName(localeName, LOCALE_NAME_MAX_LENGTH);

// If the default locale is returned, find that locale name, otherwise use "en-us".
if (defaultLocaleSuccess)
{
hr = pFamilyNames->FindLocaleName(localeName, &index, &exists);
}
if (SUCCEEDED(hr) && !exists) // if the above find did not find a match, retry with US English
{
hr = pFamilyNames->FindLocaleName(L"en-us", &index, &exists);
}
}

// If the specified locale doesn't exist, select the first on the list.
if (!exists)
index = 0;

UINT32 length = 0;

// Get the string length.
if (SUCCEEDED(hr))
{
hr = pFamilyNames->GetStringLength(index, &length);
}

// Allocate a string big enough to hold the name.
wchar_t* name = new (std::nothrow) wchar_t[length+1];
if (name == NULL)
{
hr = E_OUTOFMEMORY;
}

// Get the family name.
if (SUCCEEDED(hr))
{
hr = pFamilyNames->GetString(index, name, length+1);
}
if (SUCCEEDED(hr))
{
// Print out the family name.
wprintf(L"%s\n", name);
}

SafeRelease(&pFontFamily);
SafeRelease(&pFamilyNames);

delete [] name;
}

SafeRelease(&pFontCollection);
SafeRelease(&pDWriteFactory);
}

因为这是我在 DirectWrite 中的第一步,所以我对上面提到的错误消息一无所知。

最佳答案

MSDN page on DWriteCreateFactory声明您必须包含 dwrite.h(假设您在代码编译后已经完成)和链接 dwrite.lib

您必须将该库明确添加到您的 VisualStudio 项目中。

关于c++ - 我无法从 DirectWrite 获取此示例以在 V2015 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36068398/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com