How .NET handles .H and .CPP files?

T

TOM

Can anyone describe how .NET handles .H and .CPP files as far as the linker
is concerned?
I'm getting some unresolved metadata errors from the linker (LNK2022).

Fails: Interface and class public data defined in .H file
Class implementation and private variables defined in .CPP file

OK: Interface, class public data and class private variables defined in .H
file,
Class implementation in .CPP file.


The reason for wanting to keep the private variables out of the .H file are
that they need objbase.h
plus some USB includes from the DDK to be defined. These includes break all
the other .NET modules
auto-generated by the forms builder that need to use the class.

-- Tom
 
R

Ronald Laeremans [MSFT]

Hi Tom,

Can you give a concrete example of what fails?

Thanks.

Ronald
 
T

TOM

Ron,

Thanks again for addressing my issue. I have found a good work around.
Reading the
C++ Stroustrup book left some questions on class declaration syntax in a .H
file. It seems
that the .H file must delare all public and all private members, methods,
and data of a class.
This is a change from 2002, where the private variables did not have to be
defined in the .H file
(only the CPP file). Broken means linker metadata error #2022.

I am able to hide the private variables from the .H file by defining a
helper class in the CPP code which encapsulates
all the nasty USB data structures [those break the auto-generated forms
modules]. The
class declaration in the .H file can use a forward reference to the helper
class to avoid exposing what's
inside the helper to the .H file. Then the task was to find out how to
define that forward syntax for managed
classes, which seems obvious now.

.. H file
// define interface to USBdevice
__gc class public USBdevice {
public:
.. the managed types of the class;
__gc class Helper * d; // forward reference to very messy Helper
class in the CPP file
};


..CPP file
// implementation of USBdevice
#include objbase.h // very offensive to auto-gen forms code, but
needed for USB headers
#include USB headers from DDK

__gc class public Helper {
lots of messy USB variables
};

__gc class public USBdevice{
public:
the Udevice variables;
Helper * d; // not forward
};
 

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