Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / March 2005

Tip: Looking for answers? Try searching our database.

Converting Int32 * to int * for CLS compliancy.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jason Bell - 24 Mar 2005 07:14 GMT
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
Jason Bell - 24 Mar 2005 07:23 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.