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++ / June 2007

Tip: Looking for answers? Try searching our database.

How to get an unmanaged pointer within VC++ .Net?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Orbian - 23 Jun 2007 01:36 GMT
I am using an unmanaged pointer and need to take the address of this
and pass it to a function (a pointer to a pointer). If the pointer is
defined as a global variable it will work, however if I move it into a
class variable I get teh following error:

error C2440: 'type cast' : cannot convert from 'IDevMgr *__gc * ' to
'IDevMgr ** '

Basically I want to go from:

IDevMgr *gDev;

public __gc class CMyClass
{
};

to:

public __gc class CMyClass
{
  private:
     IDevMgr *m_Dev;
};

and then do a:

MyFunc(&m_Dev);

from a member function in CMyClass. MyFunc(&gDev) will work fine
though.
Ben Voigt [C++ MVP] - 25 Jun 2007 06:38 GMT
> I am using an unmanaged pointer and need to take the address of this
> and pass it to a function (a pointer to a pointer). If the pointer is
[quoted text clipped - 26 lines]
> from a member function in CMyClass. MyFunc(&gDev) will work fine
> though.

You need a pinning pointer for that I think, and I only know how to do that
with C++/CLI.  The syntax you are using is obsolete and the Managed
Extensions for C++ that used that syntax are buggy and have no future.

The reason what you are doing doesn't work is that when the data is inside a
managed class, it is in the garbage collected heap, and can move around at
any time.

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.