2
\$\begingroup\$

I have designed a C++/CLI wrapper library that allows C++ applications on windows, and other platforms that can load C dlls (e.g. Java via JNA or Python) to make calls to my .Net library.

I was wondering if my dll import/export header, which will be used by external developers, complies with the current "best practices" for C++ on windows. I would be grateful if other developers could point out any examples of poor coding practices or if anything is not as clear as it could be for my header below. For example, I am not sure if I should be using __int32 rather than the int type.

I am also keen to improve so please also post any links or book recommendations for API/DLL design.

    **//-----------------------------------------------------------------------
// <copyright file="dllHeader.h" company="drone">
//     Copyright (c) .
// </copyright>
// <date>26-Apr-2016</date>
// <author>?? (drone@codereview.stackoverflow)</author>
//-<version>???</version>
//-----------------------------------------------------------------------
/// This file contains the dllimports/ dllexports for the wrapper. 

// Dependencies:
//      - C runtime Library v120
//      -.net framework version 4.0 or newer
//      - MyDotNetLibrary.dll (managed)

#pragma once
#ifndef dllHeader_h
#define dllHeader_h

// if DLLEXPORTS is defined, define as dllexports, 
// otherwise declare dllimport prototypes. 

#ifdef DLLEXPORTS
#define DLLAPI __declspec(dllexport)
#else 
#define DLLAPI __declspec(dllimport)
#endif 
#define DLLCALL __cdecl // Calling convention is __cdecl

// callbacks:
// typedef return_type ( callingconvention *func_pointer) (params)
typedef void(__stdcall *eventCallback)(void); // stdcall used for WINAPI compat. 
typedef void(__stdcall *eventNewValueCallback)(unsigned long long); //UInt64


extern "C"      // No name mangling
{
    //  Open or close connection to controller 
    //  (arg1: true=Connect, false=Disconn arg2: 0=USB, 1=RS232 3= Simul, arg3: commport number)
    DLLAPI unsigned int       DLLCALL OpenComms(bool, unsigned int, unsigned int); // wrapper to Comms.OpenComms()

    // Methods in alphabetical order 
    DLLAPI bool               DLLCALL ApplySampleCals(bool);            // wrapper to Comms.ApplySampleCals() Toggle between uncalibrated and sample calibrated temperatures. Refer to example in html docs. 

    DLLAPI bool               DLLCALL CalibrateTstDistance(void);
  //.. etc More exported functions in a similar layout

    DLLAPI bool               DLLCALL SetTstMode(bool);


    // Comms Events
    /*********************************************/
    /* Event and callback methods                */
    /* See "myCApiExample" example in apiDocs      */
    /*********************************************/
    // Start callbacks
    DLLAPI void DLLCALL StartEvents();
    // Stop callbacks
    DLLAPI void DLLCALL StopEvents();

    // Set or Register callbacks. See typedefs above for declaration of *eventCallback and *eventNewValueCallback. 
    DLLAPI void DLLCALL SetControllerConnectedCallback(eventCallback); 
    DLLAPI void DLLCALL SetNewValueCallback(eventNewValueCallback);
    DLLAPI void DLLCALL SetControllerDisconnectedCallback(eventCallback);
}
#endif
\$\endgroup\$
  • \$\begingroup\$ Hi! Welcome to Code Review. Good job on your first post! \$\endgroup\$ – TheCoffeeCup Jun 6 '16 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.