Using TTask::Future<> in Embarcadero XE7 C++ - 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?

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;"

Convert void (*)() to void (*)(unsigned char)

I'm trying to convert a void (*)() to void (*)(unsigned char) but my knowledge in C++ isn't good enough. I searched, but I could not find any examples. So I thought to create a function of function but I get some error:
typedef void (* voidFuncPtr)();
void castHandler(voidFuncPtr handler)(uint8_t gpio_num)
{
handler();
}
void attachInterrupt(uint8_t pin, voidFuncPtr handler, int mode)
{
// typedef void (* voidFuncPtr)();
// typedef void (* gpio_interrupt_handler_t)(uint8_t gpio_num);
// typedef void (* gpio_interrupt_handler_t)(unsigned char)
gpio_set_interrupt(pin, GPIO_INTTYPE_EDGE_ANY, castHandler(handler));
}
error: 'castHandler' declared as function returning a function void
castHandler(voidFuncPtr handler)(uint8_t gpio_num)
error: 'castHandler' was not declared in this scope
gpio_set_interrupt(pin, GPIO_INTTYPE_EDGE_ANY, castHandler(handler));
Can someone help me?
You need to maintain a table of handlers for each GPIO. Something like the following (untested and incomplete - some initializations and error checking are omitted) code:
typedef void (* voidFuncPtr)();
voidFuncPtr handlers[MAX_HANDLERS];
void attachInterrupt(uint8_t pin, voidFuncPtr handler, int mode)
{
handlers[pin] = handler;
}
void handleGPIO(unsigned char pin)
{
if (handlers[pin])
handlers[pin]();
}
void enableGPIOInterrupts(void)
{
/// Do this for each available pin
gpio_set_interrupt(pin, GPIO_INTTYPE_EDGE_ANY, handleGPIO);
}
Why not just write a function to do a redirection i.e.
void redirectFunction(unsigned char)
{
handler();
}
then
gpio_set_interrupt(pin, GPIO_INTTYPE_EDGE_ANY,redirectFunction);
EDIT
Perhaps this in C++:
void redirectFunction(std::function<void()> handler, unsigned char)
{
handler();
}
void wibble() { }
gpio_set_interrupt(pin, GPIO_INTTYPE_EDGE_ANY,
std::bind(redirectFunction, _1, wibble)
);

error: ISO C++ forbids declaration of 'core' with no type

