Dynamically Object Creation 
Author Message
 Dynamically Object Creation

I am trying to dynmically create objects by using their class name,
"MyClass".  The classes are derived from CObject and use the
DECLARE_DYNCREATE and IMPLEMENT_DYNCREATE macros.  I get the CRuntimeClass
structure and call CreateObject("MyClass") but it returns NULL.

Stepping into CreateObject("MyClass"), there is a call to
FromName("MyClass") which searches pModuleState->m_classList for "MyClass".
Only "COList":, "CDocItem", "CMapStringToString", "CMapStringToOb",
"CMapWordToOb", "CStringArray", "CDWordArray", "CWordArray", "CByteArray",
and "CObArray" appear in the list of classes.

How do I get my class to appear in the class list so I can create an object
by using the class name?

Tom



Wed, 14 Sep 2005 01:30:05 GMT  
 Dynamically Object Creation
Hi Tom,

Please refer to these two articles in MSDN:

"Accessing Run-Time Class Information"
"Dynamic Object Creation"

HTH.

Best regards,
yhhuang
VS.NET, Visual C++
Microsoft

This posting is provided "AS IS" with no warranties, and confers no rights.
Got .Net?  http://www.gotdotnet.com
--------------------

!Subject: Dynamically Object Creation
!Date: Fri, 28 Mar 2003 18:30:05 -0600
!Lines: 17
!X-Priority: 3
!X-MSMail-Priority: Normal
!X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
!X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106

!Newsgroups: microsoft.public.vc.mfc
!NNTP-Posting-Host: bdsl.66.12.179.178.gte.net 66.12.179.178
!Path:
cpmsftngxa06!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08.phx.gbl
!TK2MSFTNGP11.phx.gbl
!Xref: cpmsftngxa06 microsoft.public.vc.mfc:369221
!X-Tomcat-NG: microsoft.public.vc.mfc
!
!I am trying to dynmically create objects by using their class name,
!"MyClass".  The classes are derived from CObject and use the
!DECLARE_DYNCREATE and IMPLEMENT_DYNCREATE macros.  I get the CRuntimeClass
!structure and call CreateObject("MyClass") but it returns NULL.
!
!Stepping into CreateObject("MyClass"), there is a call to
!FromName("MyClass") which searches pModuleState->m_classList for "MyClass".
!Only "COList":, "CDocItem", "CMapStringToString", "CMapStringToOb",
!"CMapWordToOb", "CStringArray", "CDWordArray", "CWordArray", "CByteArray",
!and "CObArray" appear in the list of classes.
!
!How do I get my class to appear in the class list so I can create an object
!by using the class name?
!
!Tom
!
!
!



Fri, 16 Sep 2005 10:05:59 GMT  
 Dynamically Object Creation
yhhuang,

I have done all the things in the articles you referenced, however,
FromName() still cannot find my class in the list it searches.  The
documentation of FromName() states lpszClassName is "The familiar name of a
class derived from CObject".  I have done that and apparently my class is
still not a "familiar name".  My question is:

What do I need to do to get my class registered so it's name appears on the
list of classes FromName() searches?

Tom


Quote:
> Hi Tom,

> Please refer to these two articles in MSDN:

> "Accessing Run-Time Class Information"
> "Dynamic Object Creation"

> HTH.

> Best regards,
> yhhuang
> VS.NET, Visual C++
> Microsoft

> This posting is provided "AS IS" with no warranties, and confers no
rights.
> Got .Net?  http://www.gotdotnet.com
> --------------------

> !Subject: Dynamically Object Creation
> !Date: Fri, 28 Mar 2003 18:30:05 -0600
> !Lines: 17
> !X-Priority: 3
> !X-MSMail-Priority: Normal
> !X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
> !X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106

> !Newsgroups: microsoft.public.vc.mfc
> !NNTP-Posting-Host: bdsl.66.12.179.178.gte.net 66.12.179.178
> !Path:

