SimMain.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. This software is subject to the license described in the License.txt file
  3. included with this software distribution. You may not use this file except in compliance
  4. with this license.
  5. Copyright (c) Dynastream Innovations Inc. 2012
  6. All rights reserved.
  7. */
  8. // Main project file.
  9. // compile in the common language runtime mixed mode (/clr)
  10. // This program relies on the ANT dlls and the VS libraries to be run
  11. #include "stdafx.h"
  12. #include "MainForm.h"
  13. #include <stdio.h>
  14. #include <vcclr.h>
  15. #include <windows.h>
  16. using namespace ANTPlusSim;
  17. class Thunk
  18. // event forwarder
  19. {
  20. public:
  21. Thunk(MainForm^ A_ANTMainPtr)
  22. {
  23. ANTMainPtr = A_ANTMainPtr;
  24. }
  25. static void __stdcall CallbackForwarder(void* param, UCHAR ucChannel_, UCHAR ucMessageCode_, UCHAR* pucBuffer_)
  26. {
  27. static_cast<Thunk*>(param)->ANTMainPtr->ProcessChannelEvent(ucChannel_, ucMessageCode_, pucBuffer_);
  28. }
  29. static void __stdcall CallbackForwarder2(void* param, UCHAR ucChannel_, UCHAR ucMessageCode_, UCHAR* pucBuffer_)
  30. {
  31. static_cast<Thunk*>(param)->ANTMainPtr->ProcessProtocolEvent(ucChannel_, ucMessageCode_, pucBuffer_ );
  32. }
  33. private:
  34. gcroot<MainForm^> ANTMainPtr;
  35. };
  36. Thunk *pThunk;
  37. //#pragma unmanaged
  38. void UnmanagedSender(UCHAR ucChannel_, UCHAR ucMessageCode_, UCHAR* pucBuffer_)
  39. {
  40. pThunk->CallbackForwarder(pThunk, ucChannel_, ucMessageCode_, pucBuffer_);
  41. }
  42. void UnmanagedEventSender(UCHAR ucChannel_, UCHAR ucMessageCode_, UCHAR* pucBuffer_)
  43. {
  44. pThunk->CallbackForwarder2(pThunk, ucChannel_, ucMessageCode_, pucBuffer_);
  45. }
  46. #pragma managed
  47. [STAThreadAttribute]
  48. int main()
  49. {
  50. System::Threading::Thread::CurrentThread->ApartmentState = System::Threading::ApartmentState::STA;
  51. MainForm ^pMainForm;
  52. #if defined(SIMULATOR_DISPLAY)
  53. pMainForm = gcnew MainForm(SIM_DISPLAY);
  54. #elif defined(SIMULATOR_SENSOR)
  55. pMainForm = gcnew MainForm(SIM_SENSOR);
  56. #else
  57. #error "SIMULATOR NOT DEFINED"
  58. #endif
  59. pThunk = new Thunk(pMainForm);
  60. // Create the main window and run it
  61. Application::Run(pMainForm);
  62. delete pThunk;
  63. return 0;
  64. }