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:

#ifdef TRADITIONALDLL_EXPORTS
#define TRADITIONALDLL_API __declspec(dllexport)
#else
#define TRADITIONALDLL_API __declspec(dllimport)
#endif

#ifdef __cplusplus
extern "C"
{
#endif

   typedef struct LOCATION
   {
      short x;
      short y;
   } LOCATION;
   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);
   TRADITIONALDLL_API void DrawCities(HDC hDC, 
   CITY cities[],int numCities);
   TRADITIONALDLL_API void CreateCity(CITY** pCity);
#ifdef __cplusplus
}
#endif

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

Show: