CTime and managed wrappers 
Author Message
 CTime and managed wrappers

I am writing managed wrapper classes for an 'unmanaged' C++ class library.
However, if I include a 'unmanaged' class header that takes an argument of
type CTime (say, in the constructor) in the managed wrapper class, the
compiler gives the following error:

error C2653:'CTime': is not a class or namespace name

What is the simplest way around this kind of problem?

Thanks,
Mark



Sat, 27 Nov 2004 02:20:46 GMT  
 CTime and managed wrappers
I will be more specific.  I know it is not a difficult question, but I don't
know how to do it.

I have a an exportable 'unmanaged' class in a class library created in
VC++6, recompiled under .NET:

class AFX_CLASS_EXPORT CUnmanagedClass
{
 public:
    CUnmanagedClass(CTime tDate)
    virtual ~CUnmanagedClass();

Quote:
}

I am trying to write a managed C++ wrapper class library to allow exposure
of the C++ class library to C# programs. However, upon #including the header
file in a managed file, e.g.,

#include "C:\UnmanagedClassLib\UnmanagedClass.h"

the compiler generates the following error,

    error C2653:'CTime': is not a class or namespace name

I suppose the problem is that CTime is an MFC class that is not supported in
the managed environment.  Whate is the simplest way to deal with this kind
of problem?

Thanks,
Mark



Sat, 27 Nov 2004 23:56:03 GMT  
 CTime and managed wrappers
I would like some feedback... is this a difficult question?

Should I shell out another $245 to MS to have it answered?  Or is this
information provided somewhere?  Links to articles are welcome!

Thanks, Mark



Sun, 28 Nov 2004 21:58:44 GMT  
 CTime and managed wrappers
If you can provide a small, but full repro demonstrating the problem, that
would significantly increase the chances of getting help in a timely
fashion.

Ronald Laeremans
Visual C++ compiler and libraries team


Quote:
> I would like some feedback... is this a difficult question?

> Should I shell out another $245 to MS to have it answered?  Or is this
> information provided somewhere?  Links to articles are welcome!

> Thanks, Mark



Mon, 29 Nov 2004 05:49:29 GMT  
 CTime and managed wrappers


Quote:
> If you can provide a small, but full repro demonstrating the problem, that
> would significantly increase the chances of getting help in a timely
> fashion.

> Ronald Laeremans
> Visual C++ compiler and libraries team

Thank you for replying to my post.  I have created a simple library and a
trivial application that illustrates the problem.

The library, named ClassLib, was created under VC++6 and recompiled in .NET.
There is a single class, CUnmanagedClass, whose header file appears as
(except for the 'decoration'):

// Begin of CUnmanagedClass.h

#ifdef EXPORT_CLASS
#define AFX_CLASS_EXPORT __declspec(dllexport)
#else
#define AFX_CLASS_EXPORT __declspec(dllimport)

#if _MSC_VER > 1000
#pragma once
#endif

class AFX_CLASS_EXPORT CUnmanagedClass
{
public:
    CUnmanagedClass(CTime tDate = CTime::GetCurrentTime());
    virtual ~CUnmanagedClass();

    CTime GetTime() const;

private:
    CTime m_tDate;

Quote:
};

// End of CUnmanagedClass.h

A few words about the curious use of "EXPORT_CLASS".  It is marked as
defined in the Project\Properties\C/C++\Command Line\Additional Options tab
by adding the instruction, /DEXPORT_CLASS.  The intention is to redefine the
AFX_CLASS_EXPORT macro for a .NET application that imports a header file.
It is my understanding that this macro is not defined in .NET. I don't
understand why it is preferable to put this in the preexisting class
library, as opposed to a set of equivalent instructions in the calling
application, but this is the advice that I received from MS and for which I
paid $245.  Without this redefinition, the compiler yields error
C2470:'CUnmanagedClass': looks like a function definition, but there is no
formal parameter list; skipping apparent body.

The managed application, named TestManagedApp, is created under .NET using
the "Managed C++ Application" template.  In the
Project\Properties\Linker\Input\Additional Dependencies tab I have placed
the path of the ClassLib.lib file.  In TestManagedApp.cpp I have placed an
#include directive that provides the full path of the header file for
UnmanagedClass.  The entire .cpp file appears as:

// Beginning of TestManagedApp.cpp

#include "stdafx.h"

#using <mscorlib.dll>
#include <tchar.h>

#include "C:\ClassLib\UnmanagedClass.h"

int _tmain(void)
{
    return 0;

Quote:
}

// End of TestManagedApp.cpp

Upon compiling this code I receive a raft of errors, the first of which is

    error C2653:'CTime': is not a class or namespace name

The remaining errors are all related to the use of a CTime variable.  If I
replace all instances of CTime in UnmanagedClass with, say, int, none of
these errors appear.

I hope this is sufficient information to help solve this problem.  I have
placed this question in other newsgroups -- one person suggested that I
place #include "Afxwin.h" in TestManagedApp.cpp.  This, however, led to yet
more errors:  error LNK2005: "void* __cdecl operator new(unsigned int)" etc,
etc.

Again, Thanks for your help on this problem.
Mark



Tue, 30 Nov 2004 01:06:09 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. managed C++ wrapper around unmanaged C++ classes: causing StackOverflow exception

2. Making managed wrapper for legacy unmanaged classes.

3. Interface of Managed C++ wrappers

4. Referencing data from unmanaged code to managed code in C++ Wrapper class

5. Managed C++ Wrapper

6. Unmanaged Application with Managed Wrapper Dll won't run on Windows XP

7. Managed C++ "wrapper classes" deployment problem

8. Managed C++ Wrapper for DLL

9. Managed C++ wrappers for unmanaged C++ classes

10. Unmanaged code doesn't run properly from managed wrapper

11. Managed wrapper for COM Server

12. Tutorial wanted for using a managed C++ class wrapper

 

 
Powered by phpBB® Forum Software