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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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 |