On 17/01/2022 17:31, Jiří Činčura wrote:
>> I suspect you didn't understand well how easy it is.
>
> I'm all ears. Or actually eyes - I'll be glad to learn some new C#/.NET
> interop tricks.
>
I'd not say it's tricks, certainly not for you.
I just see no difficulty in this more than the C approach you have said
to be better.
class Program
{
[DllImport("libfbclient.so", CallingConvention =
CallingConvention.Cdecl)]
public static unsafe extern FIREBIRD_IMaster* fb_get_master_interface();
static unsafe void Main(string[] args)
{
var master = fb_get_master_interface();
var dispatcher1 = master->vTable->getDispatcher(master);
// Or this, to repeat less things
var masterVTable = master->vTable;
var dispatcher2 = masterVTable->getDispatcher(master);
}
}
With the below declarations (that can be generated automatically if
large parts are needed), or similar wrappers (also automatically
generated) directly in C# as the .c one.
[StructLayout(LayoutKind.Sequential)]
unsafe struct FIREBIRD_IMasterVTable
{
public IntPtr cloopDummy;
public UIntPtr version;
public delegate* unmanaged[Cdecl] <FIREBIRD_IMaster*,
FIREBIRD_IStatus*> getStatus;
public delegate* unmanaged[Cdecl] <FIREBIRD_IMaster*,
FIREBIRD_IProvider*> getDispatcher;
// ...
/*
struct FIREBIRD_IPluginManager* (*getPluginManager)(struct
FIREBIRD_IMaster* self);
struct FIREBIRD_ITimerControl* (*getTimerControl)(struct
FIREBIRD_IMaster* self);
struct FIREBIRD_IDtc* (*getDtc)(struct FIREBIRD_IMaster* self);
struct FIREBIRD_IAttachment* (*registerAttachment)(struct
FIREBIRD_IMaster* self, struct FIREBIRD_IProvider* provider, struct
FIREBIRD_IAttachment* attachment);
struct FIREBIRD_ITransaction* (*registerTransaction)(struct
FIREBIRD_IMaster* self, struct FIREBIRD_IAttachment* attachment, struct
FIREBIRD_ITransaction* transaction);
struct FIREBIRD_IMetadataBuilder* (*getMetadataBuilder)(struct
FIREBIRD_IMaster* self, struct FIREBIRD_IStatus* status, unsigned
fieldCount);
int (*serverMode)(struct FIREBIRD_IMaster* self, int mode);
struct FIREBIRD_IUtil* (*getUtilInterface)(struct FIREBIRD_IMaster*
self);
struct FIREBIRD_IConfigManager* (*getConfigManager)(struct
FIREBIRD_IMaster* self);
FB_BOOLEAN (*getProcessExiting)(struct FIREBIRD_IMaster* self);
*/
}
[StructLayout(LayoutKind.Sequential)]
unsafe struct FIREBIRD_IMaster
{
public IntPtr cloopDummy;
public FIREBIRD_IMasterVTable* vTable;
}
[StructLayout(LayoutKind.Sequential)]
unsafe struct FIREBIRD_IStatus
{
// ...
}
[StructLayout(LayoutKind.Sequential)]
unsafe struct FIREBIRD_IProvider
{
// ...
}
Adriano
Firebird-Devel mailing list, web interface at
https://lists.sourceforge.net/lists/listinfo/firebird-devel