invalid operand for __typeof, expected a fully defined managed type

G

Ghost

Hi all, I wrote a program in C# and now I have to "translate" it i
visual C++ (MFC) using .NET, but I had a little problem:

*ERRORS*
error C3181: 'CTestDlg' : invalid operand for __typeof, expected
fully defined managed type

error C3363: 'void CTestDlg::BtnAboutClick(System::Object __g
*,System::EventArgs __gc *)' : cannot create a delegate handler fo
'System::EventHandler' from a non-member function or a member of a
unmanaged class

error C2227: left of '->Add' must point to class/struct/union

*SOURCE LINES*
ResourceManager* resources = new ResourceManager(__typeof(CTestDlg));

btnAbout->Click += new EventHandler(this, &CTestDlg::BtnAboutClick);

Control::Controls->Add(btnAbout);

My .h file is:

class CTestDlg: public CDialog
{
//lots of code.....
}

I'm wasting my time on these errors but I don't know how can I fi
them, could someone help me?
Thank you for the help (I hope :D


-
Ghos
 
A

Antti Keskinen

Hello !

The Visual Studio series has one crucial advantage over other IDEs: it tends
to state very specifically what the error is. The first error gives you a
hint: "use of __typeof expects a fully defined _managed_ type" and the
second error confirms it: "... from a non-member function or a member of an
_unmanaged_ class".

Putting it in plain english, the class CTestDlg is not defined as a managed
type, period. If you're writing for the C++/CLI syntax, the following
declaration would make it managed:

ref CTestDlg : public CDialog
{
// code
}

If you're writing for Managed Extensions for C++, the declaration is:

__gc class CTestDlg : public CDialog
{
// code
}

Remember that creating a managed version of your class also removes the need
to explicitly delete a created object of this type. Also other programming
qwirks get implied when an unmanaged class is moved to the managed
environment, like the need for a different type of declaration syntax (which
might impose problems if the instance is created by the MFC framework). This
means, in english that if you use the doc/view architecture of MFC, you must
create and upkeep the doc/views manually, because MFC isn't a managed
framework.

Hope this helps,
-Antti Keskinen
 

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