I was wondering if it is possible to throw exceptions in a function called with #pragma startup like this:
Code: Select all
void Func()
{
trow Exception("Test error");
}
#pragma startup Func
So i had to come with a workaround like this:
Code: Select all
// TVectorList is a wrapper for std:vector
typedef TVectorList<TPackageInitFunc> TPackageInitFuncList;
extern TPackageInitFuncList PackageInitFuncList;
void Func()
{
trow Exception("Test error");
}
void RegisterFunc()
{
PackageInitFuncList.Add(Func);
}
#pragma startup RegisterFunc
//then in i call another function from the dll in the host app called "InitPackage"
#define DLLEXPORT __declspec(dllexport) __stdcall
void DLLEXPORT InitPackage()
{
throw Exception("Test error for win32"); //on win64 the exception is shown in message box as expected in win32 makes the whole app fails by stop working. Why?
if (PackageInitFuncList.Count > 0) //on win64 the count is 1 as expected on win32 it is "0". Why?
{
for (int i = 0; i < PackageInitFuncList.Count; i++)
{
PackageInitFuncList.Item[i](); // this calls the Func function and raises the exception well in win64 but not in win32
}
}
}
//---------------------------------------------------------------------------
Note: the host app is a mix between (console/ vcl / windows service) and the dll is fmx.
So here is the code what is it that is making this works differently on both compilers i still use berlin 10.1 up 2. was that a bug or is this normal.
Also, is there a magic way to throw exceptions in #pragma startup for both win32 and win64
Thanks in advance any help will be appreciated.