C++ Builder XE2: Color2RGB not found - c++

The documentation for the function TGIFColor Color2RGB(TColor) should be in the Vcl.Imaging.GIFImg.hpp source file. But when I try to use it I get the error Call to undefined function 'Color2RGB'. Here is a short example:
//---------------------------------------------------------------------------
#include <Vcl.Imaging.GIFImg.hpp>
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma package(smart_init)
TGIFColor TestRGB(TColor fColor) {
TGIFColor RGBColor = Color2RGB(fColor);
return RGBColor;
}
Can anyone explain how to call this function, because the documentation doesn't!?
// Thanks
PS. I did started the question with "Hello, " but even when I edit the question it is removed :(

Read the documentation again more carefully. Color2RGB() is not a standalone function like you are trying to use it as. It is a static method of the TGIFColorMap class instead, eg:
TGIFColor TestRGB(TColor fColor)
{
TGIFColor RGBColor = TGIFColorMap::Color2RGB(fColor);
return RGBColor;
}

Related

Why multithreading in c++ DLL get error C3867 when building?

I am using VS2019
Trying to call a thread in DLL. to run two executables simultaneously with detach
following threads worked when I Run a normal c++ program
I get error
Error C3867 'myClass::runexeone': non-standard syntax; use '&' to create a pointer to member myGateway C:\Users\user\Downloads\Demo\myGateway\myplugin.cpp 21
plugin header
#include <windows.h>
#include <iostream>
#include <thread>
#define MYPLUGIN_EXPORT __declspec(dllexport)
extern "C"
{
MYPLUGIN_EXPORT void WINAPI OnStart();
}
pluging.cpp
#include "plugin.h"
using namespace std;
class myClass
{
public:
myClass()
{
}
~myClass()
{
}
void onStart()
{
std::thread(runexeone).detach();
std::thread(runexetwo).detach();
}
void runexeone()
{
int exerunpne = system("cmd /C \"%MY_ROOT%\\bin\\Mytest.exe\" -ORBEndpoint iiop://localhost:12345 -d");
}
void runexetwo()
{
int exeruntwo = system("cmd /C \"%MY_ROOT%\\bin\\Mytest_2.exe\" -ORBEndpoint iiop://localhost:12345 -d");
}
};
myClass& getmyclass()
{
static myClass myclass;
return myclass;
}
MYPLUGIN_EXPORT void WINAPI OnStart()
{
getmyClass().onStart();
}
The problem is that runexeone is an unqualified name of a member function, and std::thread needs something executable. runexeone isn't. VC++ tries to guess from context what you mean, but the suggestion isn't enough. Even if you had written &myClass::runexeone, it still wouldn't have worked, because myClass::runexeone also needs a this pointer. You can fix the latter problem by making it static.
Compiler suggestions work best when there's just one problem.
As MSalters already mentioned, you provided the wrong data type for the functor for std::thread. If you cannot make the method static (which you can actually at least for the current state of your code, but to let this not be unstated here), you can do this
void onStart()
{
std::thread(std::bind(&myClass::runexeone, this)).detach();
}
But be careful about the lifetime/existence of your object/this!

How to initialize an instance of IVectorView for C++/WRL?

I'm trying to call get_Skus() method of IStoreProduct to retrieve its Skus property using C++/WRL (not C++/CX) and I can't find any suitable code examples. That method is defined as such (as I get it from the header file in Visual Studio):
virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Skus(
/* [out][retval] */ __RPC__deref_out_opt IVectorView<ABI::Windows::Services::Store::StoreSku*> **value) = 0;
So when I try to do:
#include <Windows.Services.Store.h>
#include <wrl.h>
using namespace ABI::Windows::Services::Store;
using namespace ABI::Windows::Foundation::Collections;
IVectorView<StoreSku*> pStrSkus;
//IStoreProduct* pStorePrdct = ...;
if (SUCCEEDED(pStorePrdct->get_Skus(&pStrSkus)))
{
}
it gives me an error that:
'ABI::Windows::Foundation::Collections::IVectorView'
: cannot instantiate abstract class
I'm relatively new to WRL. Can someone show me how am I supposed to call that method?
You forgot a star - it should have been this:
IVectorView<StoreSku*>* pStrSkus;
if (SUCCEEDED(pStorePrdct->get_Skus(&pStrSkus)))
{
...
pStrSkus->Release();
}
Even better, use a ComPtr instead, so you don't have to release it manually:
ComPtr<IVectorView<StoreSku*>> pStrSkus;
if (SUCCEEDED(pStorePrdct->get_Skus(&pStrSkus)))
{
...
}

Where to initialize child controls on TCustomControl

I'm trying to create a simple custom control using Borland C++ Builder 6. In this case, I am trying to create a TPageControl with a single TTabSheet on it. I am having trouble figuring out the proper place to initialize these child controls. At the moment I am initializing everything in the constructor. Everything compiles fine, but when I attempt to place the control onto a form, the Borland IDE gives me an error "Control '' has no parent window" or something very similar. I've found out that the line that is causing this specifically is the setting of the TTabSheet's PageControl property.
The code for my control is below:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "TestControl.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//
static inline void ValidCtrCheck(TTestControl *)
{
new TTestControl(NULL);
}
//---------------------------------------------------------------------------
__fastcall TTestControl::TTestControl(TComponent* Owner)
: TCustomControl(Owner)
{
pageControl = new TPageControl(this);
pageControl->Parent = this;
tabSheet = new TTabSheet(pageControl);
tabSheet->Parent = pageControl;
tabSheet->Caption = "Page 1";
tabSheet->PageControl = pageControl;
}
//---------------------------------------------------------------------------
__fastcall TTestControl::~TTestControl()
{
pageControl->Free();
}
//---------------------------------------------------------------------------
namespace Testcontrol
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TTestControl)};
RegisterComponents("Test", classes, 0);
}
}
//---------------------------------------------------------------------------
Any assistance would be much appreciated--I'm finding that due to the age of this particular technology I'm not having much luck finding resources on this.

