Answers.Body: <p>Reusing C++ classes in C# is annoying but straightforward. You'll need to know managed C++.</p>
  
  <blockquote>
    <p><a href="https://stackoverflow.com/questions/855756/difference-between-native-and-managed-code">https://stackoverflow.com/questions/855756/difference-between-native-and-managed-code</a></p>
  </blockquote>
  
  <p>gives you what managed C++ is. It is a C++ technology invented by Microsoft, and it works as a layer between C# and unmanaged C++.</p>
  
  <p>There is no reason why you can't do it in C#. You may want two background threads. The first one sends UCI commands to the engine, while the second thread asynchronously wait for engine results.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Steps you should follow:</p>
  
  <ul>
  <li>Read what managed C++ is and why you would need it</li>
  <li>Make sure you can compile your unmanaged C++ code (regular C++). How to do it depends on your environment</li>
  <li>Make sure your can also compile managed C++ code.</li>
  <li>Make sure your C# code can call into managed C++</li>
  <li>Make sure your managed C++ code can call into unmanaged C++</li>
  <li>Now, you should be able to pass a PGN string from C# to your unmanaged C++ UCI parsing code</li>
  </ul>
  
  <p>There is no reason why you can't use the Stockfish engine in Android.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-08T11:28:52.277Z
Answers.Text: Thanks for answer, now I see my question was badly formulated as I wanted to ask on how to conect to stockfish from c# app, not how to reuse my c++ class. Sorry, I edited my question.
Answers.UserDisplayName: hoacin
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-08T13:55:51.453Z
Answers.Text: @hoacin I'm not 100% sure what steps you're asking. Maybe my edit would help?
Answers.UserDisplayName: SmallChess
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-08T14:34:32.620Z
Answers.Text: If I understand it correctly, I will download source code of Stockfish, put it to my project as you write and then use it? No external Stockfish, no input output redirection like in Windows?
Answers.UserDisplayName: hoacin
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-08T14:42:40.893Z
Answers.Text: @hoacin You can do it internally or externally. Either way you'll need to compile the source code. You'll need to make two background threads for UCI communication.
Answers.UserDisplayName: SmallChess
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-29T15:13:09.410Z
Answers.Text: I added stockfish 8 binary arm64-v8a to my project with build action AndroidNativeLibrary and it looks it is accepted by the project with no error. Is this the right step? If yes, which functions are there to be called from the binary? I suppose there should be some init, send uci message and get uci message functions, but I don't know their names and didn't find anywhere.
Answers.UserDisplayName: hoacin
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-30T01:32:01.163Z
Answers.Text: @hoacin I believe I have answered you in your another question.
Answers.UserDisplayName: SmallChess
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-08T11:10:37.657Z
Answers.LastActivityDate: 2017-05-08T13:55:14.343Z
Answers.LastEditDate: 2017-05-23T12:37:05.403Z
Answers.UserDisplayName: SmallChess
Body: <p>I looked at this question</p>
  
  <p><a href="https://chess.stackexchange.com/questions/15985/implement-a-chess-app-for-android-with-stockfish">Implement a chess app for Android with Stockfish</a></p>
  
  <p>but it doesn't seem to be answering what I want to ask. Maybe part of my question is topic for stack overflow forum, but anyway, I try it here first. </p>
  
  <p>I'm doing android app in c# with xamarin and would like to use Stockfish for analysis and play functions. I already have c++ class working with PC version of engine (uci) and I would like to reuse some of the code like uci parsing. What steps should I do to run Stockfish in my c# app? Also I would like to ask if there are some conditions under which stockfish can/can't be used in android chess app. </p>
  
Tags: <stockfish><programming>
Title: Using Stockfish in c# android (xamarin) app
ThreadText: # Using Stockfish in c# android (xamarin) app
  
  (Asked by: username_0 on 2017-05-08)
  
  I looked at this question
  
  [Implement a chess app for Android with Stockfish](https://chess.stackexchange.com/questions/15985/implement-a-chess-app-for-android-with-stockfish)
  
  but it doesn't seem to be answering what I want to ask. Maybe part of my question is topic for stack overflow forum, but anyway, I try it here first.
  
  I'm doing android app in c# with xamarin and would like to use Stockfish for analysis and play functions. I already have c++ class working with PC version of engine (uci) and I would like to reuse some of the code like uci parsing. What steps should I do to run Stockfish in my c# app? Also I would like to ask if there are some conditions under which stockfish can/can't be used in android chess app.
  
  **Tags:** stockfish, programming
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-05-08. Score: 3
  
  Reusing C++ classes in C# is annoying but straightforward. You'll need to know managed C++.
  
  > <https://stackoverflow.com/questions/855756/difference-between-native-and-managed-code>
  
  gives you what managed C++ is. It is a C++ technology invented by Microsoft, and it works as a layer between C# and unmanaged C++.
  
  There is no reason why you can't do it in C#. You may want two background threads. The first one sends UCI commands to the engine, while the second thread asynchronously wait for engine results.
  
  **EDIT**
  
  Steps you should follow:
  
  * Read what managed C++ is and why you would need it
  * Make sure you can compile your unmanaged C++ code (regular C++). How to do it depends on your environment
  * Make sure your can also compile managed C++ code.
  * Make sure your C# code can call into managed C++
  * Make sure your managed C++ code can call into unmanaged C++
  * Now, you should be able to pass a PGN string from C# to your unmanaged C++ UCI parsing code
  
  There is no reason why you can't use the Stockfish engine in Android.
  
  > **Comments:**
  > **username_0**: Thanks for answer, now I see my question was badly formulated as I wanted to ask on how to conect to stockfish from c# app, not how to reuse my c++ class. Sorry, I edited my question.  
  > **username_1**: @username_0 I'm not 100% sure what steps you're asking. Maybe my edit would help?  
  > **username_0**: If I understand it correctly, I will download source code of Stockfish, put it to my project as you write and then use it? No external Stockfish, no input output redirection like in Windows?  
  > **username_1**: @username_0 You can do it internally or externally. Either way you'll need to compile the source code. You'll need to make two background threads for UCI communication.  
  > **username_0**: I added stockfish 8 binary arm64-v8a to my project with build action AndroidNativeLibrary and it looks it is accepted by the project with no error. Is this the right step? If yes, which functions are there to be called from the binary? I suppose there should be some init, send uci message and get uci message functions, but I don't know their names and didn't find anywhere.  
  > **username_1**: @username_0 I believe I have answered you in your another question.  
  
  ---
  
  