C#.Net Calling a C++ DLL - c++

I got a DLL(without the sourcecode) which exports like this:
?ReceiveCoreDataPtr##YAXPAX#Z
?xenoAddRigidBodyAngularImpulse##YAXHMMM#Z
?xenoAddRigidBodyForce##YAXHMMM#Z
?xenoAddRigidBodyForce##YAXHMMMMMM#Z
?xenoAddRigidBodyLinearImpulse##YAXHMMM#Z
?xenoAddRigidBodyPointImpulse##YAXHMMMMMM#Z
?xenoAddRigidBodyTorque##YAXHMMM#Z
?xenoCharacterControllerCrouch##YAXH#Z
?xenoCharacterControllerJump##YAXH#Z
?xenoCharacterDisable##YAXH#Z
?xenoCharacterEnable##YAXH#Z
?xenoDeleteRigidBody##YAXH#Z
?xenoEnd##YAXXZ
?xenoGetCameraFOV##YAKH#Z
?xenoGetCameraPointX##YAKH#Z
?xenoGetCameraPointY##YAKH#Z
?xenoGetCameraPointZ##YAKH#Z
?xenoGetCameraPositionX##YAKH#Z
?xenoGetCameraPositionY##YAKH#Z
?xenoGetCameraPositionZ##YAKH#Z
?xenoGetCharacterControllerHeadPosition##YAKH#Z
?xenoGetCharacterControllerPositionX##YAKH#Z
?xenoGetCharacterControllerPositionY##YAKH#Z
?xenoGetCharacterControllerPositionZ##YAKH#Z
?xenoGetCharacterControllerRotation##YAKH#Z
?xenoGetRigidBodyAllowedPenetrationDepth##YAKH#Z
?xenoGetRigidBodyAngularDamping##YAKH#Z
?xenoGetRigidBodyAngularVelocityX##YAKH#Z
?xenoGetRigidBodyAngularVelocityY##YAKH#Z
?xenoGetRigidBodyAngularVelocityZ##YAKH#Z
?xenoGetRigidBodyFriction##YAKH#Z
?xenoGetRigidBodyGravityFactor##YAKH#Z
?xenoGetRigidBodyLinearDamping##YAKH#Z
?xenoGetRigidBodyLinearVelocityX##YAKH#Z
?xenoGetRigidBodyLinearVelocityY##YAKH#Z
?xenoGetRigidBodyLinearVelocityZ##YAKH#Z
?xenoGetRigidBodyMass##YAKH#Z
?xenoGetRigidBodyMaxAngularVelocity##YAKH#Z
?xenoGetRigidBodyMaxLinearVelocity##YAKH#Z
?xenoGetRigidBodyPointVelocityX##YAKHMMM#Z
?xenoGetRigidBodyPointVelocityY##YAKHMMM#Z
?xenoGetRigidBodyPointVelocityZ##YAKHMMM#Z
?xenoGetRigidBodyRestitution##YAKH#Z
?xenoIsRigidBodyALadder##YAHH#Z
?xenoMakeCamera##YAXHH#Z
?xenoMakeCharacterController##YAXHMM#Z
?xenoMakeCharacterController##YAXHMMM#Z
?xenoMakeCharacterController##YAXHMMMM#Z
?xenoMakeCharacterController##YAXHMMMMM#Z
?xenoMakeCharacterController##YAXHMMMMMM#Z
?xenoMakeCharacterController##YAXHMMMMMMM#Z
?xenoMakeRigidBodyDynamicBox##YAXH#Z
?xenoMakeRigidBodyDynamicBox##YAXHM#Z
?xenoMakeRigidBodyDynamicCapsule##YAXH#Z
?xenoMakeRigidBodyDynamicCapsule##YAXHM#Z
?xenoMakeRigidBodyDynamicCylinder##YAXH#Z
?xenoMakeRigidBodyDynamicCylinder##YAXHM#Z
?xenoMakeRigidBodyDynamicSphere##YAXH#Z
?xenoMakeRigidBodyDynamicSphere##YAXHM#Z
?xenoMakeRigidBodyStaticBox##YAXH#Z
?xenoMakeRigidBodyStaticCapsule##YAXH#Z
?xenoMakeRigidBodyStaticCylinder##YAXH#Z
?xenoMakeRigidBodyStaticSphere##YAXH#Z
?xenoMakeRigidBodyStaticTriangleMesh##YAXH#Z
?xenoMakeVehicle##YAXHH#Z
?xenoMoveCharacterControllerBackward##YAXH#Z
?xenoMoveCharacterControllerForward##YAXH#Z
?xenoMoveCharacterControllerLeft##YAXH#Z
?xenoMoveCharacterControllerRight##YAXH#Z
?xenoSetCharacterControllerPosition##YAXHMMM#Z
?xenoSetCharacterControllerRotation##YAXHM#Z
?xenoSetGravity##YAXM#Z
?xenoSetGravity##YAXMMM#Z
?xenoSetRigidBodyAllowedPenetrationDepth##YAXHM#Z
?xenoSetRigidBodyAngularDamping##YAXHM#Z
?xenoSetRigidBodyAngularVelocity##YAXHMMM#Z
?xenoSetRigidBodyAsLadder##YAXHH#Z
?xenoSetRigidBodyFriction##YAXHM#Z
?xenoSetRigidBodyGravityFactor##YAXHM#Z
?xenoSetRigidBodyLinearDamping##YAXHM#Z
?xenoSetRigidBodyLinearVelocity##YAXHMMM#Z
?xenoSetRigidBodyMass##YAXHM#Z
?xenoSetRigidBodyMaxAngularVelocity##YAXHM#Z
?xenoSetRigidBodyMaxLinearVelocity##YAXHM#Z
?xenoSetRigidBodyPosition##YAXHMMM#Z
?xenoSetRigidBodyRestitution##YAXHM#Z
?xenoSetRigidBodyRotation##YAXHMMM#Z
?xenoSetTimeStep##YAXM#Z
?xenoStart##YAXH#Z
?xenoStart##YAXHM#Z
?xenoStart##YAXHMH#Z
?xenoStart##YAXXZ
?xenoUpdate##YAXXZ
?xenoVehicleAccelerate##YAXHM#Z
?xenoVehicleHandbrake##YAXH#Z
?xenoVehicleReverse##YAXH#Z
?xenoVehicleTurn##YAXHM#Z
When I try to use it in another C++ App like this
#include <windows.h>
class XenoPhysics
{
private:
typedef void (*FunctionFunc)(void);
typedef void (*FunctionFuncFloat)(float);
typedef void (*FunctionFuncInt)(int);
typedef void (*FunctionIntFloatFloatFloat)(int,float,float,float);
HMODULE libInstance;
public:
void LoadLib()
{
this->libInstance = LoadLibrary(L"F:\\xenophysics.dll");
}
void UnloadLib()
{
FreeLibrary(libInstance);
}
void xStart()
{
FunctionFunc curFunc;
curFunc = (FunctionFunc)GetProcAddress(this->libInstance, "?xenoStart##YAXXZ");
curFunc();
}
void xEnd()
{
FunctionFunc curFunc;
curFunc = (FunctionFunc)GetProcAddress(libInstance, "xenoEnd");
curFunc();
}
void xUpdate()
{
FunctionFunc curFunc;
curFunc = (FunctionFunc)GetProcAddress(libInstance, "xenoUpdate");
curFunc();
}
void xMakeRigidBodyStaticBox(int objid)
{
FunctionFuncInt curFunc;
curFunc = (FunctionFuncInt)GetProcAddress(libInstance, "xenoMakeRigidBodyStaticBox");
curFunc(objid);
}
void xMakeRigidBodyDynamicBox(int objid)
{
FunctionFuncInt curFunc;
curFunc = (FunctionFuncInt)GetProcAddress(libInstance, "xenoMakeRigidBodyDynamicBox");
curFunc(objid);
}
void xSetRigidBodyPosition(int objid, float x, float y, float z)
{
FunctionIntFloatFloatFloat curFunc;
curFunc = (FunctionIntFloatFloatFloat)GetProcAddress(libInstance, "xenoSetRigidBodyPosition");
curFunc(objid, x, y, z);
}
void xSetGravity(float grav)
{
FunctionFuncFloat curFunc;
curFunc = (FunctionFuncFloat)GetProcAddress(libInstance, "xenoSetGravity");
curFunc(grav);
}
};
This is the "wrapper"(or whatever you would call it) class.. To call the functions I'm doing
XenoPhysics * d = new XenoPhysics();
d->LoadLib();
d->xStart();
It then throws the following error at me(Note that it passes the LoadLib() without any errors)
Unhandled exception at 0x50261bc9 in Xeno Test.exe: 0xC0000005: Access violation reading location 0x00000064.
And yes; I've checked that the "curFunc" gets the address, not just a NULL pointer(atleast I think I've checked that)..
Anyone who can help out?
Edit: Forgot the C#.Net code, how stupid of me :3
Here is the C++ CLR DLL "wrapper" I tried to make:
#include <windows.h>
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the XENOWRAPPERWIN32_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// XENOWRAPPERWIN32_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#ifdef XENOWRAPPERWIN32_EXPORTS
#define XENOWRAPPERWIN32_API __declspec(dllexport)
#else
#define XENOWRAPPERWIN32_API __declspec(dllimport)
#endif
typedef void (*FunctionFunc)();
typedef void (*FunctionFuncFloat)(float);
typedef void (*FunctionFuncInt)(int);
typedef void (*FunctionIntFloatFloatFloat)(int,float,float,float);
// This class is exported from the xeno wrapper win32.dll
class XENOWRAPPERWIN32_API Cxenowrapperwin32 {
public:
Cxenowrapperwin32(void);
HINSTANCE libInstance;
// FunctionFunc curFunc;
// Library base functions
void LoadLib()
{
libInstance = LoadLibrary(L"F:\\xenophysics.dll");
}
void UnloadLib()
{
FreeLibrary(libInstance);
}
// Function calls to the xeno physics
void xStart()
{
FunctionFunc curFunc;
curFunc = (FunctionFunc)GetProcAddress(libInstance, "?xenoStart##YAXXZ");
curFunc();
}
void xEnd()
{
FunctionFunc curFunc;
curFunc = (FunctionFunc)GetProcAddress(libInstance, "?xenoEnd##YAXXZ");
curFunc();
}
void xUpdate()
{
FunctionFunc curFunc;
curFunc = (FunctionFunc)GetProcAddress(libInstance, "?xenoUpdate##YAXXZ");
curFunc();
}
void xMakeRigidBodyStaticBox(int objid)
{
FunctionFuncInt curFunc;
curFunc = (FunctionFuncInt)GetProcAddress(libInstance, "?xenoMakeRigidBodyStaticBox##YAXH#Z");
curFunc(objid);
}
void xMakeRigidBodyDynamicBox(int objid)
{
FunctionFuncInt curFunc;
curFunc = (FunctionFuncInt)GetProcAddress(libInstance, "?xenoMakeRigidBodyDynamicBox##YAXH#Z");
curFunc(objid);
}
void xSetRigidBodyPosition(int objid, float x, float y, float z)
{
FunctionIntFloatFloatFloat curFunc;
curFunc = (FunctionIntFloatFloatFloat)GetProcAddress(libInstance, "?xenoSetRigidBodyPosition##YAXHMMM#Z");
curFunc(objid, x, y, z);
}
void xSetGravity(float grav)
{
FunctionFuncFloat curFunc;
curFunc = (FunctionFuncFloat)GetProcAddress(libInstance, "?xenoSetGravity##YAXM#Z");
curFunc(grav);
}
};
extern XENOWRAPPERWIN32_API int nxenowrapperwin32;
XENOWRAPPERWIN32_API int fnxenowrapperwin32(void);
and here is how I use it in C#.Net
class xeno
{
[DllImport("C:\\Users\\hayer\\Documents\\Visual Studio 2008\\Projects\\xeno wrapper win32\\Debug\\xeno wrapper win32.dll", EntryPoint = "?LoadLib#Cxenowrapperwin32##QAEXXZ")]
public static extern void xLoadLib();
public void LoadLib()
{
xLoadLib();
}
[DllImport("C:\\Users\\hayer\\Documents\\Visual Studio 2008\\Projects\\xeno wrapper win32\\Debug\\xeno wrapper win32.dll", EntryPoint = "?UnloadLib#Cxenowrapperwin32##QAEXXZ")]
public static extern void xUnloadLib();
public void UnloadLib()
{
xUnloadLib();
}
[DllImport("C:\\Users\\hayer\\Documents\\Visual Studio 2008\\Projects\\xeno wrapper win32\\Debug\\xeno wrapper win32.dll", EntryPoint = "?xStart#Cxenowrapperwin32##QAEXXZ")]
public static extern void xStart();
public void Start()
{
xStart();
}
[DllImport("C:\\Users\\hayer\\Documents\\Visual Studio 2008\\Projects\\xeno wrapper win32\\Debug\\xeno wrapper win32.dll", EntryPoint = "?xUpdate#Cxenowrapperwin32##QAEXXZ")]
public static extern void xUpdate();
public void Update()
{
xUpdate();
}
[DllImport("C:\\Users\\hayer\\Documents\\Visual Studio 2008\\Projects\\xeno wrapper win32\\Debug\\xeno wrapper win32.dll", EntryPoint = "?xEnd#Cxenowrapperwin32##QAEXXZ")]
public static extern void xEnd();
public void End()
{
xEnd();
}
[DllImport("C:\\Users\\hayer\\Documents\\Visual Studio 2008\\Projects\\xeno wrapper win32\\Debug\\xeno wrapper win32.dll", EntryPoint = "?xMakeRigidBodyDynamicBox#Cxenowrapperwin32##QAEXH#Z")]
public static extern void xMakeRigidBodyDynamicBox(int objid);
public void MakeRigidBodyDynamicBox(int id)
{
xMakeRigidBodyDynamicBox(id);
}
[DllImport("C:\\Users\\hayer\\Documents\\Visual Studio 2008\\Projects\\xeno wrapper win32\\Debug\\xeno wrapper win32.dll", EntryPoint = "?xMakeRigidBodyStaticBox#Cxenowrapperwin32##QAEXH#Z")]
public static extern void xMakeRigidBodyStaticBox(int objid);
public void MakeRigidBodyStaticBox(int id)
{
xMakeRigidBodyStaticBox(id);
}
[DllImport("C:\\Users\\hayer\\Documents\\Visual Studio 2008\\Projects\\xeno wrapper win32\\Debug\\xeno wrapper win32.dll", EntryPoint = "?xSetGravity#Cxenowrapperwin32##QAEXM#Z")]
public static extern void xSetGravity(float grav);
public void SetGravity(float g)
{
xSetGravity(g);
}
[DllImport("C:\\Users\\hayer\\Documents\\Visual Studio 2008\\Projects\\xeno wrapper win32\\Debug\\xeno wrapper win32.dll", EntryPoint = "?xSetRigidBodyPosition#Cxenowrapperwin32##QAEXHMMM#Z")]
public static extern void xSetRigidBodyPosition(int obj, float x, float y, float z);
public void SetRigidBodyPosition(int id, float q, float w, float e)
{
xSetRigidBodyPosition(id, q, w, e);
}
}
And in the main C#.Net program I do
xeno tx = new xeno();
tx.Start();
tx.SetGravity(-1);
tx.MakeRigidBodyStaticBox(ground.Id);
tx.MakeRigidBodyDynamicBox(cube.Id);
tx.SetRigidBodyPosition(cube.Id, 0, 50, 0);

