Applies To:
  • CitectSCADA 1.00 1.01 1.10 1.11 1.20 2.00 2.01

Summary:
Question: Can I pass arguments by reference to DLL functions?

Solution:
You can only pass arguments by value to DLL functions. Strings are passed via a pointer however they are copied for the DLL call. If you modify the string argument in a DLL the string will not be changed in Citect. The result of the DLL call must be returned as the return value of the DLL function.

You can call a DLL function which modifies its arguments by writing DLL wrapper functions. These wrapper functions will be called via the DLLCall() cicode function which will then call the function you require. The wrapper functions will extract the result and pass it back to Citect via the return value. If you have several arguments you want to return you will need to call the wrapper function several times.

void
HardFunc(char* pStr)
{
// this c function modifies it's argument
}

// this is a wrapper for the above function to return string as the result
char*
WrapHardFunc(char* pStr)
{
   HardFunc(pStr);
   return pStr
}

void
HardTwoArgs(char* pStr1, char* pStr2)
{
// this c function modifies both it's arguments
}

static char Buf[256];

// this wrapper calls the function and returns one string,
// saves the other string in Buf
char*
WrapHardOne(char* pStr1, char* pStr2)
{
   HardTwoArgs(pStr1, pStr2);
   strcpy(Buf, pStr2);
   return pStr1;
}

void
WrapHardTwo(void)
{
// pick up the second argument
   return Buf;
}

/* The cicode would look like this */

hWrapHardFunc = DLLOpen("MyDLL", "WrapHardFunc", "cc")
sRes = DllCall(hWrapHardFunc, "^"string to pass^"");

hWrapHardOne = DLLOpen("MyDLL", "WrapHardOne", "ccc")
hWrapHardTwo = DLLOpen("MyDLL", "WrapHardTwo", "c")
sResOne = DllCall(hWrapHardOne, "^"string argument one^"^"string argument two^"");
sResTwo = DllCall(hWrapHardTwo, "");

 

Keywords:
 

Attachments