Hey Flippo I'm also trying to connect C# with gretl api. My P/Invoke signature is like so
[DllImportAttribute(Constants.gretlLibraryPath, EntryPoint = "gretl_read_native_data", CallingConvention = CallingConvention.Cdecl)] public static extern int gretl_read_native_data(string fileName, ref Structures.DATASET dataset); you have to mind that callingConversation must be Cdecl. Besides you have to marshal DATASET, like so // Call Gretl Api new datasetIntPtr pointer = GretlCore.NativeGretl.Methods.datainfo_new();// Marshal pointer to datasetStructures.DATASET dataset = (Structures.DATASET)Marshal.PtrToStructure(pointer, typeof(Structures.DATASET)); You can also try to call directly IntPtr. Hope this helps. LP Simon 2011/12/30 Filippo Bonsignori <filippo.bonsignori(a)logobject.ch> > Hello gretl users! > > I'm trying to open a ".gdt" file calling gretl_read_native_data (system > info's: "gretl 1.9.6 - build date 2011-10-17" on "Windows 7 Ultimate - > Service Pack 1") from a C# class: the result is always an error code 12 (it > seems that something is wrong into the file path name ...). > > Follows a significant excerpt of my code > > [Start C# code] > ... > > IntPtr dset; > > [DllImport(@"C:\Program Files (x86)\gretl\libgretl.dll")] > internal static extern void libgretl_init(); > > [DllImport(@"C:\Program Files (x86)\gretl\libgretl.dll")] > internal static extern IntPtr create_new_dataset(IntPtr pZ, int nvar, int > nobs, int markers); > > > [DllImport(@"C:\Program Files (x86)\gretl\libgretl.dll", CharSet = > CharSet.Unicode)] > internal static extern int gretl_read_native_data(string fname, IntPtr > pdset); > > ... > > int err; > string fname = @"C:\Program Files (x86)\gretl\data\misc\australia.gdt"; > > libgretl_init(); > dset = datainfo_new(); > > err = gretl_read_native_data(fname, dset); > > ... > > [End C# code] > > Where am I wrong? > > Regards, Filippo. > > > _______________________________________________ > Gretl-users mailing list > Gretl-users(a)lists.wfu.edu > http://lists.wfu.edu/mailman/listinfo/gretl-users > -- LP SimonHey Flippo
I'm also trying to connect C# with gretl api. My P/Invoke signature is like so
[DllImportAttribute(Constants.gretlLibraryPath, EntryPoint = "gretl_read_native_data", CallingConvention = CallingConvention.Cdecl)] public static extern int gretl_read_native_data(string fileName, ref Structures.DATASET dataset);
you have to mind that callingConversation must be Cdecl.
Besides you have to marshal DATASET, like so
// Call Gretl Api new dataset IntPtr pointer = GretlCore.NativeGretl.Methods.datainfo_new(); // Marshal pointer to dataset Structures.DATASET dataset = (Structures.DATASET)Marshal.PtrToStructure(pointer, typeof(Structures.DATASET));You can also try to call directly IntPtr.
Hope this helps.
LP Simon
2011/12/30 Filippo Bonsignori <[email protected]>
Hello gretl users!
I'm trying to open a ".gdt" file calling gretl_read_native_data (system
info's: "gretl 1.9.6 - build date 2011-10-17" on "Windows 7 Ultimate -
Service Pack 1") from a C# class: the result is always an error code 12 (it
seems that something is wrong into the file path name ...).
Follows a significant excerpt of my code
[Start C# code]
...
IntPtr dset;
[DllImport(@"C:\Program Files (x86)\gretl\libgretl.dll")]
internal static extern void libgretl_init();
[DllImport(@"C:\Program Files (x86)\gretl\libgretl.dll")]
internal static extern IntPtr create_new_dataset(IntPtr pZ, int nvar, int
nobs, int markers);
[DllImport(@"C:\Program Files (x86)\gretl\libgretl.dll", CharSet =
CharSet.Unicode)]
internal static extern int gretl_read_native_data(string fname, IntPtr
pdset);
...
int err;
string fname = @"C:\Program Files (x86)\gretl\data\misc\australia.gdt";
libgretl_init();
dset = datainfo_new();
err = gretl_read_native_data(fname, dset);
...
[End C# code]
Where am I wrong?
Regards, Filippo.
_______________________________________________
Gretl-users mailing list
[email protected]
http://lists.wfu.edu/mailman/listinfo/gretl-users
--
LP Simon
