Retrieving input from custom block in userFunction block
I have a C++ dll written using Visual Studio 2015 which is called by a userFunction block.
The dll includes a custom block which asks for a single integer input.
I am able to use the API to create the dialog, set a default for the parameter, etc, but for the life of me, I can't figure out how to put the response back into my dll. Can someone please help?
Answers
-
There are several examples in \vsdk\examples.
If you need just doubles, look at TankMfc.
If you need more sophisticated data types, look at MatrixOp. You create a block with the VBF_USE_SIGNAL_DESCRIPTORS flag and use the SIGNAL fata type in simulation step function.
If you can show an excerpt from your code and specify the problem better, I'll tell you what to do. When I read your post twice, I was not sure if you could not get a value from simulation or from the dialog box.
0 -
Hi Andrei - thanks for the reply.
I'm basically look for a hook to know when the user dismisses the block, so I know to act on it. I'm looking to use the block to launch an external application upon command. (I was assuming since there was an event function to initialize the block parameters, there'd be one when it gets dismissed.) Doesn't seem like that's the case.
I had looked at that example, but it's so old (Visual Studio 5? Whoa...) that my IDE refuses to read it. I did give it another look after your suggestion, and it seems like it's hooking into the dialog values within the simulation function, so this wouldn't work for what I need. The example uses its own dialog, so I might be able to figure out how to hook into its messages. Although I'm actually using Qt and not MFC, so... yeah.
Thanks again.
0 -
There are several functions which must be implemented inside a user block dll source code.
1. Simulation step function,
EXPORT32 void EXPORT PASCAL myFunc(vsmAddon3_INFO* pi, SIGNAL* inSig[], SIGNAL outSig[])
2. Parameter allocation function (the PA function)EXPORT32 long PASCAL EXPORT myFuncPA(short* ppCount)
3. Parameter initialization function (the PI)EXPORT32 void EXPORT PASCAL myFuncPI(vsmAddon3_INFO* pi)
4. Simulation Start function (the SS function)
EXPORT32 void EXPORT PASCAL myFuncSS(vsmAddon3_INFO* pi, long* runCount)5. Parameter Change function (the PC)
EXPORT32 LPSTR EXPORT PASCAL myFuncPC(vsmAddon3_INFO* pi, long* runCount)Usually a dialog box is invoked in this function
6. Simulation End function
EXPORT32 void EXPORT PASCAL myFuncSE(double params[], long* runCount)7. User Event function for a block
EXPORT32 LPSTR PASCAL EXPORT myFuncEvent(HWND h, int msg, WPARAM wParam, LPARAM lParam)'there'd be one when it gets dismissed' this can be either in the simulation end function or in the event function
under
case WM_VSM_DESTROY:
All the WM_VSM_ messages are listed in vsuser.h in \vsdk\include directory.
I always wanted to use Qt instead of MFC for a user dll /emoticons/default_wink.png' srcset='/emoticons/wink@2x.png 2x' title=';)' width='20' />
0 -
WM_VSM_DESTROY is only called when the .vsm is closed unfortunately, not when the block is closed /emoticons/default_sad.png' srcset='/emoticons/sad@2x.png 2x' title=':(' width='20' />. I think I'm stuck with having to hook into qt's message loop.
The Qt thing was relatively straightforward - I created a Qt dll, imported my project into Visual Studio, and then cleaned up the differences by comparing to an existing project that used MFC. Works nicely /emoticons/default_smile.png' srcset='/emoticons/smile@2x.png 2x' title=':)' width='20' /> (Well, except for the problem above lol). Happy to help if you ever need it.
0 -
Oh, did you tell Embed about your block?
In the code, there should be a data structure USER_MENU_ITEM
Then you expose it to Embed in vsmInit (assuming that the data structure name is um1)
EXPORT32 int EXPORT PASCAL vsmInit()
{
setUserBlockMenu(um1);
return 0;
}
In Embed, go to Edit > Preferenced > Addonsand add the path to your dll.
This will place your block in the menu. You can create just a menu entry, without creating a block, if you want to perform just some operation.
Can you describe the scenario you trying to implement, please?
0