You must use proper calling conversion and parameters.

Related

JNI Error : java.lang.NoSuchMethodError: no static method

Error Message : Pending exception java.lang.NoSuchMethodError thrown by 'void com.exampleTest.NDKT.I(android.app.Activity):-2'
java.lang.NoSuchMethodError: no static method "Lcom/exampleTest/NDKT;.PN()Ljava/lang/String;"
I should try ndk c++ call java method because i want you java method thought android package name know
i tried below
java call method String -> void change
=> c++ : jmethodID jMethod = pE->GetStaticMethodID(jClass, "GO", "()V");
java code "this" -> "MainActivity.this"
- Java code
CallNDK class{
public static void initialize(final Activity a,final SIMECB cb) {
System.loadLibrary("simpleinit");
_CB = cb;
_INSTANCE = new CallNDK();
new Thread(new Runnable() {
public void run() {
_INSTANCE.I(a);
}
}).start();
}
}
==> initialize () -> Activity = MainActivity.this
- NDK
CallNDK.cpp
static string mPN; //Packege Name
#ifdef __ANDROID__
void CallNDK::I(JNIEnv* pE, jobject pA){
// Package Name Method call
CHECK::PN(pE, mPN);
}
CHECK.h
#ifndef CHECK_H_
#define CHECK_H_
#ifdef __ANDROID__
#include <jni.h>
#endif
using namespace std;
class CHECK {
public:
#ifdef __ANDROID__
static void PN(
JNIEnv* pE,
string& pO);
#endif
};
#endif
CHECK.cpp
#include "CHECK.h"
#ifdef __ANDROID__
#include <jni.h>
#endif
using namespace std;
#ifdef __ANDROID__
void CHECK::PN(JNIEnv* pE, string& pO){
jclass classes = pE->FindClass("com/exampleTest/NDKT");
jmethodID jMethod = pE->GetMethodID(classes, "SimpleMethod", ()Ljava/lang/String;");
if(!jMethod) {
CALLUtil::LOG("class loader method access");
return;
}
jstring jsResult = (jstring)pE->CallStaticObjectMethod(jClass, jMethod);
const char* cResult = pE->GetStringUTFChars(jsResult, NULL);
std::string sResult(cResult);
pO = sResult;
}
- NDK of call java class code
enter code here
NDKT Class {
private static int _MAX_TRY_INVOKE_COUNT = 5;
public static String SimpleMethod(Activity a){
for(int i = 0; i < _MAX_TRY_INVOKE_COUNT; i++) {
try {
return a.getApplicationContext().getPackageName();
} catch (Exception e) {
try { Thread.sleep(50); } catch (Exception e2) { }
}
}
return ""
}
}
Error
JNI DETECTED ERROR IN APPLICATION:
JNI FindClass called with pending exception 'java.lang.NoSuchMethodError' thrown in void com.exampleTest.CallNDK.I(android.app.Activity):-2 in call to FindClass from void com.exampleText.CallNDK.I(android.app.Activity)
Pending exception java.lang.NoSuchMethodError thrown by 'void com.exampleTest.NDKT.I(android.app.Activity):-2'
java.lang.NoSuchMethodError: no static method "Lcom/exampleTest/NDKT;.PN()Ljava/lang/String;"

Using TTask::Future<> in Embarcadero XE7 C++

I tried to make "Tutorial: Using Futures from the Parallel Programming Library" from here.
I created project "File > New > Multi-Device Application - C++Builder > Blank Application" and copy source from link.
#include <System.Threading.hpp>
.h
public: // User declarations
System::DelphiInterface<IFuture__1<System::String> > FutureString;
System::String __fastcall FutureHandler(TObject* Sender);
.cpp
void __fastcall TForm1::Button1Click(TObject *Sender) {
FutureString = TTask::Future<System::String>(0, this->FutureHandler);
}
System::String __fastcall TForm1::FutureHandler(TObject* Sender) {
Sleep(3000);
System::String str = System::String().sprintf(L"Hello %d", Random(42));
return str;
}
After build I'm getting this error message:
[ilink64 Error] Error: Unresolved external 'System::DelphiInterface > System::Threading::TTask::Future(System::TObject*, System::UnicodeString (* __closure)(System::TObject*))' referenced from C:\USERS\PC\DESKTOP\64BIT\WIN64\DEBUG\UNIT1.O
declaration from System.Threading.hpp
template<typename T> static System::DelphiInterface<IFuture__1<T> >
__fastcall Future(System::TObject* Sender, T __fastcall (__closure *)
(System::TObject* Sender) )/* overload */;
===
protected:
HIDESBASE System::DelphiInterface<IFuture__1<T> > __fastcall Start(void);
T __fastcall GetValue(void);
#ifndef _WIN64
typedef T __fastcall (__closure *_dt_System_Threading_2)(System::TObject* Sender);
__fastcall TFuture__1(System::TObject* Sender, _dt_System_Threading_2 Event,
const System::DelphiInterface<System::Sysutils::TFunc__1<T> > Func, TThreadPool* APool)/* overload */;
#else /* _WIN64 */
__fastcall TFuture__1(System::TObject* Sender, TFunctionEvent__1<T> Event, const System::DelphiInterface<System::Sysutils::TFunc__1<T> > Func, TThreadPool*
APool)/* overload */;
#endif /* _WIN64 */
private:
// __classmethod void __fastcall Destroy#();
protected:
/* TTask.Create */ inline __fastcall TFuture__1(System::TObject* Sender,
System::Classes::TNotifyEvent Event, const System::Sysutils::_di_TProc AProc, TThreadPool* const APool, TTask* const AParent, TTask::TCreateFlags CreateFlags)/* overload */ : TTask(Sender, Event, AProc, APool, AParent, CreateFlags) { }
public:
/* TTask.Create */ inline __fastcall TFuture__1(void)/* overload */ :
TTask() { }
/* TTask.Destroy */ inline __fastcall virtual ~TFuture__1(void) { }
private:
void *__IFuture__1; // IFuture__1<T>
public:
operator IFuture__1<T>*(void) { return (IFuture__1<T>*)&__IFuture__1; }
};
how to cope with this error?

