-
February 19th, 2007, 10:17 AM
#1
Reflection - Assembly::CreateInstance of a non "ref" c++ class
Hello All.
I have a c++ class not defined with the ref keyword
class CMsg {...}
I'm trying to create an instance of CMsg using Reflection, as follows:
Assembly^ assembly = Assembly::GetAssembly(CMsg::typeid);
System::Object^ msg = assembly->CreateInstance("SIMsgs.CMsg");
Well, it works, I get a CMsg, but as a _reference_, while I need a pointer....
Since CMsg is not a "ref" class I can't cast the return value to CMsg, and so can't call its methods. I can see it's member in the debugger, but can't reach them.
For example this line:
CMsg ^cmsg = (CMsg ^)msg;
Create the following complication errors:
Error 1 error C3699: '^' : cannot use this indirection on type 'SIMsgs::CMsg' e:\projects\Secure1\pkg\Server\SIMsgs\MsgGenerator.cpp 34
Error 2 error C3699: '^' : cannot use this indirection on type 'SIMsgs::CMsg' e:\projects\Secure1\pkg\Server\SIMsgs\MsgGenerator.cpp 34
Error 3 error C2440: 'type cast' : cannot convert from 'System::Object ^' to 'SIMsgs::CMsg *' e:\projects\Secure1\pkg\Server\SIMsgs\MsgGenerator.cpp 34
Anyway to get a (CMsg *) out of the return value of CreateInstance()?
Any other solution?
Thank you very much and in advance,
Roee Oz
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|