How to install GDI+ SDK - c++

I recently downloaded GDI+ SDK from the following link:
https://www.microsoft.com/en-us/download/confirmation.aspx?id=18909
I have it, but it simply extracts two folders, one of which contains no code at all, just the eula.
I am not sure what you call the files I was given here. I assumed they would be a library, and should just be #included. However, c++ seems a lot less straight forward as to importing things(Java seemed a lot clearer to me on how to use external code). Then again, maybe I just haven't found that essential tutorial yet.
Either way, I am at a loss on how to incorporate GDI+ into my code.
The following site (https://msdn.microsoft.com/en-us/library/system.drawing.image(v=vs.110).aspx) says plainly that System.Drawing is a namespace, which to my knowledge is in GDI+. I have the following code:
#include "C:\GDI+\asms\10\msft\windows\gdiplus\gdiplus.dll"
#include <stdafx.h>
#include <windows.h>
#include <objidl.h>
#include <gdiplus.h>
When trying to code the following:
using namespace System.Drawing;
I get the error: Must be a namespace name.
How should I install the SDK files so that I can use them in my projects?
Clearly, I am not doing something right.

#include is for header files only, cannot be used to add *.dll files.
using namespace System.Drawing; is for .Net, C++ doesn't know what it is
In Visual Studio use this to link to library:
#pragma comment( lib, "Gdiplus.lib" )
You also need Gdi startup and shut down.
//#pragma warning( push ) optional
//#pragma warning( disable : 4458 )
#include <gdiplus.h>
//#pragma warning( pop )
//link to library:
#pragma comment( lib, "Gdiplus.lib" )
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR, int)
{
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
//do stuff
Gdiplus::GdiplusShutdown(gdiplusToken);
return 0;
}

Related

C++ Builder 10.4 community edition => scoped_lock are missing (at least seems to be a path mess)

Just installed C++Builder 10.4 Community Edition. My app is a console multi-threaded app, and uses std::scoped_lock (C++17).
It seems that C++Builder chooses a <mutex> header file that does not define scoped_lock in C:\Program Files (x86)\Embarcadero\Studio\21.0\include\dinkumware64, where the <mutex> header file that is in C:\Program Files (x86)\Embarcadero\Studio\21.0\include\dinkumware64\Dinkum\threads actually does define them, but is not the one used during include resolution.
What am I missing? Has this ever been tested?
Launch C++Builder fresh from install, create a new console, multi-threaded application, take the pre-generated shim code for main() and add this code:
#pragma hdrstop
#pragma argsused
#include <mutex>
#ifdef _WIN32
#include <tchar.h>
#else
typedef char _TCHAR;
#define _tmain main
#endif
#include <stdio.h>
std::mutex m;
int _tmain(int argc, _TCHAR* argv[])
{
std::scoped_lock lock(m);
return 0;
}
And that will fail with an error:
no member named "std::scoped_lock" in namespace "std"
The application is 32 bits, debug. I've tried 64 bits as the <mutex> header is strangely located under dinkumware64/mutex, and debug no/debug, I've tried changing various options but no avail.
Now under dinkumware64/Dinkum/threads/, there is another "mutex" package that includes scoped_lock, but I have no idea why C++Builder selects it or not, and it's not in the std namespace anyway.
The standard library is located in dinkumware64 for 32-bit programs as well, so you should be looking there.
Problem is that scoped_lock is missing from the standard library.
You can easily implement this class by yourself by using std::lock, or just use std::lock_guard if you only have one mutex.

Set custom EntryPoint for a simple application

