# Hi list!<br># I&#39;m trying to learn how to write externals (after being able to link and compile the source codes thanks to Yvan Vander Sanden&#39;s tutorial) and come up with a strange behavoir: The object [additive~] turns into a messege box [additive~( (and sometimes its borders are totally erased or sometimes pd crashes) after saving the patch (but not everytime). Maybe I made a mistake that I couldn&#39;t find. What might be the reason of such an error?
<br># Here is the code I&#39;ve written. The object should be post the number of incoming bangs and the time after creation (when dsp is on) and compiled .dll file is attached.<br>-ugur-<br><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include &quot;m_pd.h&quot;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">static t_class *additive_tilde_class;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">

typedef struct _additive_tilde {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; t_object x_obj;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">&nbsp; t_int bangtime;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; t_float time;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">} t_additive_tilde;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">

void additive_tilde_bang(t_additive_tilde *x)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">{</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">

&nbsp; post(&quot;you banged %d times. time: %f&quot;, x-&gt;bangtime++, x-&gt;time);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">}</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">t_int *additive_tilde_perform(t_int *w)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">

{</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; t_additive_tilde *x = (t_additive_tilde *)(w[1]);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">

&nbsp; t_sample&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *out =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (t_sample *)(w[2]);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; n =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (int)(w[3]);</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; while (n--)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; {</span>

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; *out++ = x-&gt;time;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">

&nbsp;&nbsp;&nbsp; x-&gt;time += 1.0f/44100;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; }</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">&nbsp; return (w+4);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">}</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">void additive_tilde_dsp(t_additive_tilde *x, t_signal **sp)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">

{</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; dsp_add(additive_tilde_perform, 3, x,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sp[0]-&gt;s_vec, sp[0]-&gt;s_n);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">}</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">void *additive_tilde_new(t_floatarg f)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">{</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">&nbsp; t_additive_tilde *x = (t_additive_tilde *)pd_new(additive_tilde_class);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">

&nbsp; x-&gt;time = f;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; x-&gt;bangtime =&nbsp; 0;</span><span style="font-family: courier new,monospace;"></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp; outlet_new(&amp;x-&gt;x_obj, gensym(&quot;signal&quot;));
</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; return (void *)x;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">}</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">__declspec (dllexport) void additive_tilde_setup(void)
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">{</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; additive_tilde_class = class_new(gensym(&quot;additive~&quot;),
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (t_newmethod)additive_tilde_new,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0, sizeof(t_additive_tilde),</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CLASS_DEFAULT,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A_DEFFLOAT, 0);</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp; class_addmethod(additive_tilde_class,</span>

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (t_method)additive_tilde_dsp, gensym(&quot;dsp&quot;), 0);</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">&nbsp; class_addbang(additive_tilde_class, additive_tilde_bang);</span><span style="font-family: courier new,monospace;"></span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">}</span><br>