Undefined reference to vtable SFML Android

I am compiling a program that uses SFML on android. It compiles normally when I compile it with g++. When I run ndk-build in the android project directory I get the following error:
/home/engineer/Desktop/android_ndk/android-ndk-r11c/toolchains/arm- linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/ld: the vtable symbol may be undefined because the class is missing its key function (see go/missingkeymethod)
/home/engineer/Desktop/android/jni/SandJar.hpp:16: error: undefined reference to 'vtable for SandJar'
I have an abstract class jar and 2 class sandyJar and sandjar that both inherit it. However, I don't understand why it compiles for g++ but doesnt for the ndk-build command.
Here are some of the source files stripped down(it compiles from main):
Main.cpp:
int main(int argc, char *argv[])
{
sf::RenderWindow window(sf::VideoMode::getDesktopMode(), "");
int WIDTH = window.getSize().x;
int HEIGHT = window.getSize().y;
vector<Jar*> jars;
SandJar SJAR(5,5,5,WIDTH, HEIGHT);
CandyJar CJAR(5,5,5,WIDTH, HEIGHT);
CJAR.add();
CJAR.move(120, 0);
jars.push_back(&CJAR);
jars.push_back(&SJAR);
etc.
}
Jar.hpp
class Jar
{
public:
virtual void add() = 0;
virtual void draw(sf::RenderWindow&) = 0;
virtual void update() = 0;
virtual void move(int,int) = 0;
virtual void setScale(float) = 0;
virtual void incAnim() = 0;
virtual void decAnim() = 0;
};
SandJar.hpp
class SandJar : public Jar
{
public:
//initializer
SandJar(const int, const int, const int, const int, const int);
SandJar(const int);
//function for adding candy
void add();
void update();
void draw(sf::RenderWindow&);
void incAnim();
void decAnim();
void move(int, int);
void setScale(float);
private:
//vars
};
SandJar.cpp
SandJar::SandJar(int Capacity){
}
SandJar::SandJar(int Width, int Height, int Capacity, int WindowW, int WindowH){
}
void SandJar::init() {
}
void SandJar::incAnim() {
}
void SandJar::decAnim() {
}
void SandJar::move(int x, int y)
{
}
void SandJar::setScale(float scl)
{
}
void SandJar::update() {
}
void SandJar::add() {
}
void SandJar::draw(sf::RenderWindow& window) {
}
As it turns out there was no problem with any of the code. The problem was the Android.mk file used for the project. I appended the hpp and cpp files to LOCAL_SRC_FILES and it built correctly. It says not to include "includes" in LOCAL_SRC_FILES but once added it compiled correctly. There may be a better fix.

