idl chapter (in c++) duty take c-style array c#


i am operative an existent formula bottom finished adult com interfaces combined c++ c# front end. there new functionality needs added, i'm carrying cgange com portions. sole case, i need pass an array (allocated c#) member filled.



what i means pass an array int slight c#, something like:



// preferred c# signature
void getfoo(int buffersize, int[] buffer);

// preferred usage
int[] blah = ...;
getfoo(blah.length, blah);


a integrate wrenches works:




  • c++/cli managed c++ can't used (com finished divided case).

  • the c# side can't collected /unsafe (using organise allowed).



the com interface wholly used (an wholly ever used) c# part, i'm reduction concerned interoperability com consumers. portability between 32 64 bit also pleasantness (everything being collected run 32 bit machine, formula generators converting pointers integers). eventually, transposed only c++/cli, nonetheless ways off.






my initial attempt



is something identical to:



hresult getfoo([in] int buffersize, [in, size_is(buffersize)] int buffer[]);


and cost tlb construction (seems reasonable):



hresult _stdcall getfoo([in] int buffersize, [in] int* buffer);


which alien c# (not reasonable):



void getfoo(int buffersize, ref int buffer);


which i could with



int[] b = ...;
fixed(int *bp = &b[0])
{
getfoo(b.length, ref *bp);
}


...except i can't accumulate /unsafe.






at moment



i am using:



hresult getfoo([in] int buffersize, [in] int_ptr buffer);


which imports as:



void getfoo(int buffersize, int buffer);


and i need use like:



int[] b = ...;
gchandle bpin = gchandle.alloc(b, gchandletype.pinned);
try
{
getfoo(b.length, (int)marshal.unsafeaddrofpinnedarrayelement(b, 0));
}
finally
{
bpin.free();
}


which works..., nonetheless i'd cleaner way.






so, doubt is



is there an idl construction permitted c# import tlb generator case? not, finished c# side small safer?



Comments

Popular posts from this blog

list macos calm editors formula editors

how hibernate @any-related annotations?

why does floated <input> control floated component slip over too distant right ie7, nonetheless firefox?