Easier Export/Import

If you are using Microsoft C++ 5.0 you can use the following technique to make exporting/importing functions from a DLL a bit easier because you donít have to use a DEF file to define the exports.

As long as you use the Microsoft compiler for both the DLL and the EXE that uses the DLL, you donít have to worry about the name mangling/decorating that is done automatically by the compiler.

Suppose you with to export a function

HRESULT GetLCD(long *plValue);

First create an include file, functions.h

// functions.h
#ifndef __FUNCTIONS_H__
#define __FUNCTIONS_H__

// Unless already specified convert to import interface
#ifndef IMPORTEXPORT
#define IMPORTEXPORT __declspec(dllimport)
#endif

IMPORTEXPORT HRESULT GetLCD(long *lpValue);

#endif // __FUNCTIONS_H__

In files that are part of the DLL implementation use the following to include functions.h

// Convert to export interface BEFORE including functions.h
#define IMPORTEXPORT __declspec(dllexport)
#include "functions.h"

IMPORTEXPORT HRESULT GetLCD(long *plValue)
{
}

In files that use the DLL use the following to include functions.h

#include "functions.h"