ARM GNU GCC(C++) path configuration related issue on Eclipse Platform

I'm trying to make Wrapper class for FreeRTOS on ARM GNU compiler with C++. I did it on Keil MDK-ARM v5.14 without any problem but I cant accomplish on eclipse platform. I think it is about my wrong Source Location configuration on eclipse.
I'm using Eclipse Luna 4.4.2, ARM GNU GCC 4.9.2 and GNU ARM Eclipse Plug-ins
Here is my Wrapper class interface:
#ifndef TASKOOP_H_
#define TASKOOP_H_
#include "FreeRTOS.h"
#include "task.h"
class TaskOOP {
private:
TaskHandle_t _handle;
public:
TaskOOP();
virtual ~TaskOOP();//xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
void create(const char * const pcName, const uint16_t usStackDepth, UBaseType_t uxPriority); //xTaskCreate( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask )
void deleteT(); //vTaskDelete( TaskHandle_t xTaskToDelete )
void suspend(); //vTaskSuspend( TaskHandle_t xTaskToSuspend )
void resume(); //vTaskResume( TaskHandle_t xTaskToResume )
UBaseType_t getTaskPriority(); //uxTaskPriorityGet( TaskHandle_t xTask )
void setTaskPriority(UBaseType_t uxNewPriority); //vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority )
static void delay(const TickType_t xTicksToDelay); //vTaskDelay( const TickType_t xTicksToDelay )
static void vTaskStartScheduler( void );
static void vTaskEndScheduler( void );
static void vTaskSuspendAll( void );
static BaseType_t xTaskResumeAll( void );
private:
static void bridge(void* pThis);
protected:
virtual void run(void) = 0;
};
#endif /* TASKOOP_H_ */
Here is my implementation:
#include "TaskOOP.h"
TaskOOP::TaskOOP():_handle(0) {
// TODO Auto-generated constructor stub
}
TaskOOP::~TaskOOP() {
// TODO Auto-generated destructor stub
}
void TaskOOP::create(const char * const pcName, const uint16_t usStackDepth, UBaseType_t uxPriority){
xTaskCreate(bridge,pcName,usStackDepth,this,uxPriority,&_handle);
}
void TaskOOP::deleteT(){
vTaskDelete(_handle);
}
void TaskOOP::suspend(){
vTaskSuspend(_handle);
}
void TaskOOP::resume(){
vTaskResume(_handle);
}
UBaseType_t TaskOOP::getTaskPriority(){
return uxTaskPriorityGet(_handle);
}
void TaskOOP::setTaskPriority(UBaseType_t uxNewPriority){
vTaskPrioritySet( _handle, uxNewPriority );
}
void TaskOOP::delay(const TickType_t xTicksToDelay){
vTaskDelay(xTicksToDelay);
}
void TaskOOP::vTaskStartScheduler(void){
vTaskStartScheduler();
}
void TaskOOP::vTaskEndScheduler(void){
vTaskEndScheduler();
}
void TaskOOP::vTaskSuspendAll(void){
vTaskSuspendAll();
}
BaseType_t TaskOOP::xTaskResumeAll( void ){
return xTaskResumeAll();
}
void TaskOOP::bridge(void* pThis){
TaskOOP* task = (TaskOOP *)pThis;
task->run();
}
Here are some print-screens from my eclipse settings:
I cant upload them as image because I dont have enough reputation.
So the question is how should I configure my Path and Source Location?

