Why do I get this error when I run my project as a .DLL but not as a .EXE

Forrest Crawford 60 Reputation points
2024-06-10T22:16:12.87+00:00

I've got a .dll project in which I'm utilizing Direct 2D to draw on a window. For some reason, one line is continually giving me errors when I attempt to run it:

// Create a Direct2D factory.
hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_pDirect2dFactory);

The problem is that this line works fine when I run the project as a .exe. I copied and pasted the whole page over from the working project to the new .dll but it now gives me this error:

Severity Code Description Project File Line Suppression State Details Error LNK2019 unresolved external symbol D2D1CreateFactory referenced in function "long __cdecl D2D1CreateFactory(enum D2D1_FACTORY_TYPE,struct _GUID const &,void * *)" (?D2D1CreateFactory@@YAJW4D2D1_FACTORY_TYPE@@AEBU_GUID@@PEAPEAX@Z) DxfDrawer C:\Users\REDACTED\source\repos\Direct2DinWPF\DxfDrawer\DxfDrawer.obj 1

Here is a link to my project. The line in question is line 126.

git

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,647 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,754 questions
{count} votes

Accepted answer
  1. RLWA32 45,691 Reputation points
    2024-06-11T00:13:43.63+00:00

    For some reason the linker was not searching d2d1.lib which caused the LNK2019 error. If you add d2d1.lib to the linker inputs in the project property page instead of using the pragma directive it will build successfully.

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.