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 variable in DLL (UserFuncs.h)
Hello,
I would like to use a global (Flexsim) variable in my dll code, but I cannot get it to work. What I did: I added the UserFuncs.h file from the dll maker to my header files. I declared a global variable as: DECLARE_FLEXSIM_GLOBAL_VARIABLE( WM_Control, treenode ) #define WM_Control (*_WM_Control_pointer) when I try to compile (debug or release mode) I get the following error msg: >c:\flexsim\flexsim5\libraries\dll maker\userfuncs.h(16) : error C2065: 'intWM_Control_globalvariableindex' : undeclared identifier 1>c:\flexsim\flexsim5\libraries\dll maker\userfuncs.h(16) : error C2065: 'WM_Control_globalvariableindex' : undeclared identifier 1>c:\flexsim\flexsim5\libraries\dll maker\userfuncs.h(16) : error C2065: 'successful' : undeclared identifier 1>c:\flexsim\flexsim5\libraries\dll maker\userfuncs.h(16) : error C2065: 'WM_Control_globalvariableindex' : undeclared identifier can anyone explain how to use the global variables in dll code? Thanks.! Esther |
#2
|
||||
|
||||
If you have a global variable that you only want to use within your dll, just add it like a usual global variable in C++ by defining it outside the scope of any function or class.
|
#3
|
|||
|
|||
Hi,
If it is a global variable in a Flexsim model, try to add this line of code to UserFuc.h. Code:
#define DECLARE_FLEXSIM_GLOBAL_VARIABLE(name, type) type * _##name##_pointer; When tested in VS C++ 2005 there are no error in compiling but I have not tested to use it in a DLL. Lars-Olof |
#4
|
|||
|
|||
Hello Lars-Olof and Phil,
Thanks for your replies. The object I want to refer to is indeed a Flexsim Global Variable and Lars_Olofs tip helped me in a way, but all my references in the cpp files give error msgs when building the solution. I get an error "C2440: 'initializing' : cannot convert from 'linkedlist *' to 'treenode *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast". I had already tried the tip Phil gave me in an earlier stage, but did not succeed, I will try this again though and try to get it to work. Esther |
#5
|
||||
|
||||
Esther,
I've made and committed some changes to the dll repository. It turns out it was an issue with binding.h. I changed the definition of DECLARE_FLEXSIM_GLOBAL_VARIABLE to: Code:
#define DECLARE_FLEXSIM_GLOBAL_VARIABLE(name, type)\ int _##name##_globalvariableindex = getglobalvariableindex(#name);\ if(_##name##_globalvariableindex == 0)\ { unboundfunctions += #name; unboundfunctions += "\n"; }\ else _##name##_pointer = &(getglobalvariableas##type(_##name##_globalvariableindex)); |
The Following User Says Thank You to Anthony Johnson For This Useful Post: | ||
Esther Bennett (05-27-2010) |
#6
|
|||
|
|||
I copy this code to binding.h
#define DECLARE_FLEXSIM_GLOBAL_VARIABLE(name, type)\ int _##name##_globalvariableindex = getglobalvariableindex(#name);\ if(_##name##_globalvariableindex == 0)\ { unboundfunctions += #name; unboundfunctions += "\n"; }\ else _##name##_pointer = &(getglobalvariableas##type(_##name##_globalvariab leindex)) i want to use global varible variable1 in dll and i add two lines in UserFuncs.h DECLARE_FLEXSIM_GLOBAL_VARIABLE(variable1, Double) #define var (*_variable1_pointer) and i insert #include "UserFuncs.h"into the file FlexsimFuncs.h but i also get error, what is wrong? attach is my dll maker ,i use vs2008 and flexsim 5.04. Last edited by LINWEIXU; 09-11-2012 at 03:17 AM. |
#7
|
||||
|
||||
Without looking into your attachment I see only "Double" instead of "double". This could be an error because C++ is case sensitive.
Greetings Carsten |
Tags |
dll, global variable |
Thread | Thread Starter | Forum | Replies | Last Post |
Global variable as experiment variable | Matthias Hofmann | Q&A | 3 | 09-08-2009 09:42 AM |
Variable Operator | Michael Hartlieb | Q&A | 2 | 07-06-2009 03:53 AM |
Global variable named "i" | Bill Chan | Gripes and Goodies | 1 | 04-21-2009 06:40 AM |
Limit in the completion hints? Global Tables, Global Variables, etc.? | Tom David | Gripes and Goodies | 6 | 09-09-2008 04:05 PM |
Display Global Variable | Sung Kim | Q&A | 4 | 02-24-2008 11:24 PM |