cpmsftngxa06!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08.phx.gbl

- Show quoted text -

Quote:
> !TK2MSFTNGP11.phx.gbl
> !Xref: cpmsftngxa06 microsoft.public.vc.mfc:369221
> !X-Tomcat-NG: microsoft.public.vc.mfc
> !
> !I am trying to dynmically create objects by using their class name,
> !"MyClass".  The classes are derived from CObject and use the
> !DECLARE_DYNCREATE and IMPLEMENT_DYNCREATE macros.  I get the
CRuntimeClass
> !structure and call CreateObject("MyClass") but it returns NULL.
> !
> !Stepping into CreateObject("MyClass"), there is a call to
> !FromName("MyClass") which searches pModuleState->m_classList for
"MyClass".
> !Only "COList":, "CDocItem", "CMapStringToString", "CMapStringToOb",
> !"CMapWordToOb", "CStringArray", "CDWordArray", "CWordArray",
"CByteArray",
> !and "CObArray" appear in the list of classes.
> !
> !How do I get my class to appear in the class list so I can create an
object
> !by using the class name?
> !
> !Tom
> !
> !
> !



Sun, 18 Sep 2005 15:19:37 GMT  
 Dynamically Object Creation
Hi Tom,

Please refer to the following code. I used them on my side and all work
fine.

// in .H file
class CPerson : public CObject
{
    DECLARE_DYNCREATE( CPerson )
public:
    CPerson(){};

    // other declaration

Quote:
};

// in .CPP file
IMPLEMENT_DYNCREATE( CPerson, CObject )

void CDyneCreateDlg::OnButton1()
{
        // TODO: Add your control notification handler code here
        CRuntimeClass* pRuntimeClass = RUNTIME_CLASS( CPerson );
        CObject* pObject = pRuntimeClass->CreateObject();
        ASSERT( pObject->IsKindOf( RUNTIME_CLASS( CPerson ) ) );

Quote:
}

You can refer to it to check the difference.

Best regards,
yhhuang
VS.NET, Visual C++
Microsoft

This posting is provided "AS IS" with no warranties, and confers no rights.
Got .Net?  http://www.gotdotnet.com
--------------------



!Subject: Re: Dynamically Object Creation
!Date: Wed, 2 Apr 2003 08:19:37 -0600
!Lines: 76
!X-Priority: 3
!X-MSMail-Priority: Normal
!X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
!X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106

!Newsgroups: microsoft.public.vc.mfc
!NNTP-Posting-Host: bdsl.66.12.179.178.gte.net 66.12.179.178
!Path:
cpmsftngxa08.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.
phx.gbl
!Xref: cpmsftngxa08.phx.gbl microsoft.public.vc.mfc:367660
!X-Tomcat-NG: microsoft.public.vc.mfc
!
!yhhuang,
!
!I have done all the things in the articles you referenced, however,
!FromName() still cannot find my class in the list it searches.  The
!documentation of FromName() states lpszClassName is "The familiar name of a
!class derived from CObject".  I have done that and apparently my class is
!still not a "familiar name".  My question is:
!
!What do I need to do to get my class registered so it's name appears on the
!list of classes FromName() searches?
!
!Tom
!

!> Hi Tom,
!>
!> Please refer to these two articles in MSDN:
!>
!> "Accessing Run-Time Class Information"
!> "Dynamic Object Creation"
!>
!> HTH.
!>
!> Best regards,
!> yhhuang
!> VS.NET, Visual C++
!> Microsoft
!>
!> This posting is provided "AS IS" with no warranties, and confers no
!rights.
!> Got .Net?  http://www.gotdotnet.com
!> --------------------

!> !Subject: Dynamically Object Creation
!> !Date: Fri, 28 Mar 2003 18:30:05 -0600
!> !Lines: 17
!> !X-Priority: 3
!> !X-MSMail-Priority: Normal
!> !X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
!> !X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106

