:Now my problem, is that the DLL i have already has those sized
:constants. I need to write a wrapper, which basically converts the
:single or 2D pointers, to the corresponding formats.
:for ex. the matlab interface needs int *linesize, but the DLL has int
:linesize[4].
If you were to pass an arbitrary structure into a C function, by
casting the pointer to void*, then there is no standard way for the
function to be able to figure out what the structure looks like
internally. (Some implimentations might have non-standard ways.) You
will thus not be able to write a C function which can be passed an
arbitrary structure and which will construct the appropriate new
structure.
Similarily, if you try to work it at the preprocessor level, you will
find that the preprocessor has no way to refer to items such as "the
first element of the named parameter". You thus will not be able to do
what you want by a preprocessor macro being passed an arbitrary
structure.
If you were willing to rewrite all your structure definitions, then you
could perhaps [in newer versions of C] write something like a
"DEFINE_STRUCTURE" macro that took as arguments all the pieces of the
structure, and which emitted both the regular 'struct' definition and
the modified definition you needed. Except that you want more than just
that -- you would also want to emit a pair of function that converted
between the two forms. I don't know if that is possible with a variable
number of arguments even in C99 [I haven't looked at what the C99
preprocessor is capable of.]
What I would suggest to you is that your problem would be most easily
solved outside the C program itself, by using some preprocessing
of your header files. As the preprocessing would be largely
textual, I would suggest that a program such as perl might be
easier to impliment this in than in pure C. The idea would be
to write a program (e.g., perl script) which read your header
files that define your structures, and emitted code that
defined the modified header and defines functions to do the
conversion. If you have lots of code, you could get fancier and
add a script that read through the code, figured out which
structures were referenced, and inserted #include statements
into the code to import the modified structure definitions
and conversion functions.