Since the marhsalling of the C/Delphi struct to a byte array happens at the application level not at the COM level, CLR/COM interop won't unmarshal the data for you. You could, as Robert says, try to exploit Marshal.PtrToStructure, but I think it makes sense to write your own code to parse the byte array.

I agree with Robert that calling CoInitializeSecurity is probably unnecessary. You use pinvoke to make calls to Win32API from F#, but you probably never need to directly pinvoke any of the Co* functions because either they are called automatically by the CLR (e.g., CoInitialize) or have been wrapped somewhere in System.Runtime.InteropServices (e.g. CoTaskMemAlloc).

By on 10/5/2007 1:13 AM ()

Hello.

You and Robert are right -- there was no need to manually call CoInitialize. Also all those structures i got over COM did not include pointers to unmanaged memory, so was no need to use Marshal.PtrToStructure.

For now i have yet one question: how can i explain to F# compiler that my sources is in Cp1251 encoding?

Part of my data are strings with chars from Cp1251 locale and default locale on server and my computer is also Cp1251, so i suppose

there will be sufficient to just "fsi --use ...", but that didn't work. I've also try

1
fsi --fsi-server-input-codepage 1251, but that also didn't work.

For now i use UNICODE-16 for source files and all works well.

But is there option for fsi or python-like file comment to define file encoding?

P.S. For now i use this function to convert list to string:

1
2
3
4
let l2s l =
    let f = String.make 1
    let f = f >> (^)
    List.fold_right f l ""

is it easer ways to such convertion?

By on 10/23/2007 6:56 PM ()

As far as I know there is currently no way to explicitly set the character encoding used but I believe such a feature is being considered. For now a unicode is the only way to support characters outside of the ascii 0-127 range, though I thought UTF-8 was the only supported unicode encoding.

Your on the right lines with fold function, but you can define the function in one line of code:

1
let stingOfList l = List.fold_left (+) "" l
By on 10/23/2007 10:06 PM ()

Thanks, Robert.

Your function is simpler and also is tail recursive.

But it has signature

"string list -> string", and mine has "char list -> string", so after small changes:

1
let stringOfList l = List.fold_left (fun a c -> a + String.of_char c) "" l

P.S. It seems, there is no runtime function to convert list of chars to string.

By on 10/25/2007 7:39 PM ()

A constructor of String does this for arrays, so maybe this would be preferred:

1
let stringOfList l = new System.String(List.to_array l) 
By on 10/25/2007 10:14 PM ()

I strongly suspect this is little to do with F# itself and more to do with .NET/Com interop, so you maybe better posting the question to one of the MSDN forums on .NET interop.

I don't know of any way to automatically marshal an array to a structure, but there is a method to marshal a pointer to structure, Marshal.PtrToStructure in the System.Runtime.InteropServices namespace. It maybe possible to configure the COM interop to generate pointers instead of arrays, but not sure how you would do this.

I would have thought it not necessary to explicitly call CoInitializeSecurity, I would guess that this is handled by the Com Callable Wrapper generated by TlbImp.exe, but again not completely sure here.

The firefox issue is a known bug with community server, I believe there is a patch, but our administrator, optionsScapler, seems to be on an extended leave of absence at the moment. Sorry about this.

By on 10/3/2007 5:03 AM ()

Thanks for your answer, Robert.

For now i'm think to write simple wrapper

to read primitive types from byte array.

I suppose it's nice occasion to learn f# modic syntax.

But i really don't know what to do with pointer types.

By on 10/3/2007 5:31 AM ()
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