I am getting error in the title. First of all, I did my search here in stackoverflow and in the google. There are many similar errors but I couldn't figure out how to solve the error. Some of the errors that I am getting with the error in the title are below. There are way many errors than the below errors but I just put a few of them.
core.cpp:9:102: error: ISO C++ forbids declaration of 'core' with no type [-fpermissive]
uint32_t number_of_core_msg_types, uint32_t msg_q_size, uint32_t bytes_per_flit) throw(err) :
core.cpp:9:102: error: 'int boost::core::core(const pe_id&, const uint64_t&, boost::shared_ptr<id_factory<long long unsigned int> >, boost::shared_ptr<tile_statistics>, logger&, boost::shared_ptr<random_gen>, boost::shared_ptr<memory>, uint32_t, uint32_t, uint32_t)' should have been declared inside 'boost::core'
core.cpp: In function 'int boost::core::core(const pe_id&, const uint64_t&, boost::shared_ptr<id_factory<long long unsigned int> >, boost::shared_ptr<tile_statistics>, logger&, boost::shared_ptr<random_gen>, boost::shared_ptr<memory>, uint32_t, uint32_t, uint32_t)':
core.cpp:10:5: error: only constructors take member initializers
pe(id), system_time(t), stats(st), log(l), ran(r),
Here is my core.hpp file:
#ifndef __CORE_HPP__
#define __CORE_HPP__
#include <vector>
#include <map>
#include <boost/shared_ptr.hpp>
#include <boost/bind.hpp>
#include "id_factory.hpp"
#include "logger.hpp"
#include "statistics.hpp"
#include "pe.hpp"
#include "random.hpp"
#include "bridge.hpp"
#include "messages.hpp"
#include "memory.hpp"
using namespace std;
using namespace boost;
/* core class provides common constructor process and connect process */
#define MAX_PAYLOAD 256
class core : public pe {
public:
core(const pe_id &id, const uint64_t &system_time,
shared_ptr<id_factory<packet_id> > packet_id_factory,
shared_ptr<tile_statistics> stats, logger &log,
shared_ptr<random_gen> ran,
shared_ptr<memory> mem,
uint32_t number_of_core_msg_types,
uint32_t msg_queue_size, uint32_t m_bytes_per_flit) throw(err);
virtual ~core() throw();
/* Common core methods */
virtual void connect(shared_ptr<bridge> net_bridge) throw(err);
virtual void tick_positive_edge() throw(err);
virtual void tick_negative_edge() throw(err);
/* Fast forwarding */
virtual uint64_t next_pkt_time() throw(err);
virtual bool is_drained() const throw() = 0;
/* not used */
virtual void add_packet(uint64_t time, const flow_id &flow, uint32_t len) throw(err);
virtual bool work_queued() throw(err);
virtual bool is_ready_to_offer() throw(err);
virtual void set_stop_darsim() throw(err);
protected:
/* implement core logic */
virtual void execute() = 0;
/* check and update finished memory requests */
virtual void update_from_memory_requests() = 0;
void tick_positive_edge_memory() throw(err);
void tick_negative_edge_memory() throw(err);
/* use these queues to use the network */
shared_ptr<messageQueue> receive_queue(uint32_t type);
shared_ptr<messageQueue> send_queue(uint32_t type);
/* Global time */
const uint64_t &system_time;
/* Aux */
shared_ptr<tile_statistics> stats;
logger &log;
shared_ptr<random_gen> ran;
uint32_t m_number_of_msg_types;
uint32_t m_first_core_msg_type;
uint32_t m_msg_queue_size;
uint32_t m_bytes_per_flit;
/* memory */
shared_ptr<memory> m_memory;
private:
typedef struct {
packet_id id;
flow_id flow;
uint32_t len;
uint32_t xmit;
uint64_t payload[MAX_PAYLOAD];
} core_incoming_packet_t;
typedef map<uint32_t, core_incoming_packet_t> incoming_packets_t;
void release_xmit_buffer();
map<uint32_t/*msg type*/, shared_ptr<messageQueue> > m_out_msg_queues;
map<uint32_t/*msg type*/, shared_ptr<messageQueue> > m_in_msg_queues;
/* Network */
shared_ptr<bridge> m_net;
vector<uint32_t> m_queue_ids;
incoming_packets_t m_incoming_packets;
shared_ptr<id_factory<packet_id> > m_packet_id_factory;
map<uint32_t, uint64_t*> m_xmit_buffer;
uint32_t m_receive_channel_round_robin_pointer;
uint32_t m_send_queue_round_robin_pointer;
};
#endif
and here is relevant part of the core.cpp file:
#include "core.hpp"
core::core(const pe_id &id, const uint64_t &t, shared_ptr<id_factory<packet_id> > pif,
shared_ptr<tile_statistics> st, logger &l, shared_ptr<random_gen> r,
shared_ptr<memory> mem,
uint32_t number_of_core_msg_types, uint32_t msg_q_size, uint32_t bytes_per_flit) throw(err) :
pe(id), system_time(t), stats(st), log(l), ran(r),
m_msg_queue_size(msg_q_size), m_bytes_per_flit(bytes_per_flit), m_memory(mem), m_packet_id_factory(pif),
m_receive_channel_round_robin_pointer(0), m_send_queue_round_robin_pointer(0)
{
m_number_of_msg_types = number_of_core_msg_types + mem->number_of_mem_msg_types();
m_first_core_msg_type = mem->number_of_mem_msg_types();
for (uint32_t i = 0; i < m_number_of_msg_types; ++i) {
m_in_msg_queues[i] = shared_ptr<messageQueue> (new messageQueue(i, m_msg_queue_size));
m_out_msg_queues[i] = shared_ptr<messageQueue> (new messageQueue(i, m_msg_queue_size));
}
m_memory->set_core_send_queues(m_out_msg_queues);
m_memory->set_core_receive_queues(m_in_msg_queues);
}
core::~core() throw() { }
void core::connect(shared_ptr<bridge> net_bridge) throw(err) {
m_net = net_bridge;
shared_ptr<vector<uint32_t> > qs = m_net->get_ingress_queue_ids();
m_queue_ids.clear();
copy(qs->begin(), qs->end(), back_insert_iterator<vector<uint32_t> >(m_queue_ids));
}
shared_ptr<messageQueue> core::receive_queue(uint32_t type) {
assert((uint32_t)type < m_number_of_msg_types);
return m_in_msg_queues[type];
}
shared_ptr<messageQueue> core::send_queue(uint32_t type) {
assert((uint32_t)type < m_number_of_msg_types);
return m_out_msg_queues[type];
}
void core::release_xmit_buffer() {
/* release xmit buffer for injection if transmission is done */
for (map<uint32_t, uint64_t*>::iterator i = m_xmit_buffer.begin(); i != m_xmit_buffer.end(); ++i) {
if (m_net->get_transmission_done(i->first)) {
delete[] i->second;
m_xmit_buffer.erase(i->first);
break;
}
}
}
.......
.......
.......
Can anyone point out what the problem is? By the way, I am trying to compile a program and these codes are the parts of the program.

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?

C#.Net Calling a C++ DLL

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.