Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a DLL for CSL Scripting Use

Status
Not open for further replies.

sweep123

Technical User
May 1, 2003
185
GB
I have been trying to use my DLL but keep getting the error no 'initialize' entry found in WHL_TEST_DLL.DLL

It's the 1st time I have tried to do a DLL in Visual Studio.

See code below:-

// WHL_TEST_DLL.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include <ZCslApi.h>
#include <stdlib.h>
#include <stdio.h>
#include "WHL_TEST_DLL.h"

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}

// This is an example of an exported variable
WHL_TEST_DLL_API int nWHL_TEST_DLL=0;

// This is an example of an exported function.
WHL_TEST_DLL_API int fnWHL_TEST_DLL(void)
{
return 42;
}

// This is the constructor of a class that has been exported.
// see WHL_TEST_DLL.h for the class definition
CWHL_TEST_DLL::CWHL_TEST_DLL()
{
return;
}

/*
* c h e c k N u m b e r
*
* Check if string represents a number
*/
static int checkNumber(char *s)
{
int any;
any = 0;
if (*s=='-' || *s=='+') s++;
while ('0'<=*s && *s<='9') { s++; any = 1; }
if (*s=='.') s++;
while ('0'<=*s && *s<='9') s++;
return any && *s == 0;
} /* checkNumber */

/*
* a v e r a g e
*
* Sample CSL function calculating the average of up 5 numbers
*/
ZExportAPI(void) average(ZCslHandle aCsl)
{
double sum;
long bufsiz;
int argCount, i;
char buf[40], name[4];

/* get actual # of arguments */
bufsiz = sizeof(buf);
ZCslGet(aCsl, "argCount", buf, &bufsiz);
argCount = atoi(buf);

/* calculate sum of all arguments */
sum = 0.0;
for (i = 0; i < argCount; i++) {
/* create name of parameter */
sprintf(name, "p%d", i+1);

/* get argument */
bufsiz = sizeof(buf);
if ( ZCslGet(aCsl, name, buf, &bufsiz) ) return; /* (1) */

/* check for number */
if (!checkNumber(buf)) {
sprintf(buf, "argument %d is no number!", i);
ZCslSetError(aCsl, buf, -1); /* (2) */
} /* if */

sum += atof(buf);
} /* for */

/* return result */
sprintf(buf, "%f", sum / argCount);
ZCslSetResult(aCsl, buf, -1); /* (2) */
} /* average */

/*
* i n i t i a l i z e
*
* initialize csl library at load time
*/
ZCslInitLib(csl)
{
static char* module = "WHL_DLL"; /* module name */
long errs;

/* define a global constant by loading a script */
errs = ZCslLoadScriptMem(
csl, /* csl handle */
module, /* module name */
"const myVersion = 1.0;\n" /* script source */
);
if (errs) return; /* (1) */

/* load a function (no errs check since returning hereafter anyway) */
ZCslAddFunc(
csl, /* handle */
module, /* module name */
"average(const p1, " /* declaration */
"const p2, "
"[const p3, "
"const p4, "
"const p5])",
average); /* function address */
} /* initialize */

/*
* c l e a n u p
*
* clean up csl library before unloading
*/
ZCslCleanupLib(csl)
{
/* nothing to clean up in our sample */
} /* cleanup */


The header has the following:-

// This class is exported from the WHL_TEST_DLL.dll
class WHL_TEST_DLL_API CWHL_TEST_DLL {
public:
CWHL_TEST_DLL(void);
// TODO: add your methods here.
};

extern WHL_TEST_DLL_API int nWHL_TEST_DLL;

WHL_TEST_DLL_API int fnWHL_TEST_DLL(void);

// This is an exported function.
ZCslInitLib(csl);

// This is an exported function.
// ZExportAPI(void) average(ZCslHandle aCsl);

// This is an exported function.
ZCslCleanupLib(csl);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top