In fact I have a module

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#light
#nowarn "0051"   // suppress warnings about the use of byref features to interoperate with native code

module nc = begin
   open System.Runtime.InteropServices

    ...

    [<DllImport(@"netcdf.dll",EntryPoint="nc_inq_varname")>] 
    extern int nc_inq_varname_(int ncid, int varid, <b>char</b>* name)
//                                                                     ^ syntax error
    let Inq_varname ncid varid =
        let mutable thisncid = ncid
        let mutable thisvarid = varid
        let mutable varname = 'c'
        let status = nc_inq_varname_(thisncid,thisvarid,&&varname)
        varname, status

end

With: F# Version 1.9.4.15, compiling for .NET Framework Version v2.0.50727
I get error: c:\at_work\fsharp\netcdf\netcdf_small.fs(55,53): error FS0191: syntax error.

If I look my book Expert F# table 17-1 (page 514)
I found
unmanaged C type: char* managed Class: System.String or System.Text.StringBuilder
I read example syahello page 515 and guess change my code

module nc = begin
open System.Runtime.InteropServices
open System.Text
...

[<DllImport(@"netcdf.dll",EntryPoint="nc_inq_varname")>]
extern int nc_inq_varname_(int ncid, int varid, StringBuilder name)

let Inq_varname ncid varid =
let mutable thisncid = ncid
let mutable thisvarid = varid
let mutable varname = new StringBuilder(50)
let status = nc_inq_varname_(thisncid,thisvarid,varname)
varname.ToString(), status

end

If I run this last coding, I have success
Usage of StringBuilder: good pratice or not?

I never found documentation on ... (?)

By on 6/8/2008 5:06 AM ()

I believe he was asking about a possible typo in your original post

1
extern int nc_inq_varname_(int ncid, int varid, dhar *name)

where you declare the type as dhar* name instead of char* name. I think the STRONG tag was just to emphasize the change.

By on 6/24/2008 1:30 PM ()

It looks like you have a typo?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 

#light  
[<System.Runtime.InteropServices.DllImport(@"netcdf.dll",EntryPoint="nc_inq_varname")>] 
extern int nc_inq_varname_(int ncid, int varid, <b>char</b>* name)

#nowarn "51"

let Inq_varname ncid varid =
    let mutable thisncid = ncid
    let mutable thisvarid = varid
    let mutable varname = 'c'                                                     //?? <=== yes mutalble but ... ??
    let status = nc_inq_varname_(thisncid,thisvarid,&&varname)
    varname, status

By on 6/7/2008 11:19 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper