This documentation is archived and is not being maintained.

Example DLL

Visual Studio .NET 2003

To enable Managed Extensions for C++ to provide a marshaling layer, the following DLL is provided as an example. The following header file fragment defines the functions and data types for this example:

#define TRADITIONALDLL_API __declspec(dllexport)
#define TRADITIONALDLL_API __declspec(dllimport)

#ifdef __cplusplus
extern "C"

   typedef struct LOCATION
      short x;
      short y;
   typedef struct CITY
      char * name;
      LOCATION location;
   } CITY;
   TRADITIONALDLL_API int PickANumber();
   TRADITIONALDLL_API double DistanceToCity(LOCATION location);
   TRADITIONALDLL_API void DrawCity(HDC hDC,CITY * city);
   CITY cities[],int numCities);
   TRADITIONALDLL_API void CreateCity(CITY** pCity);
#ifdef __cplusplus

The code demonstrates the following concepts:

  • The PickANumber function returns an integer. (Note that integers have an identical in-memory representation in managed and unmanaged code.)
  • The CITY structure contains a char* member and a nested structure (LOCATION) member.
  • The DrawCity function takes as arguments a GDI HDC and a pointer to a CITY structure.
  • The CreateCity function takes a pointer to pointer to CITY.

Go to the next step | Go back to the last step

See Also

Managed Extensions for C++ and Data Marshaling Tutorial