How does call method without the variable assign in C++? [duplicate]

This question already has answers here:
When does invoking a member function on a null instance result in undefined behavior?
(2 answers)
Closed 7 years ago.
I'm trying to understand code below.
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
class A
{
public :
void Test();
};
void A::Test()
{
ShowMessage("Hello");
}
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
A *x;
x->Test();
}
I expect EAccessViolation error,when I call the Test method.
How does work without the x assign ?
How does work without the x assign ?
In theory, the posted code is cause for undefined behavior.
In practice, it works some times because A::Test() does not depend on any member data. It is not guaranteed to work in every platform.

_matherr does not get called when built into a DLL

I have a basic solution file (.sln) where I was able to reproduce a problem I have been facing recently.
It contains 3 projects:
1.) MathTest.lib - containing methods that might cause a mathematical error, like acos(1.1).
2.) MathTestDll.dll - calls the methods from the above lib.
3.) UnitTest.exe - calls the exported method in the DLL that should cause the error.
What I'm trying to do is fairly simple:
The following code contains the _matherr() routine and should ideally link fine. The call to acos() with a value of 1.1 is invalid (invalid input) and should cause an error which should be handled by the implemented _matherr() handler. I hope I'm right about the behavior of _matherr(). Please let me know.
MathTest.lib
#include "MathTest.h"
#include <iostream>
#include <math.h>
int _matherr(_exception* _Except)
{
std::cout << _Except->name;
return -1;
}
void MathTest::ThrowMatherr(float par)
{
float result = acos(par);
std::cout << result;
}
This 'ThrowMatherr()' method will be called by the DLL as follows:
MathTestDll.dll
void MatherrCaller::CauseMatherr()
{
MathTest* mathtest = new MathTest();
mathtest->ThrowMatherr(1.1);
}
which is then exported as:
extern "C" __declspec(dllexport) void CallThisToCauseMatherr();
void CallThisToCauseMatherr()
{
MatherrCaller* caller = new MatherrCaller();
caller->CauseMatherr();
}
This exported method will be called by a simple test.
UnitTest.exe
#include <windows.h>
typedef void (*METHODTOCALL)();
int main()
{
HMODULE module = LoadLibrary((LPCSTR)"..\\Debug\\MatherrTestDll.dll");
if(module != NULL)
{
METHODTOCALL ProcAdd = (METHODTOCALL) GetProcAddress(module, (LPCSTR)"CallThisToCauseMatherr");
if (NULL != ProcAdd)
{
(ProcAdd)();
}
FreeLibrary(module);
}
return 0;
}
All methods get called fine. But the acos() method which has been passed invalid input never calls the _matherr() error handler. Please let me know how I can fix this.
I had to make the question detailed to get my point through. Please don't mind.
It is explicitly mentioned in the documentation for _matherr:
For special error handling, you can
provide a different definition of
_matherr. If you use the dynamically linked version of the C run-time
library (Msvcr90.dll), you can replace
the default _matherr routine in a
client executable with a user-defined
version. However, you cannot
replace the default _matherr routine
in a DLL client of Msvcr90.dll.
You'll need to put the override in the EXE module. Alter your unit test to accommodate this.