Define Threads in Visual Studio 2010

I want to create a C++ application in Visual Studio 2010 which contains 2 threads:
read data from a extern file
write data to an extern file
I already read the theory about threading but don't really understand how I can use it. Is there anybody who can show me how I can simply define and run these 2 threads in Visual Studio 2010?
Currently I have the following example which doesn't work:
class Thread
{
public:
Thread();
int Start(void * arg);
protected:
int Run(void * arg);
static void * EntryPoint(void*);
virtual void Setup();
virtual void Execute(void*);
void * Arg() const {return Arg_;}
void Arg(void* a){Arg_ = a;}
private:
THREADID ThreadId_;
void * Arg_;
};
Thread::Thread() {}
int Thread::Start(void * arg)
{
Arg(arg); // store user data
int code = thread_create(Thread::EntryPoint, this, & ThreadId_);
return code;
}
int Thread::Run(void * arg)
{
Setup();
Execute( arg );
}
/*static */
void * Thread::EntryPoint(void * pthis)
{
Thread * pt = (Thread*)pthis;
pt->Run( pt->Arg() );
}
virtual void Thread::Setup()
{
// Do any setup here
}
virtual void Thread::Execute(void* arg)
{
// Your code goes here
}
I am also open for good tutorials or code examples.
If the program does not compile, you should include the headers of the undefined functions as specified in http://www.MSDN.com . Also make shure the thread is not started from a DLL entrypoint (such as DllMain()).
Also, you should compile with multithreading enabled (i believe it is /MT option).