# Correct way of calling VSTPluginFormat::dispatcher

**URL:** <https://forum.juce.com/t/correct-way-of-calling-vstpluginformat-dispatcher/52312>\
**Category:** General JUCE discussion\
**Created:** [July 25, 2022, 4:40pm UTC](https://forum.juce.com/t/correct-way-of-calling-vstpluginformat-dispatcher/52312 "2022-07-25T16:40:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MKR](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@MKR](https://forum.juce.com/u/MKR)\
**Post date:** [July 25, 2022, 4:40pm UTC](https://forum.juce.com/t/correct-way-of-calling-vstpluginformat-dispatcher/52312/1 "2022-07-25T16:40:36Z")

</div>

I am writing a VST3 plugin that hosts a VST2 plugin and need to call the dispatcher.

> class MyPluginAudioProcessor : public juce::AudioProcessor, public juce::AudioProcessorListener  
> {  
> …  
> std::unique\_ptr \<juce::AudioPluginInstance\> vst2plugin;  
> }

I get an compiler error:  
\*Cannot use dynamic\_cast to convert from 'std::unique\_ptr\<juce::AudioPluginInstance\>’ to 'juce::AudioPluginInstance _’_

> void MyPluginAudioProcessor::foo()  
> {  
> auto\* XXX= dynamic\_cast\<juce::AudioPluginInstance\*\>(this.vst2plugin);  
> juce::VSTPluginFormat::dispatcher(XXX, 0, 0, 0, nullptr, 0);  
> }

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [July 25, 2022, 8:34pm UTC](https://forum.juce.com/t/correct-way-of-calling-vstpluginformat-dispatcher/52312/2 "2022-07-25T20:34:13Z")

</div>

dynamic\_cast is not the right tool to access the pointee of an unique\_ptr.

Since the `vst2plugin` is a `std::unique_ptr<juce::AudioPluginInstance>`, you would access the `juce::AudioPluginInstance*` by calling `vst2plugin.get()`, or to get the reference `juce::AudioPluginInstance&` by dereferencing it `*vst2plugin`. But careful, if it is a nullptr.

---

<div class="post-metadata">

**Author:** ![MKR](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@MKR](https://forum.juce.com/u/MKR)\
**Post date:** [July 26, 2022, 7:29am UTC](https://forum.juce.com/t/correct-way-of-calling-vstpluginformat-dispatcher/52312/3 "2022-07-26T07:29:09Z")

</div>

Thanks a lot Daniel!  
vst2plugin.get() did do the trick
