In general, there is such a thing. Unicorn Engine. Allows you to run emulation of different processors. It has a ready add-in for .NET, that's just written in F #. And there, when it cannot create an object the actual engine gives an error of the type: "XX, Unable to create Unicorn engine".

let checkResult(errCode: Int32, errMsg: String) = if errCode <> Common.UC_ERR_OK then raise(ApplicationException(String.Format("{0}. Error: {1}", errMsg, errCode)) 

in the engine itself there is a function char * strrerror (int code); And it is even imported (but here, I’m saying that the problem is, it is imported as an IntPtr strerror (Int)) attempt to make to the forehead like this:

 let checkResult(errCode: Int32, errMsg: String) = if errCode <> Common.UC_ERR_OK then raise(ApplicationException(String.Format("{0}. Error: {1} {2}", errMsg, errCode, binding.Strerror(errCode))) 

causes an error in the next let

Error 2 Probably incorrect indents: this marker is out of context, starting at position (50:45). Try increasing the indentation of the marker or use standard formatting conventions. F: .projects.cpp.msvc \ UnicornManaged \ Unicorn.fs 52 5 UnicornManaged

I assume that the problem is that the function is imported as an IntPtr and not a String. (Although, maybe I did something wrong syntactically. Nevertheless, I don’t know this language)

 [<AutoOpen>] module private Imported = . . . [<DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)>] extern IntPtr uc_strerror(Int32 err) . . . let instance = {new IBinding with . . . member thi.Strerror(err) = uc_strerror(err) . . . } 

Who is familiar with this f #? Tell me how to fix the code

  • Question in interopa. Where did you get the P / Invoke declaration? - VladD

2 answers 2

Try this

 [<DllImport("unicorn", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)>] extern string uc_strerror(Int32 err) 
  • one
    You might be interested in this - in F # Slack a channel has opened for discussing F # in Russian. In order to get there you just need to join the F # Software Foundation , then you should receive an invitation to slack - user227049
  • sort of figured out a bit. compiled like this. `let сheckResult (errCode: Int32, errMsg: String) = if errCode <> Common.UC_ERR_OK then let errorStringPtr = binding.Strerror (errCode) let msg = Marshal.PtrToStringAnsi (errorStringPtr) raise (ApplicationException (rantrnthePtRToStringAnsi (errorStringPtr)) (ApplicationException (rantservice (errCode)) }. Error: {1} {2} ", errMsg, errCode, msg)))` I’ll not check it yet, as it shows errors, because The main need is not in this code, but in that. what uses it. and there I figured out what was the error. PS I can’t deal with kamenta in any way, or rather with their design - EugenOS

It seems like I figured out a bit. Compiled like this.

 let checkResult(errCode: Int32, errMsg: String) = if errCode <> Common.UC_ERR_OK then let errorStringPtr = binding.Strerror(errCode) let msg = Marshal.PtrToStringAnsi(errorStringPtr) raise( ApplicationException(String.Format("{0}. Error: {1} {2}", errMsg, errCode, msg ))) 

While I will not check how it shows errors, because The main need now is not in this code, but in that. what uses it. And there I figured out what was the error. How to finish check.

PS I can not figure out the design of kamentov here. all the time comes out in one piece ...

PPS bohdan_trotsenko, your version did not cause any errors either, but in Unicorn itself, a function in the form of IntPtr was used (there I spied what I did). I did not edit the code in many places, I would prefer to change it in one, although I would have made your option (in C # I did, in similar cases)