Converting Int32 * to int * for CLS compliancy.

J

Jason Bell

While I'm experienced with c# and regular c++, I'm very new to managed
c++ so please bare with me.

Here's the scenario:

I have a function that wraps a pointer to an unmanaged function. I want
the wrapping function to be CLS compliant.

Here's what I have now. It works perfectly, but isn't CLS compliant:

void gle::GenBuffersARB( int number, int * buffer )
{
glGenBuffersARB(number, buffer);
}

glGenBuffersARB is the pointer to the unmanaged function. The second
parameter must be a pointer to an unmanaged int. I tried using Int32s
in the function pointer declaration, but that causes
system.typeloadexception. And before you mention it, yes I do have to
use a function pointer to use this function, you can't do simple
external declarations for OpenGL extensions.

I would like something like this:

void gle::GenBuffersARB( Int32 number, Int32 * buffer )

This is CLS compliant: the second parameter is seen as ref int by c# and
byref by vb.net.

How would I convert a reference to a managed Int32 into a pointer to an
unmanaged int? I looked at __box, but that creates a copy. This won't
work because glGenBuffersARB must change the original "buffer" int
passed to the wrapping function. Even if I could do something like
this, that would help:

copy numbers from Int32 buffer to a new int
pass pointer to the new int to glGenBuffersARB
copy the modified numbers in the int back to the Int32
 
J

Jason Bell

haha never mind, a blonde moment. I whipped up a very easy solution:

void gle::GenBuffersARB( Int32 number, Int32 * buffer )
{
int tempbuffer = *buffer;
int tempnumber = number;

gle::glGenBuffersARB( tempnumber, &tempbuffer );
*buffer = tempbuffer;
}

voila
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top