Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Общие вопросы по .NET и C# > регистрация dll и COM Interop


Автор: Perun 3.12.2009, 15:48
Создал расширение оболочки для своего контекстного меню. Получил dll.


В своём приложении использую так:
Код

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ShellExt;

using System.Globalization;
using System.IO;
using Microsoft.Win32;

using System.Diagnostics;

namespace ShellExt
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        const string clsid = "{6B3A1F0C-C382-40d6-AA13-33B0AB46EEAA}";
        string guid = "{6B3A1F0C-C382-40d6-AA13-33B0AB46EEAA}";
        string pathDLL = Application.StartupPath+@"\MENU.dll";
        private void button1_Click(object sender, EventArgs e)
        {
           // Регистрируем COM и dll
            Assembly mAsm = Assembly.LoadFrom(pathDLL);

          try
          {
              RegistrationServices mReg = new RegistrationServices();
              mReg.RegisterAssembly(mAsm,0);
         catch(Exception ex)  
          { 
            MessageBox.Show (ex.Message); 
          }
        }

        private void button2_Click(object sender, EventArgs e)
        {   
           try 
            {
             // Отменяем регистрацию COM и dll
             Assembly mAsm = Assembly.LoadFile(pathDLL);  
             RegistrationServices mReg = new RegistrationServices(); 
             mReg.UnregisterAssembly(mAsm); 
            }
           catch(Exception ex)  
            {
             MessageBox.Show (ex.Message);
            }
        }
}



записи в реестре создаются в самой dll
[code=csharp]

[System.Runtime.InteropServices.ComRegisterFunctionAttribute()]
        static void DLLRegisterServer(String str1)
        {
            try
            {
                // For Winnt set me as an approved shellex
                RegistryKey root;
                RegistryKey rk;
                root = Registry.LocalMachine;
                
                rk = root.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved", true);//rk.SetValue(guid.ToString(), "BatchResults shell extension");
                rk.SetValue(guid, "FrontLine");                
                rk.Close();

                // Set "Folder\\shellex\\ContextMenuHandlers\\BatchResults" regkey to my guid
                root = Registry.ClassesRoot;
                rk = root.CreateSubKey("*\\shellex\\ContextMenuHandlers\\FrontLine");// новое
                rk = root.OpenSubKey("*\\shellex\\ContextMenuHandlers\\FrontLine", true);// новое
                rk.SetValue("", guid);
                rk.Close();
            }
            catch(Exception e)
            {
                System.Console.WriteLine(e.ToString());
            }
        }

        [System.Runtime.InteropServices.ComUnregisterFunctionAttribute()]
        static void DllUnregisterServer(String str1)
        {
            try
            {
                RegistryKey root;
                RegistryKey rk;

                // Remove ShellExtenstions registration
                root = Registry.LocalMachine;
                rk = root.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved", true);
                rk.DeleteValue(guid);//rk.DeleteValue(str1);
                rk.Close();
                // Delete  regkey
                root = Registry.ClassesRoot;
                root.DeleteSubKey("*\\ShellEx\\ContextMenuHandlers\\FrontLine");
            }
            catch(Exception e)
            {
                System.Console.WriteLine(e.ToString());
            }
        }
[code=csharp]


Автор: Perun 3.12.2009, 17:49
я пробовал регистрацию из командной строки через regasm(для 2.0 делаю и Regasm соответственный). Написал, что всё прошло - меню нет, а реестр заполнился. Укажите на ошибку пожалуйста

Автор: Perun 4.12.2009, 15:10
Кто-нибудь ответит?

Автор: explorer 6.12.2009, 10:47
А в GAC сборку свою установил? 
gacutils -i assembly_name.dll

Автор: Perun 18.12.2009, 14:33
благодарю, установил!
хоть и из другой темы, но решение пришло!!)))
как спасибо сказать?

Автор: tol05 18.12.2009, 14:38
Цитата

Репутация: нет [ + | — ]

выбрать одно из двух )))

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)