Groups | Blog | Home
all groups > visual c > december 2006 >

visual c : Referencing an managed class from an unmanaged class?



Bruce
12/29/2006 10:47:01 PM

I need to fire an event from an unmanaged class. If I declare a pointer
to the managed class within the unmanaged class I get a compile error "

"cannot declare a managed 'm_pGps' in an unmanaged 'MyProgressNotifier'"


Any idea how I can do this?


--
Bruce E. Stemplewski
GarXface OCX and C++ Class Library for the Garmin GPS
Bruce
12/29/2006 10:54:04 PM
Here is what I need to do? I need top pass a pointer to the
MyProgressNotifier class to an unmanaged function. So the
MyProgressNotifier class cannot be managed. The NotifyTotal function
will be called from the mentioned unmanaged function.


class MyProgressNotifier : public GarXface4::ProgressNotifier
{

public:

MyProgressNotifier() :ProgressNotifier()
{


}


void NotifyTotal(int nTotal)
{
ProgressNotifier::NotifyTotal(nTotal);
// Fire managed event here

}


};



--
Bruce E. Stemplewski
GarXface OCX and C++ Class Library for the Garmin GPS
raylopez99
12/30/2006 1:34:16 AM
I have no idea Bruce. Though I don't code for a living, I would not
even mix unmanaged with managed code. Just start from a Tabula Rasa.

But do check something as fundamental as you are compiling with the
/clr option rather than /clr:safe option.

RL

[quoted text, click to view]
Ben Voigt
1/1/2007 10:50:14 AM

[quoted text, click to view]

gcroot<mngd_class*>

[quoted text, click to view]

Ben Voigt
1/1/2007 10:58:09 AM

[quoted text, click to view]

Sorry, meant gcroot<mngd_class^>

[quoted text, click to view]

Bruce
1/1/2007 2:13:45 PM
[quoted text, click to view]

Yes I finally found this in a search. Thank you. It is working perfectly.

Bruce E. Stemplewski
GarXface OCX and C++ Class Library for the Garmin GPS
Tamas Demjen
1/4/2007 11:38:49 AM
[quoted text, click to view]

I have examples for both ways:

http://tweakbits.com/ManagedToUnmanagedCallback.cpp
http://tweakbits.com/UnmanagedToManagedCallback.cpp

AddThis Social Bookmark Button