!> !Newsgroups: microsoft.public.vc.mfc
!> !NNTP-Posting-Host: bdsl.66.12.179.178.gte.net 66.12.179.178
!> !Path:
!>
!cpmsftngxa06!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08.phx.gb
l
!> !TK2MSFTNGP11.phx.gbl
!> !Xref: cpmsftngxa06 microsoft.public.vc.mfc:369221
!> !X-Tomcat-NG: microsoft.public.vc.mfc
!> !
!> !I am trying to dynmically create objects by using their class name,
!> !"MyClass".  The classes are derived from CObject and use the
!> !DECLARE_DYNCREATE and IMPLEMENT_DYNCREATE macros.  I get the
!CRuntimeClass
!> !structure and call CreateObject("MyClass") but it returns NULL.
!> !
!> !Stepping into CreateObject("MyClass"), there is a call to
!> !FromName("MyClass") which searches pModuleState->m_classList for
!"MyClass".
!> !Only "COList":, "CDocItem", "CMapStringToString", "CMapStringToOb",
!> !"CMapWordToOb", "CStringArray", "CDWordArray", "CWordArray",
!"CByteArray",
!> !and "CObArray" appear in the list of classes.
!> !
!> !How do I get my class to appear in the class list so I can create an
!object
!> !by using the class name?
!> !
!> !Tom
!> !
!> !
!> !
!>
!
!
!



Tue, 20 Sep 2005 09:58:51 GMT  
 Dynamically Object Creation
yhhuang,

I have done all the things in the articles you referenced, however,
FromName() still cannot find my class in the list it searches.  The
documentation of FromName() states lpszClassName is "The familiar name of a
class derived from CObject".  I have done that and apparently my class is
still not a "familiar name".  My question is:

What do I need to do to get my class registered so it's name appears on the
list of classes FromName() searches?

Tom


Quote:
> Hi Tom,

> Please refer to these two articles in MSDN:

> "Accessing Run-Time Class Information"
> "Dynamic Object Creation"

> HTH.

> Best regards,
> yhhuang
> VS.NET, Visual C++
> Microsoft

> This posting is provided "AS IS" with no warranties, and confers no
rights.
> Got .Net?  http://www.gotdotnet.com
> --------------------

> !Subject: Dynamically Object Creation
> !Date: Fri, 28 Mar 2003 18:30:05 -0600
> !Lines: 17
> !X-Priority: 3
> !X-MSMail-Priority: Normal
> !X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
> !X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106

> !Newsgroups: microsoft.public.vc.mfc
> !NNTP-Posting-Host: bdsl.66.12.179.178.gte.net 66.12.179.178
> !Path:

cpmsftngxa06!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08.phx.gbl

- Show quoted text -

Quote:
> !TK2MSFTNGP11.phx.gbl
> !Xref: cpmsftngxa06 microsoft.public.vc.mfc:369221
> !X-Tomcat-NG: microsoft.public.vc.mfc
> !
> !I am trying to dynmically create objects by using their class name,
> !"MyClass".  The classes are derived from CObject and use the
> !DECLARE_DYNCREATE and IMPLEMENT_DYNCREATE macros.  I get the
CRuntimeClass
> !structure and call CreateObject("MyClass") but it returns NULL.
> !
> !Stepping into CreateObject("MyClass"), there is a call to
> !FromName("MyClass") which searches pModuleState->m_classList for
"MyClass".
> !Only "COList":, "CDocItem", "CMapStringToString", "CMapStringToOb",
> !"CMapWordToOb", "CStringArray", "CDWordArray", "CWordArray",
"CByteArray",
> !and "CObArray" appear in the list of classes.
> !
> !How do I get my class to appear in the class list so I can create an
object
> !by using the class name?
> !
> !Tom
> !
> !
> !



Fri, 23 Sep 2005 17:31:21 GMT  
 Dynamically Object Creation
Hi Tom,

