FR

pcosmos.ca

Philippe Choquette's universe

Home
News
Profile
Contact
Half-Life
Music
PCASTL
Computer Science
Videos
Readings
OpenGL
Elements
C64 sids
Links
Operators
Data Types
Internal Functions
Tree Structure
Batch Execution
Examples
Interpreter

Library Example

In a file named main.c:

#include <windows.h>
#include <math.h>
#include <string.h>

typedef struct
{
   double x;
   double y;
} point;


typedef struct
{
   point vertices[3];
   double perimeter;
   float extra;
} triangle;


BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved)
{
    return TRUE;
}


double distance(point a, point b)
{
   return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}


__declspec(dllexport) int dll_demo(int n1, int n2, float copy, triangle* t, 
   double* avgx, double* avgy, char* str)
{
   t->perimeter = 0.0;
   t->perimeter += distance(t->vertices[0], t->vertices[1]);
   t->perimeter += distance(t->vertices[1], t->vertices[2]);
   t->perimeter += distance(t->vertices[2], t->vertices[0]);
   t->extra = copy;
   
   *avgx = (t->vertices[0].x + t->vertices[1].x + t->vertices[2].x) / 3.0;
   *avgy = (t->vertices[0].y + t->vertices[1].y + t->vertices[2].y) / 3.0;

   strcpy(str, "done");

   return n1 + n2;
}

On the command line:

cl main.c /LD /O2 /Fedll_demo.dll

In the interpreter: test_dll_demo.astl.
Call in math library example: testmath.astl.

Calls to a function in a library return a PCASTL object with always the following members.

MemberFunction return type
ret_int32int, short, char, pointer in 32-bit OS
ret_int64long long, pointer in 64-bit OS
ret_doubledouble
ret_floatfloat
Mobile
linkedin
bandcamp
steam