ATTENTIONThis FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices. |
flexsim.com |
#1
|
|||
|
|||
Global variables are now known in the dll project.
Hi everybody
An external solver which uses a C++ interface must be used in one of triggers of an object. To integrate the external solver, I decided to move the flexscript code to C++ function and make a dll project such that beside the flexscript I can write C++ and use my external code which itself used another library. but to make this compile is not an easy task; In the cpp file of dll project I do not have access to the global variables of flexsim model. How can I make the global variables visible from inside the C++ code which produces the dll? is there any other better solution? comments are appreciated. |
#2
|
||||
|
||||
It is very well possible to use a global variable in your dll
Check out this post: /threads/thread1367&highlight=global+variables+d ll Another solution would be to use a node as a global variable and refer to that node in the DLL |
#3
|
|||
|
|||
Thanks for your comment.
I got also another cases: 1) a macro has been defined like: IS_BUSY e.g. . How can we make use this macro in the cpp code. the former method does not work. of course one way is to re-declare it here but is there any cleaner way? 2) in flexsim and in one of the triggers I have the following: ##some flexscript ###### getNBtransporters(); ### some flexscript I need to hide getNBtransporters from the user and put in in a dll. I still want to let the use to be able to modify the trigger but not knowing what happens in getNBtransporter. is there any way around this? thanks in advance |
#4
|
||||
|
||||
I don't think macros can be accessed in a DLL, but you can simply copy the complete set.
For your other problem, make a different node (or nodes) and call those nodes from within your code so: ##nodefunction( node("x") ) ###### getNBtransporters(); ### nodefunction( node("y") ) And change your GUI so that the triggers point to these nodes instead of the original. Than the user can enter his or hers code on the node x and y and you have your original code that is not influenced by the user. |
#5
|
|||
|
|||
Thank you indeed Steven for your comments.
do you know where i can find an example of using DECLARE_FLEXSIM_GLOBAL_VARIABLE ? I did the declaration in USEFUNC.h but it is not very clear what us meant by: "Then make sure you do as the comment in UserFuncs.h says, namely add two lines, one for DECLARE_FLEXSIM_GLOBAL_VARIABLE, and one with the macro." in the link you posted. 2) would you mind elaborating on this: --------------------------------- For your other problem, make a different node (or nodes) and call those nodes from within your code so: ##nodefunction( node("x") ) ###### getNBtransporters(); ### nodefunction( node("y") ) And change your GUI so that the triggers point to these nodes instead of the original. Than the user can enter his or hers code on the node x and y and you have your original code that is not influenced by the user. --------------------------------- where this snippet is going to be? in C++ project or in the model. what is meant by GUI, which GUI? How does a trigger point to something? Is there any example in the site? Many thanks in advance. |
#6
|
||||
|
||||
In your userfuncs you should write:
DECLARE_FLEXSIM_GLOBAL_VARIABLE( WM_Control, treenode ) #define WM_Control (*_WM_Control_pointer) And instead of WM_Control you should write your own Global Variable name and instead of treenode you should define the type. So if your global variable is MyGlobal and it is an int your 2 lines should be: DECLARE_FLEXSIM_GLOBAL_VARIABLE( MyGlobal , int) #define WM_Control (*_MyGlobal _pointer) 2) Sorry I think that I misread your question. What you can do is make a usercommand, toggle it as a DLL node/function and call your DLL function from within this usercommand. Then you can use this usercommand in your code everywhere and the user doesn't know what code is behind it. |
#7
|
|||
|
|||
Thank you for your comment.
is that all? because I get '_Globalvar_pointer': pointer to reference is illegal 'intGlobalvar_pointer': undeclared identifier 'Globalvar_globalvariableindex': undeclared identifier 'Globalvar_globalvariableindex': undeclared identifier |
#8
|
||||
|
||||
Sorry, then I can't help you now. I asked a collegue who did it in the past and she said that it was a bit complicated. It is easier to use nodes in Flexsim and read those from within your DLL. You can also make usercommands that reads those nodes so that you have some kind of global variables.
Otherwise send a mail to flexsim support and ask them to help you out |
The Following User Says Thank You to Steven Hamoen For This Useful Post: | ||
Shahin Gelareh (04-20-2012) |
#9
|
||||
|
||||
I'm using global variables in dlls without problem. Let's try it again ;-)
In UserFuncs.h you have to add: DECLARE_FLEXSIM_GLOBAL_VARIABLE(Name_Of_Variable, Type_Of_Variable) #define Name_Of_Variable(*_Name_Of_Variable_pointer) In your cpp-file you can use Name_Of_Variable to get access. Example: You have a global variable "counter" of type "double" In UserFuncs.h: DECLARE_FLEXSIM_GLOBAL_VARIABLE(counter, double) #define counter(*_counter_pointer) In mydll.cpp: counter = counter + 1.0; I hope this helps. |
#10
|
|||
|
|||
Thanks Steven. I need to find another way around it.
Recent experiences says waiting for support can make one wasting much time. Carsten, I am not sure if understood what makes you approach different from what Steven proposed initially? |
#11
|
||||
|
||||
In short
Steven: DECLARE_FLEXSIM_GLOBAL_VARIABLE( MyGlobal , int) #define WM_Control (*_MyGlobal _pointer) Carsten: DECLARE_FLEXSIM_GLOBAL_VARIABLE( MyGlobal , int) #define MyGlobal (*_MyGlobal _pointer) Only a small difference but ... P.S.: With Firefox I can't select a color in the editor |
#12
|
|||
|
|||
Hi Carsten,
thank you for paying attention , reading and commenting --- very much appreciated. I basically use DECLARE_FLEXSIM_GLOBAL_VARIABLE( QueueQC, treenodearray ) #define QueueQC (*_QueueQC_pointer) like yours DECLARE_FLEXSIM_GLOBAL_VARIABLE( MyGlobal , int) #define MyGlobal (*_MyGlobal _pointer) but ... am I missing anything. Should VisualSutio be connected to flexsim instance running or some thing like that? |
#13
|
||||
|
||||
If your dll is connected your global variable should work.
I don't know what your problem could be. |
The Following User Says Thank You to Carsten Seehafer For This Useful Post: | ||
Shahin Gelareh (04-23-2012) |
#14
|
|||
|
|||
Thanks for comment.
Finally, Support helped in updating the source code of dll and now it works fine in the same way as people said. Shahin |
Thread | Thread Starter | Forum | Replies | Last Post |
Dinamic Global Variables | juan alberto | Q&A | 3 | 05-25-2011 07:53 AM |
Global variables | juan alberto | Q&A | 5 | 11-10-2010 05:47 PM |
Update of global variables | BenjaminBuecklein | Q&A | 4 | 11-18-2008 03:43 AM |
Limit in the completion hints? Global Tables, Global Variables, etc.? | Tom David | Gripes and Goodies | 6 | 09-09-2008 04:05 PM |
State files and global variables | Markus Bans | Q&A | 3 | 07-08-2008 12:22 PM |