Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Welcome Guest | Log In | Register | Benefits
Channels ▼
RSS

A DynaCall() Function for Win32


August 1998/A DynaCall() Function for Win32/Listing 1

Listing 1: docall.c — Example calls to DynaCall()

//------------------------------------------------------------------
//  DoCall.c - Test app for the DynaCall DLL. Ton Plooy 1998
//------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#define  WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "dynacall.h"

//------------------------------------------------------------------

int main(int argc, char *argv[])
{
    UINT       t_uint;
    DYNAPARM   Parm[10];
    HINSTANCE  hInst;
    DWORD      lpFunction;
    RESULT     rc;
    double     d = 3.14159;

    // Call the MessageBox function. 
    hInst      = LoadLibrary("USER32.DLL");
    lpFunction = SearchProcAddress(hInst, "MessageBoxA");
    if ((LPVOID)lpFunction != NULL) {
        // MessageBox(HWND hWnd, LPCTSTR lpText,
        //            LPCTSTR lpCaption, UINT uType)
        memset(Parm, 0, sizeof(Parm));
        t_uint          = MB_YESNO;
        Parm[0].nWidth  = sizeof(HWND);    
        Parm[1].nWidth  = sizeof(LPCTSTR);
        Parm[2].nWidth  = sizeof(LPCTSTR);
        Parm[3].nWidth  = sizeof(UINT);
        Parm[0].pArg    = NULL;
        Parm[1].pArg    = "Dynacall Demo";
        Parm[2].pArg    = "wdj";
        Parm[3].dwArg   = MB_YESNO;          
        rc = DynaCall(DC_CALL_STD, lpFunction, 4, Parm, NULL, 0);
        FreeLibrary(hInst);
        printf("MessageBox: %d\n", rc.Int);
    }

    hInst      = LoadLibrary("msvcrt.dll");
    lpFunction = SearchProcAddress(hInst, "sin");
    if ((LPVOID)lpFunction != NULL) {
        memset(Parm, 0, sizeof(Parm));
        Parm[0].nWidth  = sizeof(double);
        Parm[0].pArg    = &d;               // Arg is > 4 bytes,
        Parm[0].dwFlags = DC_FLAG_ARGPTR;   //   use pointer
        rc = DynaCall(DC_CALL_STD_M8, lpFunction, 1, Parm, NULL, 0);
        FreeLibrary(hInst);

        printf("sin(%lf): %.12lf\n", d, rc.Double);
    }

    return 0;
}
//End of File

Related Reading


More Insights