create and connect with "exe" C#

Can anyone past code here to create the executable file, which can be connected without errors to solidworks? Just Form-Button.

public partial class Form1 : Form
    {
        SldWorks.SldWorks   swApp;
        ModelDoc2           swModel;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                swApp = (SldWorks.SldWorks)Marshal.GetActiveObject("SldWorks.Application");
            }
            catch
            {
                MessageBox.Show("Error getting SolidWorks Handle");
                return;

This code allways show

"Error getting SolidWorks Handle"

And what difference will be if libraries .NET or COM are connected?

SolidworksApi macros