Log in

View Full Version : problem writing C++ application


stax76
17th March 2019, 07:23
It's been 10 I've not used C++ and even then I wasn't very good so please bear with me.

The very first line I wrote already causes an error. :)

Can anybody tell me what I miss?

// aviDrawDX.cpp : Defines the entry point for the application.
//

#include "framework.h"
#include "aviDrawDX.h"
#include "aviDrawDX.h"
#include "shellscalingapi.h"
#include "windows.h"
#include <winuser.h>

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst; // current instance
WCHAR szTitle[MAX_LOADSTRING]; // The title bar text
WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name

// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE);

1>aviDrawDX.obj : error LNK2019: unresolved external symbol SetProcessDpiAwareness referenced in function wWinMain
1>C:\Users\frank\Daten\Projekte\CPP\aviDrawDX\x64\Debug\aviDrawDX.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "aviDrawDX.vcxproj" -- FAILED.

stax76
17th March 2019, 08:08
Maybe I need to link against a lib file but how do I know what is the name of the lib file? It's not documented in the document for SetProcessDpiAwareness.

stax76
17th March 2019, 08:23
Problem solved, I needed to add shcore.lib in the Linker options.

Selur
17th March 2019, 08:28
It's not documented in the document for SetProcessDpiAwareness.
Looking at https://docs.microsoft.com/en-us/windows/desktop/api/shellscalingapi/nf-shellscalingapi-setprocessdpiawareness which indicates taht SetProcessDpiAwareness belongs to Shellscalingapi.h (https://docs.microsoft.com/en-us/windows/desktop/api/shellscalingapi/) and at the bottom of the page you see the requirements:
Requirements

Minimum supported client Windows 8.1 [desktop apps only]
Minimum supported server Windows Server 2012 R2 [desktop apps only]
Target Platform Windows
Header shellscalingapi.h
Library Shcore.lib
DLL Shcore.dll
-> what documentation are you looking at?

Cu Selur

Ps.: LOL, you already solved it while I was writing up my reply. :) Note that this is not supported on Windows 7.

nevcairiel
17th March 2019, 09:52
Instead of using the SetProcessDpiAwareness call, I would personally recommend setting DPI Awareness in the manifest. That is fully compatible with any OS version.

stax76
17th March 2019, 09:55
Thanks, I missed it somehow. In the end if I can get it working it's gonna be a dll used in staxrip which sets DPI awareness already in a Win 7 compatible way.

stax76
19th March 2019, 17:18
What I want to achieve is having a faster preview dialog in StaxRip, it uses GDI+/System.Drawing. The plan is to create a C++ DLL that takes a DIB pointer from the avifile API and renders it using DirectX. I want to create a bitmap from the DIB by calling the function GdipCreateBitmapFromGdiDib, I included the header Gdiplusheaders.h and added the Gdiplus.lib file to the linker options. Now there are many errors:

1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\Gdiplusheaders.h(34): error C2504: 'GdiplusBase': base class undefined
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\Gdiplusheaders.h(39): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\Gdiplusheaders.h(39): error C2143: syntax error: missing ',' before '&'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\Gdiplusheaders.h(40): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\Gdiplusheaders.h(40): error C2143: syntax error: missing ',' before '&'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\Gdiplusheaders.h(40): error C2535: 'Region::Region(const int)': member function already defined or declared
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\Gdiplusheaders.h(39): note: see declaration of 'Region::Region'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\Gdiplusheaders.h(41): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\Gdiplusheaders.h(41): error C2143: syntax error: missing ',' before '*'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\Gdiplusheaders.h(41): error C2535: 'Region::Region(const int)': member function already defined or declared
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\Gdiplusheaders.h(39): note: see declaration of 'Region::Region'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\Gdiplusheaders.h(49): error C3646: 'MakeInfinite': unknown override specifier

I'm using VS 2019 RC with newest SDK and plattform toolkit, in VS 2017 I can't compile anything C++, I've tried to compile my Open with++ shell extension and nomatter what I've tried it wouldn't compile successfully in VS 2017.

What could be the reason for the errors? Do I have to add a search directory somewhere VS to look for headers? Did I meantion I'm not very good in C++? :)

lvqcl
19th March 2019, 17:49
From MSDN page:
Header

Gdiplusheaders.h (include Gdiplus.h)

which means that you need to include Gdiplus.h, and not Gdiplusheaders.h directly.

stax76
19th March 2019, 18:32
that works nicely, thanks.

stax76
3rd April 2019, 15:19
Maybe someone can give me a hint which APIs or source codes I can use to draw a RGB 24 DIB returned by the avifile API. I want to draw to a win32 window handle and it has to be fast so no GDI+. I'm much of a C++ beginner but won't give up on this until I get something done that works.

videoh
3rd April 2019, 15:48
"has to be fast"

That is vague. It would help if you could specify your performance requirements, say, frame rate for 1080p.

stax76
3rd April 2019, 16:06
Currently I use GDI+, I've not measured it but it's so slow that it hurts, on a HD screen it's OK but with UHD it's maybe 2-3 fps only, anything faster than that would be an improvement.

videoh
3rd April 2019, 16:12
That's horrible.

DGIndexNV uses the simple SetDIBitsToDevice() and plays UHD way, way faster than 2-3 fps. DGIndex also uses that function. Source code for DGIndex is available. See store.cpp.

Use StretchDIBits() if you need to resize for display.