Throw exeption in #pragma startup function in dll?

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

Throw exeption in #pragma startup function in dll?

Postby Ahmed Sayed » Tue Sep 24, 2019 8:14 am

Hello every one,

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


Becuase i tried on both Win32/Win64 and it does not work.

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.
Ahmed Sayed
Top Poster
Top Poster
 
Posts: 28
Joined: Thu Nov 08, 2018 4:12 pm

Return to Technical

Who is online

Users browsing this forum: No registered users and 11 guests

cron