C to PB conversion needed
Posted: Tue Oct 18, 2011 4:55 pm
Hi guys,
I have 2 "C" headers that need converting to PB. They are originally for DLL plugins for TrueBasic and I want make some DLLs for my own use ... I don't have much any C experience and would be glad if someone can convert them for me :-
Thanks for your help.
I have 2 "C" headers that need converting to PB. They are originally for DLL plugins for TrueBasic and I want make some DLLs for my own use ... I don't have much any C experience and would be glad if someone can convert them for me :-
Code: Select all
typedef struct
{
long refcnt; /* Number of True BASIC strings pointing to this physical string. */
long len; /* Length of the True BASIC string text. */
char text[4]; /* The start of the text of the string. Not limited to 4 chars. */
} string;
typedef struct
{
string *str; /* A pointer to the actual string. */
long maxlen; /* Unused information. */
} tb_sptr;
typedef union
{
signed char ch[8];
char b[8];
double d;
struct
{
long val, flag; /* If flag is -1, then val is used to store the number as an integer. */
} i;
struct
{
unsigned long low;
long high;
} x;
struct
{
short sig3, sig2, sig1, exp;
} e;
} tb_num;
#define MAX_DIMS 30
typedef struct
{
long base, extent;
} range;
typedef struct
{
long dimensions;
long array_tag; /* TAG_NARR if numeric array, TAG_SARR if string array. */
long maxsize, maxlen;
long elements;
range range[MAX_DIMS];
} array;
#define TAG_NARR -1
#define TAG_SARR -2
Code: Select all
// A simple Test Program ...
#define DLLPREFIX __declspec(dllexport)
/* CALL TB_PlaySound(soundfile,syncflag)
soundfile is name of a .WAV file
syncflag is 0 for asynchronous sound, 1 for synchronous sound.
*/
DLLPREFIX void
TB_PlaySound(char *ptrs)
{
tb_sptr *soundfile;
tb_num *syncflag;
DWORD soundtype = SND_FILENAME;
char *csoundfile;
/* Get flag and adjust soundtype if necessary */
syncflag = *(tb_num **) ptrs;
if (syncflag->i.flag != -1) return;
if (syncflag->i.val) soundtype = soundtype & SND_SYNC; else soundtype = soundtype & SND_ASYNC;
/* Advance to next TB arg */
ptrs += 8;
/* Get TB string with sound file name */
soundfile = *(tb_sptr **) ptrs;
/* Convert TB string to C string */
csoundfile = (char *) calloc(soundfile->str->len+1,1);
if (csoundfile == NULL) return;
memcpy(csoundfile,soundfile->str->text,soundfile->str->len);
/* Play the sound using the Windows API */
(void) PlaySound(csoundfile,NULL,soundtype);
/* Free the C string */
free(csoundfile);
}