c++ cli - Object Marshaling for C++/CLI Managed to Unmanaged Call -
i'm writing c++/cli extension, , having issues getting typing work out. i'd appreciate , hope i'm making simple mistake casting or passing parameters.
firstly, here definition of unmanaged function i'm trying call (and can't change):
int getresponse(const requestobject& requestobj, responseobject& responseobj);
second, unmanaged c++ requestobject has definition (which can't change):
class requestobject { public: requestobject(); void addelement(int value, int age); }
now, in managed c++/cli code (using 'ijw' interop ability), want call function. you'll note have unmanagedclassinstance (which holds method given above getresponse function definition), , managedrequestobject reqs (which managed version of want put requestobject).
requestobject* unrequest = new requestobject(); // here i'm taking things managed version of requestobject , making // unmanaged instances: each (managedrequestobject^ req in reqs) { unrequest->addelement(marshal_as<int>(req->getvalue()), marshal_as<int>(req->getage())); } // call unmanaged object request processed: responseobject* unresponse = new responseobject(); int result = unmanagedclassinstance->getresponse(unrequest, unresponse);
can please me understand how correctly pass unrequest , unresponse getresponse() function?
if keep using pointers unmanaged objects (which might want reconsiderate), should able call unmanaged function this:
int result = unmanagedclassinstance->getresponse(*unrequest, *unresponse);
but unless strictly necessary, i'd suggest instead:
requestobject unrequest; // here i'm taking things managed version of requestobject , making // unmanaged instances: each (managedrequestobject^ req in reqs) { unrequest.addelement(marshal_as<int>(req->getvalue()), marshal_as<int>(req->getage())); } // call unmanaged object request processed: responseobject unresponse; int result = unmanagedclassinstance->getresponse(unrequest, unresponse);
Comments
Post a Comment