ATTENTION

This 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

Go Back   FlexSim Community Forum > FlexSim Software > Q&A
Downloads

Q&A Using Flexsim and building models

  #1  
Old 05-25-2010
Esther Bennett Esther Bennett is offline
Flexsim User
 
Join Date: Mar 2008
Posts: 115
Downloads: 27
Uploads: 0
Thanks: 103
Thanked 116 Times in 50 Posts
Rep Power: 271
Esther Bennett is a name known to allEsther Bennett is a name known to allEsther Bennett is a name known to allEsther Bennett is a name known to allEsther Bennett is a name known to allEsther Bennett is a name known to all
Default 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  
Old 05-25-2010
Phil BoBo's Avatar
Phil BoBo Phil BoBo is offline
Flexsim Development
 
Join Date: Jan 2008
Posts: 756
Downloads: 109
Uploads: 18
Thanks: 385
Thanked 1,483 Times in 525 Posts
Rep Power: 1174
Phil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond repute
Default

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  
Old 05-25-2010
Lars-Olof Leven Lars-Olof Leven is offline
Flexsim Distributor
 
Join Date: Aug 2007
Location: Sweden, Borlnge
Posts: 312
Downloads: 278
Uploads: 2
Thanks: 300
Thanked 256 Times in 139 Posts
Rep Power: 330
Lars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to behold
Default

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;
It should be above your declaration.

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  
Old 05-26-2010
Esther Bennett Esther Bennett is offline
Flexsim User
 
Join Date: Mar 2008
Posts: 115
Downloads: 27
Uploads: 0
Thanks: 103
Thanked 116 Times in 50 Posts
Rep Power: 271
Esther Bennett is a name known to allEsther Bennett is a name known to allEsther Bennett is a name known to allEsther Bennett is a name known to allEsther Bennett is a name known to allEsther Bennett is a name known to all
Default

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  
Old 05-26-2010
Anthony Johnson's Avatar
Anthony Johnson Anthony Johnson is offline
Manager of Product Development
 
Join Date: Jul 2007
Posts: 440
Downloads: 86
Uploads: 4
Thanks: 171
Thanked 899 Times in 288 Posts
Rep Power: 735
Anthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond repute
Default

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));
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.
The Following User Says Thank You to Anthony Johnson For This Useful Post:
Esther Bennett (05-27-2010)
  #6  
Old 09-11-2012
LINWEIXU
Guest
 
Posts: n/a
Downloads:
Uploads:
Default

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.
Attached Files
File Type: zip DLL Maker5.04.zip (4.69 MB, 166 views)

Last edited by LINWEIXU; 09-11-2012 at 03:17 AM.
  #7  
Old 09-12-2012
Carsten Seehafer's Avatar
Carsten Seehafer Carsten Seehafer is offline
FlexSim Geek
 
Join Date: Oct 2008
Location: Ritterhude, Deutschland
Posts: 230
Downloads: 45
Uploads: 1
Thanks: 474
Thanked 320 Times in 143 Posts
Rep Power: 379
Carsten Seehafer has much to be proud ofCarsten Seehafer has much to be proud ofCarsten Seehafer has much to be proud ofCarsten Seehafer has much to be proud ofCarsten Seehafer has much to be proud ofCarsten Seehafer has much to be proud ofCarsten Seehafer has much to be proud ofCarsten Seehafer has much to be proud ofCarsten Seehafer has much to be proud of
Default

Without looking into your attachment I see only "Double" instead of "double". This could be an error because C++ is case sensitive.

Greetings

Carsten
  #8  
Old 09-12-2012
LINWEIXU
Guest
 
Posts: n/a
Downloads:
Uploads:
Default

thanks,the problem have solved .but in flexsim the gui set global variable use Double.

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


All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.