c# using const with DllImport -
c# using const with DllImport -
i have code illustration sdk, dll written in c , calls following:
int getattribute(const rawdevcontrol *control, rawdevattribute *attribute)
i'm using
[dllimport(@"dev.dll", setlasterror = true)] internal static extern int getattribute(const rcontrol *control, rattribute *attribute);
but of course of study can not utilize const type when defining reference function.
how can create work c#?
since c# doesn't have concept of const references, don't need worry it. on dll side, code still think have const pointer. thus, import changes this:
[dllimport(@"dev.dll", setlasterror = true)] internal static extern int getattribute(rcontrol control, rattribute attribute);
this, of course, assumes both rcontrol
, rattribute
have been defined in c#. if structs, follow examples on msdn defining structs utilize p/invoke. if classes, that's different set of problems. in case, best if classes com-based.
c# const dllimport
Comments
Post a Comment