I have this C code:
/*
WARNING: The order of this table must also match the order of a table
located in AcquireResizeFilter() in "resize.c" otherwise the users filter
will not match the actual filter that is setup.
*/
typedef enum
{
UndefinedFilter,
PointFilter,
BoxFilter,
TriangleFilter,
HermiteFilter,
HannFilter,
HammingFilter,
BlackmanFilter,
GaussianFilter,
QuadraticFilter,
CubicFilter,
CatromFilter,
MitchellFilter,
JincFilter,
SincFilter,
SincFastFilter,
KaiserFilter,
WelchFilter,
ParzenFilter,
BohmanFilter,
BartlettFilter,
LagrangeFilter,
LanczosFilter,
LanczosSharpFilter,
Lanczos2Filter,
Lanczos2SharpFilter,
RobidouxFilter,
RobidouxSharpFilter,
CosineFilter,
SplineFilter,
LanczosRadiusFilter,
CubicSplineFilter,
SentinelFilter /* a count of all the filters, not a real filter */
} FilterType;
and
WandExport MagickBooleanType MagickResizeImage(MagickWand *wand,
const size_t columns,const size_t rows,const FilterType filter)
I convert it to Pascal like this:
type
FilterType =(
UndefinedFilter,
PointFilter,
BoxFilter,
TriangleFilter,
HermiteFilter,
HannFilter,
HammingFilter,
BlackmanFilter,
GaussianFilter,
QuadraticFilter,
CubicFilter,
CatromFilter,
MitchellFilter,
JincFilter,
SincFilter,
SincFastFilter,
KaiserFilter,
WelchFilter,
ParzenFilter,
BohmanFilter,
BartlettFilter,
LagrangeFilter,
LanczosFilter,
LanczosSharpFilter,
Lanczos2Filter,
Lanczos2SharpFilter,
RobidouxFilter,
RobidouxSharpFilter,
CosineFilter,
SplineFilter,
LanczosRadiusFilter,
CubicSplineFilter,
SentinelFilter); // a count of all the filters, not a real filter
and
function MagickResizeImage(wand: PMagickWand; const columns: size_t; rows: size_t; const filter: FilterType): MagickBooleanType; cdecl; external MagickWandDLL;
When I call MagickResizeImage()
, I get an Access Violation :(
if I change const filter: FilterType
to const filter: integer
, it works.
Any idea what I am doing wrong?
In C on Windows an enum is an int
, so 4 bytes in size. In Delphi, by default, it is a single byte, or two bytes if there are more than 256 values, and so on.
You need to ensure that your Delphi type is the same size as the C type. For instance using the MINENUMSIZE
directive.
{$MINENUMSIZE 4}
Place this before you define the enumerated type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With