I have this simple hello world c++ application:
#include <windows.h>
#include <iostream>
using namespace std;
void test()
{
cout << "Hello world" << endl;
}
I want to use test as my custom entry point. So far I tried to set Linker -> Advanced -> Entrypoint to test But I got lots of lnk2001 errors. Is it possible to somehow remove any main() wmain() WinMain() and use my function with just Visual studio settings?
Using a custom entry point in a Windows app bypasses the entire CRT startup and global C++ initializations. Because of that, it requires not using the CRT, and turning off compiler features that depend on the CRT such as /GS buffer checks and other /RTC run-time error checks.
The following is an example of a minimal app with the custom entry point test.
#include <sdkDdkVer.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
// compile with /GS- lest
// LNK2001: unresolved external symbol #__security_check_cookie#4
//#pragma strict_gs_check(off)
// turn off /RTC*
#pragma runtime_checks("", off)
#pragma comment(linker, "/nodefaultlib /subsystem:windows /ENTRY:test")
int __stdcall test(void)
{
OutputDebugStringA("custom /entry:test\n");
ExitProcess(0);
}
More insight can be found in Raymond Chen's WinMain is just the conventional name for the Win32 process entry point.

linking error/conflict for SendMessageA method

I have built the aws-cpp-sdk the following way:
cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_BUILD_TYPE=Debug -DBUILD_ONLY="s3;sqs;sns"
and after that I ran:
MSBuild.exe INSTALL.vcxproj
Which produced the following files in the "*C:\Program Files\aws-cpp-sdk-all*" directory:
aws-c-common.dll
aws-c-event-stream.dll
aws-checksums.dll
aws-cpp-sdk-access-management.dll
aws-cpp-sdk-access-management.lib
aws-cpp-sdk-cognito-identity.dll
aws-cpp-sdk-cognito-identity.lib
aws-cpp-sdk-core.dll
aws-cpp-sdk-core.lib
aws-cpp-sdk-iam.dll
aws-cpp-sdk-iam.lib
aws-cpp-sdk-sns.dll
aws-cpp-sdk-sns.lib
aws-cpp-sdk-sqs.dll
aws-cpp-sdk-sqs.lib
aws-c-common.lib
aws-c-event-stream.lib
aws-checksums.lib
along with the include directory. I have included all the headers and all the libraries:
#include <aws/core/Aws.h>
#include <aws/core/auth/AWSCredentials.h>
#include <aws/core/client/ClientConfiguration.h>
#include <aws/core/utils/logging/DefaultLogSystem.h>
#include <aws/core/utils/logging/AWSLogging.h>
#include <aws/sns/model/PublishRequest.h>
#include <aws/sns/model/PublishResult.h>
#include <aws/s3/model/ListObjectsRequest.h>
#include <aws/core/utils/Outcome.h>
#include <aws/s3/model/Bucket.h>
#include <aws/sqs/SQSClient.h>
#include <aws/sqs/model/SendMessageRequest.h>
#pragma comment( lib, "aws-cpp-sdk-core.lib" )
#pragma comment( lib, "aws-c-common.lib" )
#pragma comment( lib, "aws-c-event-stream.lib" )
#pragma comment( lib, "aws-checksums.lib" )
#pragma comment( lib, "aws-cpp-sdk-core.lib" )
#pragma comment( lib, "aws-cpp-sdk-iam.lib" )
#pragma comment( lib, "aws-cpp-sdk-sqs.lib" )
#pragma comment( lib, "aws-cpp-sdk-sns.lib" )
#pragma comment( lib, "aws-cpp-sdk-cognito-identity.lib" )
#pragma comment( lib, "aws-cpp-sdk-access-management.lib" )
...
Aws::SQS::SQSClient sqs;
Aws::SQS::Model::SendMessageRequest sm_req;
sm_req.SetQueueUrl( "https://sqs.amazonaws.com/123123" );
sm_req.SetMessageBody( stringJSONFormatted.c_str() );
auto sm_out = sqs.SendMessage(sm_req);
if (sm_out.IsSuccess())
Logger::Log( "Message sent successfully to the AWS SQS" );
else
Logger::Log( "FAILED to send message send to AWS SQS" );
But whenever I build this I get:
__declspec(dllimport) public: virtual class Aws::Utils::Outcome<class Aws::SQS::Model::SendMessageResult,class Aws::Client::AWSError<enum Aws::SQS::SQSErrors> >
__cdecl Aws::SQS::SQSClient::SendMessageA(class Aws::SQS::Model::SendMessageRequest const &)const
(__imp_?SendMessageA#SQSClient#SQS#Aws##UEBA?AV?$Outcome#VSendMessageResult#Model#SQS#Aws##V?$AWSError#W4SQSErrors#SQS#Aws###Client#4##Utils#3#AEBVSendMessageRequest#Model#23##Z)
fatal error LNK1120: 1 unresolved externals
I tried everything I could find, I even re-built the library many times with different arguments, but still the same problem persists. it seems it has something do with AWS::SQSClient::SendMessageA name conflicting with some kind of Windows method (but I'm probably wrong). There was one solution which stated, if I define this before the AWS headers, it should build:
#undef GetObject
but still the same error. Any suggestions please?
The problem is that the Windows system headers define the macro SendMessage to expand to either SendMessageA or SendMessageW depending on the existence of the UNICODE macro.
It does this for a lot of functions in the Windows API, which of course means that there will be clashes with other code using symbols that turn out to be macros in Windows.
One possible solution is to #undef SendMessage after #include <windows.h>. Which might not be possible if the code you try to build comes from a third party.
You may want to take a look at this blog post for a detailed explanation.
You may try with:
#undef SendMessage
before including the AWS headers (similarly to the #undef GetObject you cited in your question).

DirectX 11 and g++ compile error

Hello I actually learning DirectX 11 with this tutorial: http://www.rastertek.com/dx11tut03.html
First Part
My code (where the probleme come from):
d3dclass.h:
//Linking
#pragma comment(lib, "dxgi.lib")
#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "d3dx11.lib")
#pragma comment(lib, "d3dx10.lib")
//Include
#include <dxgi.h>
#include <d3dcommon.h>
#include <d3d11.h>
#include <d3dx10math.h>
I do all like the tutorial, the only diference is I compile it with g++, trough this the command :
g++ -mwindows WinMain.cpp systemclass.cpp inputclass.cpp graphicsclass.cpp d3dclass.cpp -o Prog.exe -I "D:\Programme File\DirectX SDK\Include" 2> log.txt
but in the output file, I have a large sum of errors. This is the log.txt:
https://drive.google.com/open?id=1XUlcAFUyRcLIvdKbe0FkLVjkvwxpOmEv
To sum up the log there is a lot of things like __in which has not been declared in the dxgi.h, but this header is from DirectX11 Library;
Second Part
I found the way to fix a lot of my problem (of the first part) with adding this :
#define __in
#define __out
#define __inout
#define __in_bcount(x)
#define __out_bcount(x)
#define __in_ecount(x)
#define __out_ecount(x)
#define __in_ecount_opt(x)
#define __out_ecount_opt(x)
#define __in_bcount_opt(x)
#define __out_bcount_opt(x)
#define __in_opt
#define __inout_opt
#define __out_opt
#define __out_ecount_part_opt(x,y)
#define __deref_out
#define __deref_out_opt
#define __RPC__deref_out
but there still is a major problem, this is the error output :
D:\Programme File\DirectX SDK\Include/d3dx10core.h:345:13: error: expected ';' at end of member declaration
HRESULT WINAPI_INLINE GetDesc(D3DX10_FONT_DESCA *pDesc) { return GetDescA(pDesc); }
it comes from WINAPI_INLINE (this is in the DirectX header)
How can I fix this? please.
I don't have any experience with using g++, but I can help with a few details here. To use g++ you need to install the Windows SDK and configure it to include the proper paths. The legacy DirectX SDK requires the Windows SDK and is not fully standalone.
Note that the legacy DirectX SDK and the Windows SDK don't claim to be compatible with the GCC toolchain.
The __in, __out, etc. macros are called "SAL annotations" and they are there to improve the quality of static code analysis both internally at Microsoft and when using Visual C++'s /analyze switch. They are defined as 'blank' in other cases so they just get removed from the code. The macros are defined in the Windows SDK. You can try explicitly doing a #include <sal.h> and/or #include <specstrings.h> before including a version of dxgi.h.
Another thing to keep in mind is that the legacy DirectX SDK itself is deprecated along with the D3DX9, D3DX10, and D3DX1 utility libraries. As such, if you are using the Windows 8.0, 8.1, or 10 SDK you can code Direct3D 11 without using it at all--see Living without D3DX. If you do want to continue to use those older helpers--which the somewhat dated rastertek tutorials assume--, you can do so but you need to make sure the DirectX SDK include and lib paths are searched after the Windows SDK include/lib paths.
If you were using Visual C++ (which BTW has a free Community edition available), then you'd probably be having an easier time. You might also want to see the DirectX Tool Kit tutorials.

OpenCV (CvHaarClassifierCascade*) cvLoad doesn't load, unable to load xml file

I'm trying face detection using OpenCv 2.3. My trying to load "haarcascade_frontalface_alt_tree.xml" on my project, I'm constantly unable to load the xml file.
CvHaarClassifierCascade * pCascade = 0; // the face detector
const char* file ="C:\OpenCV2.3\opencv\data\haarcascades\haarcascade_frontalface_alt_tree.xml" ;
pCascade = (CvHaarClassifierCascade*) cvLoad(file , NULL, NULL, NULL);
if (!pCascade) {
exit(-1); // unable to load xml
}
I believe that I'm experiencing the same problem as this problem.
I have tried to load an image before the cvLoad command, but it didn't help.
I'm using OpenCV 2.3, made my configuration just like in this tutorial.
I'm using those libraries (I presume my configurations are correct, the file exist and can be open using Notepad++).
#include <stdio.h>
#include "opencv2\opencv.hpp"
#include "cv.h"
#include "highgui.h"
//#include "cvaux.h"
using namespace cv;
#pragma comment(lib, "opencv_core230d.lib")
#pragma comment(lib, "opencv_highgui230d.lib")
//#pragma comment(lib, "opencv_contrib230d.lib")
//#pragma comment(lib, "opencv_calib3d230d.lib")
//#pragma comment(lib, "opencv_features2d230d.lib")
//#pragma comment(lib, "opencv_flann230d.lib")
//#pragma comment(lib, "opencv_gpu230d.lib")
#pragma comment(lib, "opencv_haartraining_engined.lib")
#pragma comment(lib, "opencv_imgproc230d.lib")
//#pragma comment(lib, "opencv_legacy230d.lib")
//#pragma comment(lib, "opencv_ml230d.lib")
//#pragma comment(lib, "opencv_objdetect230d.lib")
//#pragma comment(lib, "opencv_video230d.lib")
To narrow down the issue, before calling cvLoad you should check to see if the file exists. Here's one way:
struct stat buf;
int statResult = stat(file,&buf);
if (statResult || buf.st_ino < 0) {
cout << "File not found: " << file << endl;
exit(-2);
}
You'll need to #include <sys/stat.h>
On my system (OS X 10.6.8/OpenCV 2.3), when I attempt to load haarcascade_frontalface_alt_tree.xml or haarcascade_frontalface_alt.xml I get an exception:
OpenCV Error: Unspecified error (The node does not represent a user object (unknown type?)) in cvRead, file /Users/steve/Development/opencv2/opencv/modules/core/src/persistence.cpp, line 4857
I think you are using an outdated OpenCV 1 tutorial that doesn't work with the current version of haarcascade_frontalface_alt_tree.xml. Try this OpenCV 2 tutorial instead. This code from that tutorial works for me:
CascadeClassifier face_cascade;
if (!face_cascade.load( file) ) {
cout << "Couldn't load face_cascade" << endl;
exit(-1);
}
cout << "Loaded face_cascade" << endl;
It happens also to me but finally I think I found the problem.
OpenCV has two different libraries *d.lib and *.lib the d means debug.
The problem is you need to setup the proper libraries to your environment (vs in my case) in the proper mode.
d.lib when you are in debug and .lib when you are in release.
Also in my project I need to run it in Release mode to make it work :)
This setup in my vs2009 could be found under Properties, Linker, Input, Additional dependencies.
Best regards
Check that the string with the "haarcascade_frontalface_alt.xml" file name is correct.
I had this problem and the directory separater was not being recognised. I changed the '\' character to '/' and the tutorial worked.
For your info, I was using MacOS 10.8.3 running Parallels with Windows 7, Visual Studio 2012 and opencv 2.44 - I was using the version 2 of the tutorial