Direct2d dilemma
-
I've been trying to get the example code at https://msdn.microsoft.com/en-us/library/windows/desktop/dd370994%28v=vs.85%29.aspx[^] to work for me. It's a struggle for me. One problem I think I've narrowed down is with the line
// Create the window. m\_hwnd = CreateWindow( L"D2DDemoApp", L"Direct2D Demo App", WS\_OVERLAPPEDWINDOW, CW\_USEDEFAULT, CW\_USEDEFAULT, static\_cast(ceil(640.f \* \*dpiX / 96.f)), static\_cast(ceil(480.f \* \*dpiY / 96.f)), NULL, NULL, HINST\_THISCOMPONENT, this );
I think I am getting unstuck on the paramaters which call the ceil function... The compiler gives...
c:\users\ben\dropbox\programming\direct2d\usingdirect2d\usingdirect2d\usingdirect2d\usingdirect2d.cpp(405): error C2100: illegal indirection
Any ideas welcome! Cheers
-
Good point. Bad pointer operator placement.
-
Is dpiX a ptr? If not, remove the asterisk. static_cast(ceil(640.f * dpiX / 96.f)),
Thanks for this. I'd clearly been messing around trying to get it to work when it was probably something else.
-
I've been trying to get the example code at https://msdn.microsoft.com/en-us/library/windows/desktop/dd370994%28v=vs.85%29.aspx[^] to work for me. It's a struggle for me. One problem I think I've narrowed down is with the line
// Create the window. m\_hwnd = CreateWindow( L"D2DDemoApp", L"Direct2D Demo App", WS\_OVERLAPPEDWINDOW, CW\_USEDEFAULT, CW\_USEDEFAULT, static\_cast(ceil(640.f \* \*dpiX / 96.f)), static\_cast(ceil(480.f \* \*dpiY / 96.f)), NULL, NULL, HINST\_THISCOMPONENT, this );
I think I am getting unstuck on the paramaters which call the ceil function... The compiler gives...
c:\users\ben\dropbox\programming\direct2d\usingdirect2d\usingdirect2d\usingdirect2d\usingdirect2d.cpp(405): error C2100: illegal indirection
Any ideas welcome! Cheers
I've taken away the extra asterisks. Now I get a problem which produces the compiler error
1>UsingDirect2D.obj : error LNK2019: unresolved external symbol _D2D1CreateFactory@16 referenced in function "long __cdecl D2D1CreateFactory(enum D2D1_FACTORY_TYPE,struct _GUID const &,void * *)" (?D2D1CreateFactory@@YAJW4D2D1_FACTORY_TYPE@@ABU_GUID@@PAPAX@Z)
This is where I call D2D1CreateFactory(...)
HRESULT DemoApp::CreateDeviceIndependentResources(){
HRESULT hr = S_OK;// Create a Direct2D factory. hr = D2D1CreateFactory(D2D1\_FACTORY\_TYPE\_SINGLE\_THREADED, &m\_pDirect2dFactory); return hr;
}
And I do have
#include
at the top of the file. Cheers for any help.
-
I've taken away the extra asterisks. Now I get a problem which produces the compiler error
1>UsingDirect2D.obj : error LNK2019: unresolved external symbol _D2D1CreateFactory@16 referenced in function "long __cdecl D2D1CreateFactory(enum D2D1_FACTORY_TYPE,struct _GUID const &,void * *)" (?D2D1CreateFactory@@YAJW4D2D1_FACTORY_TYPE@@ABU_GUID@@PAPAX@Z)
This is where I call D2D1CreateFactory(...)
HRESULT DemoApp::CreateDeviceIndependentResources(){
HRESULT hr = S_OK;// Create a Direct2D factory. hr = D2D1CreateFactory(D2D1\_FACTORY\_TYPE\_SINGLE\_THREADED, &m\_pDirect2dFactory); return hr;
}
And I do have
#include
at the top of the file. Cheers for any help.
That is a linker error, as identified by the
LNKxxx
message, nothing to do with header files. A header file merely contains the definitions for external functions, classes etc. The actual implementation will be in an external library (or DLL) that also needs to be included in your build; in your case D2d1.lib. -
That is a linker error, as identified by the
LNKxxx
message, nothing to do with header files. A header file merely contains the definitions for external functions, classes etc. The actual implementation will be in an external library (or DLL) that also needs to be included in your build; in your case D2d1.lib.That looks like good advice. Sorry for pestering you with what must look silly questions to you. I really appreciate your help! I did a search for d2d1.lib and found four instances on my computer. I chose one and have tried to add it into my project dependencies under 'Linker/input/additional dependencies' but get an error
1>LINK : fatal error LNK1104: cannot open file ',.obj'
Here is the string I have got in that field...
kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;dwrite.lib;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64\d2d1.lib;%(AdditionalDependencies),
Is this the right place to add a library file include for the build? If so I guess it's a formatting problem or the wrong file or something... Thanks
-
That looks like good advice. Sorry for pestering you with what must look silly questions to you. I really appreciate your help! I did a search for d2d1.lib and found four instances on my computer. I chose one and have tried to add it into my project dependencies under 'Linker/input/additional dependencies' but get an error
1>LINK : fatal error LNK1104: cannot open file ',.obj'
Here is the string I have got in that field...
kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;dwrite.lib;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64\d2d1.lib;%(AdditionalDependencies),
Is this the right place to add a library file include for the build? If so I guess it's a formatting problem or the wrong file or something... Thanks
I think you need to remove that comma after
%(AdditionalDependencies)
. I also tend to put only the 'bare' library names in the additional dependencies field. If a library is in a non-standard directory then I add that directory to the list in the "Additional Library Directories" field in the General Linker properties. Try that and see if it now builds OK. -
That looks like good advice. Sorry for pestering you with what must look silly questions to you. I really appreciate your help! I did a search for d2d1.lib and found four instances on my computer. I chose one and have tried to add it into my project dependencies under 'Linker/input/additional dependencies' but get an error
1>LINK : fatal error LNK1104: cannot open file ',.obj'
Here is the string I have got in that field...
kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;dwrite.lib;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64\d2d1.lib;%(AdditionalDependencies),
Is this the right place to add a library file include for the build? If so I guess it's a formatting problem or the wrong file or something... Thanks
If you don't want to edit your project settings you can also specify the library in one of your source files by using:
#pragma comment( lib, "d2d1" )
But this still requires that the library is located in a directory that is part of the library search paths. So you should add the path if necessary as suggested by Richard (which is generally a good idea for Windows SDKs like in your case).
-
I think you need to remove that comma after
%(AdditionalDependencies)
. I also tend to put only the 'bare' library names in the additional dependencies field. If a library is in a non-standard directory then I add that directory to the list in the "Additional Library Directories" field in the General Linker properties. Try that and see if it now builds OK.That was another good suggestion. That must have got left in from some old attempt to edit the string. In the end I used the
#pragma comment( lib, "d2d1" )
line that someone else suggested. At last I've got this thing to compile and run! Thanks again for your help.
-
If you don't want to edit your project settings you can also specify the library in one of your source files by using:
#pragma comment( lib, "d2d1" )
But this still requires that the library is located in a directory that is part of the library search paths. So you should add the path if necessary as suggested by Richard (which is generally a good idea for Windows SDKs like in your case).
Thanks, Jochen. This did the trick.