I have pasted my sample in the original post. Please refer to it. The
sample works fine on my side. I can create the instance of class through
CRuntimeClass::CreateObject.

Best regards,
yhhuang
VS.NET, Visual C++
Microsoft

This posting is provided "AS IS" with no warranties, and confers no rights.
Got .Net?  http://www.gotdotnet.com
--------------------

!Subject: Dynamically Object Creation
!Date: Mon, 7 Apr 2003 11:31:21 -0500
!Lines: 77
!X-Priority: 3
!X-MSMail-Priority: Normal
!X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
!X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106

!Newsgroups: microsoft.public.vc.mfc
!NNTP-Posting-Host: bdsl.66.12.179.178.gte.net 66.12.179.178
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.vc.mfc:370105
!X-Tomcat-NG: microsoft.public.vc.mfc
!
!yhhuang,
!
!I have done all the things in the articles you referenced, however,
!FromName() still cannot find my class in the list it searches.  The
!documentation of FromName() states lpszClassName is "The familiar name of a
!class derived from CObject".  I have done that and apparently my class is
!still not a "familiar name".  My question is:
!
!What do I need to do to get my class registered so it's name appears on the
!list of classes FromName() searches?
!
!Tom
!

!> Hi Tom,
!>
!> Please refer to these two articles in MSDN:
!>
!> "Accessing Run-Time Class Information"
!> "Dynamic Object Creation"
!>
!> HTH.
!>
!> Best regards,
!> yhhuang
!> VS.NET, Visual C++
!> Microsoft
!>
!> This posting is provided "AS IS" with no warranties, and confers no
!rights.
!> Got .Net?  http://www.gotdotnet.com
!> --------------------

!> !Subject: Dynamically Object Creation
!> !Date: Fri, 28 Mar 2003 18:30:05 -0600
!> !Lines: 17
!> !X-Priority: 3
!> !X-MSMail-Priority: Normal
!> !X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
!> !X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106

!> !Newsgroups: microsoft.public.vc.mfc
!> !NNTP-Posting-Host: bdsl.66.12.179.178.gte.net 66.12.179.178
!> !Path:
!>
!cpmsftngxa06!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08.phx.gb
l
!> !TK2MSFTNGP11.phx.gbl
!> !Xref: cpmsftngxa06 microsoft.public.vc.mfc:369221
!> !X-Tomcat-NG: microsoft.public.vc.mfc
!> !
!> !I am trying to dynmically create objects by using their class name,
!> !"MyClass".  The classes are derived from CObject and use the
!> !DECLARE_DYNCREATE and IMPLEMENT_DYNCREATE macros.  I get the
!CRuntimeClass
!> !structure and call CreateObject("MyClass") but it returns NULL.
!> !
!> !Stepping into CreateObject("MyClass"), there is a call to
!> !FromName("MyClass") which searches pModuleState->m_classList for
!"MyClass".
!> !Only "COList":, "CDocItem", "CMapStringToString", "CMapStringToOb",
!> !"CMapWordToOb", "CStringArray", "CDWordArray", "CWordArray",
!"CByteArray",
!> !and "CObArray" appear in the list of classes.
!> !
!> !How do I get my class to appear in the class list so I can create an
!object
!> !by using the class name?
!> !
!> !Tom
!> !
!> !
!> !
!>
!
!
!
!



Sat, 24 Sep 2005 02:27:20 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Object Dynamically creation, how ?

2. Add a button dynamically on the creation of a Dialog Box

3. Question about objects creation

4. Creation of Com object in C++ using dotnet..

5. remoting, and object creation question

6. Creation and use of C++ objects

7. dynamic object creation

8. Newbie OOP(s) again...dynamic object creation and scope?

9. Implementing object creation in C++

10. Problem with COM object creation with a COM service

11. ATL multithreaded object creation and destruction problem

12. how to debug the object creation

 

 
Powered by phpBB® Forum Software