Making Windows externals

Tomas Franzén tomas at lightheadsw.com
Fri Oct 22 13:51:40 EDT 2004


Hi,

I'm trying to get my first Windows DLL external to work.
It compiles successfully, but the externalFunctions and 
externalHandlers return empty. I set the 'externals' property, and 
re-open the stack afterwards.
I read in the DLL Article about how using the wrong compiler could mess 
things up. I'm currently using Bloodshed Dev C++, in which the code 
compiles without problems.
I also tried Microsoft Visual Studio, but externalFunctions/Handlers 
still return empty. Which compiler is recommended?

Here's the code:

#include "XCMDGlue.h"
  #include "windows.h" // GetComputerName(), SetComputerName()
  #include <iostream.h>
  #include <stdio.h>

  void XCabort();
  void XGetName(char *args[], int nargs, char **retstring, Bool *pass, 
Bool *error);
  void XSetName(char *args[], int nargs, char **retstring, Bool *pass, 
Bool *error);

  char Xname[] = "Test External";

  void XCabort(){
  fprintf(stderr, "external abort");
  }

  Xternal Xtable[] = {
  {"xsetcomputername", XCOMMAND, 0, XSetName, XCabort},
  {"xgetcomputername", XFUNCTION, 0, XGetName, XCabort},
  {"", XNONE, 0, NULL, NULL}
  };

  void XGetName(char *args[], int nargs, char **retstring, Bool *pass, 
Bool *error)
  {
  char buffer[MAX_COMPUTERNAME_LENGTH+1];
  DWORD dwLength;
  BOOL blnSuccess;

  dwLength = MAX_COMPUTERNAME_LENGTH+1;
  blnSuccess = GetComputerName(buffer, &dwLength);
  *pass = False; // don't pass the command up the chain
  if (blnSuccess)
  {
  *error = False; // call was successful
  //*retstring = istrdup (buffer);
  sprintf(*retstring,buffer);
  }
  else
  {
  *error = True; // call failed
  //*retstring = istrdup ("error: GetComputerName failed");
  sprintf(*retstring,"error: GetComputerName failed");
  }
  }



  void XSetName(char *args[], int nargs, char **retstring, Bool *pass, 
Bool *error)
  {
  char buffer[MAX_COMPUTERNAME_LENGTH+1];
  BOOL blnSuccess = False;

  // get the new name from the array of arguments
  if (1 == nargs)
  {
  blnSuccess = SetComputerName(args[0]);
  }

  *pass = False; // don't pass the command up the chain
  if (blnSuccess)
  {
  *error = False; // call was successful
  //*retstring = istrdup (buffer);
  sprintf(*retstring,buffer);
  }
  else
  {
  *error = True; // call failed
  //*retstring = istrdup ("error: SetComputerName failed");
  sprintf(*retstring,"error: SetComputerName failed");
  }
  }


Thanks!

Tomas Franzén
Lighthead Software
http://www.lightheadsw.com/

I'm listening to The Hives - Walk Idiot Walk 


More information about the use-livecode mailing list