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 10-28-2010
Steven Hamoen's Avatar
Steven Hamoen Steven Hamoen is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Location: Soest, NL
Posts: 854
Downloads: 43
Uploads: 0
Thanks: 391
Thanked 661 Times in 379 Posts
Rep Power: 684
Steven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond repute
Default loaduserlibrary in DLL

This is clearly a question for Flexsim.
I have checked "flexsimrunnerexports.txt" and the function "loaduserlibrary" should be available in the DLL. So I implemented it in the Flexsimfuncs.h with:

DECLARE_FLEXSIM_FUNCTION(loaduserlibrary)

and

typedef fsnode* (*_loaduserlibrary)(string Filename, fsnode* View, int reloadmedia, int changeitemcurrent, int autoinstall);

But when I call the function I get exception errors. I call it as follows:

loaduserlibrary( FileName, NULL, 1, 0, 1);

Filename is a string and I checked this function in the scriptwindow and it works so the filename and path are correct.

What have I done wrong?
  #2  
Old 11-01-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

The problem is that a string class is being passed across dll boundaries. It has to do with the allocation/deallocation of memory. The dll contains its own "heap" of memory that is separate from the exe's "heap". When the dll calls a function that's implemented on the exe's side, and passes a string as a parameter, the string's constructor method is called by the dll, which means it allocates memory on the dll's heap, while the string's destructor method is called (after the function is finished) on the exe's side, which means the memory is assumed to be deallocated from the exe's heap. Since it's allocated and deallocated on different heaps, this causes an exception. Hence all functions available to dll's must take/return char*'s instead of strings.

As for a work-around, for now I'd say see if you can call a flexscript nodefunction from the dll, and then call loaduserlibrary() from the flexscript.

Anthony
The Following User Says Thank You to Anthony Johnson For This Useful Post:
Steven Hamoen (11-01-2010)
  #3  
Old 11-01-2010
Steven Hamoen's Avatar
Steven Hamoen Steven Hamoen is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Location: Soest, NL
Posts: 854
Downloads: 43
Uploads: 0
Thanks: 391
Thanked 661 Times in 379 Posts
Rep Power: 684
Steven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond repute
Default

Hi Anthony,

Thanks, I already implemented the work around, I was just wondering if I did something wrong.

So I guess we just have to wait for the next release

Steven

Tags
dll, flexsimrunnerexports.txt, loaduserlibrary


Thread Thread Starter Forum Replies Last Post
Does the "loaduserlibrary" command has a flaw? Steven Hamoen Q&A 1 06-03-2008 02:47 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.