08-07-2018 09:33 AM
Hi,everyone.I am learning about how to build a GPI dll. And I am Not familiar with how to create commands.
I have finished some work on commands/step_1 of demos , which has shown as below
// register the name of the command
strcpy_s(commandInfo->szName, "IF2");
// register the name of the function to call
strcpy_s(commandProperties->szProcFctName, "TC2");
commandProperties->cAutoseq = eGPIREGISTER;
commandProperties->nParam = 1;
commandProperties->aParam[0].cParamType = eGPIVARTYPEDOUBLE;
strcpy_s(commandProperties->aParam[0].szParamName, "myResult");
And
GPIEXTERNC void DLLEXPORT TC2(TGPIDouble out1)
{
out1=10.0;
}
After registration of the dll,When I am trying to call TC2 in Scripts like below ,I get nothing on X.
DIM X
IF2(X)
Many thx for any help or hints!!
Best regards ,Q
Solved! Go to Solution.
08-27-2018 04:18 AM
Hello Quanercao,
I had a look through your code and found some mistakes in your code.
In Commands.cpp line 68 you set the type of the parameter to eGPIVARTYPEDOUBLE and in the next line you define the name of the parameter to "myResult". The variable "myResult" however is defined as a variable of type eGPIVARTYEDATARES. So the data types of the parameter and the associated variable don't match. DIAdem uses the associated variable to do some parameter checking (data type, range, etc.). If the data types of the parameter and the associated variable don't match, the result is undefined. So make sure that the data types of the parameter and the associated variable matches (in your example you may choose "myDouble" which is defined as a variable of data type eGPIVARTYPEDOUBLE).
The next mistake is your assumption that you may be able to return data through the parameter you have passed into the function. That is not true. The funktion does not have any return values. The correct declaration of your function is
GPIEXTERNC void DLLEXPORT
TC2(
TGPIDoubleV out1
)
The parameter you pass from DIAdem to your function comes by value and not by reference. If you want to return a value from your function, you have to assign this value to a variable.
Hope this helps.
Best Regards
Rainer
08-29-2018 06:09 AM - edited 08-29-2018 06:14 AM
Hi Rainer,
Sorry about my mistakes and thank you very much. Your reply helps a lot.
@RainerHThe parameter you pass from DIAdem to your function comes by value and not by reference. If you want to return a value from your function, you have to assign this value to a variable.
I have try many times to pass parameters by reference in C++. But it doesn't work at all.
And I don't know how to set/get value to variable in a GPI command-function.Could you please give me some advice or a demo?
Best Regards,
Quanercao
09-10-2018 03:01 AM
Hi Quanercao,
variables are defined similar to commands in the GPICallback() function in DIAdem. There is one example in the GPI-package that deals with variables. You may use this as a base for defining your own variables. In general for every variable you define as a DIAdem GPI-Variable, you have to define one global variable in your code. This way you can access this variable from both sides, from DIAdem via script and from your code (e.g. your command). So if you want to return some values from your command, just write the value(s) to your global variable(s) and read out these variable(s) in a DIAdem script.
Best Regards,
Rainer
10-13-2018 10:15 AM
Hi Rainer, I know how to do it now. Thanks a lot !!!