Драйвер OPOS для масштабной разработки. Не могу правильно зарегистрировать dll (C#)C#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 Драйвер OPOS для масштабной разработки. Не могу правильно зарегистрировать dll (C#)

Сообщение Anonymous »

Вот мой код:

Код: Выделить всё

using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using OPOSCONSTANTSLib;
using OposScale_CCO;

namespace ScaleOPOS
{
[ComVisible(true)]
[Guid("D3673432-393B-4CFF-B382-CED8F12F3388")]
[ProgId("ScaleOPOS.WeightScale")]
[ClassInterface(ClassInterfaceType.None)]

public class WeightScale : IOPOSScale
{
[ComRegisterFunction]
public static void DllRegisterServer(Type type)
{
try
{
string classKey = @"Software\Wow6432Node\OLEforRetail\ServiceOPOS\Scale";
using (RegistryKey key = Registry.LocalMachine.CreateSubKey(classKey + @"\EmulatedScale"))
{
key.SetValue("FriendlyName", "WeightScale");
key.SetValue("ProgID", "ScaleOPOS.WeightScale");
key.SetValue("Version", "1.0");
}

// Запись для ProgID
string progIdKey = @"Software\Wow6432Node\Classes\ScaleOPOS.WeightScale";
using (RegistryKey progId = Registry.LocalMachine.CreateSubKey(progIdKey))
{
progId.SetValue("", "WeightScale");
progId.SetValue("CLSID", type.GUID.ToString("B").ToUpper());
}

// Запись для CLSID
string clsidKey = $@"Software\Wow6432Node\Classes\CLSID\{type.GUID.ToString("B").ToUpper()}";
using (RegistryKey clsid = Registry.LocalMachine.CreateSubKey(clsidKey))
{
clsid.SetValue("", "WeightScale"); // Имя вашего COM-объекта

using (RegistryKey inprocServer = clsid.CreateSubKey("InprocServer32"))
{
inprocServer.SetValue("", @"C:\Users\Dmitriy\Desktop\ScaleOPOSDriver\bin\Debug\ScaleOPOSDriver.dll"); // Укажите путь к вашей DLL
inprocServer.SetValue("ThreadingModel", "Apartment");
}
}
}
catch (Exception ex)
{
throw new InvalidOperationException("Ошибка регистрации: " + ex.Message, ex);
}
}

[ComUnregisterFunction]
public static void DllUnregisterServer(Type type)
{
try
{
string classKey = @"Software\Wow6432Node\OLEforRetail\ServiceOPOS\Scale";
Registry.LocalMachine.DeleteSubKey(classKey + "\\EmulatedScale", false);

string progIdKey = @"Software\Wow6432Node\Classes\ScaleOPOS.WeightScale";
Registry.LocalMachine.DeleteSubKey(progIdKey, false);

string clsidKey = $@"Software\Wow6432Node\Classes\CLSID\{type.GUID.ToString("B").ToUpper()}";
Registry.LocalMachine.DeleteSubKey(clsidKey, false);
}
catch (Exception ex)
{
// Здесь можно записать лог или вывести сообщение об ошибке
throw new InvalidOperationException("Ошибка регистрации: "  + ex.Message, ex);
}
}

public WeightScale() { }

public void SOData(int Status)
{
throw new NotImplementedException();
}

public void SODirectIO(int EventNumber, ref int pData, ref string pString)
{
throw new NotImplementedException();
}

public void SOError(int ResultCode, int ResultCodeExtended, int ErrorLocus, ref int pErrorResponse)
{
throw new NotImplementedException();
}

public void SOOutputCompleteDummy(int OutputID)
{
throw new NotImplementedException();
}

public void SOStatusUpdate(int Data)
{
throw new NotImplementedException();
}

public int SOProcessID()
{
throw new NotImplementedException();
}

public int CheckHealth(int Level)
{
throw new NotImplementedException();
}

public int ClaimDevice(int Timeout)
{
throw new NotImplementedException();
}

public int ClearInput()
{
throw new NotImplementedException();
}

public int Close()
{
throw new NotImplementedException();
}

public int DirectIO(int Command, ref int pData, ref string pString)
{
throw new NotImplementedException();
}

public int Open(string DeviceName)
{
throw new NotImplementedException();
}

public int ReleaseDevice()
{
throw new NotImplementedException();
}

public int ReadWeight(out int pWeightData, int Timeout)
{
throw new NotImplementedException();
}

public int DisplayText(string Data)
{
throw new NotImplementedException();
}

public int ZeroScale()
{
throw new NotImplementedException();
}

public int ResetStatistics(string StatisticsBuffer)
{
throw new NotImplementedException();
}

public int RetrieveStatistics(ref string pStatisticsBuffer)
{
throw new NotImplementedException();
}

public int UpdateStatistics(string StatisticsBuffer)
{
throw new NotImplementedException();
}

public int CompareFirmwareVersion(string FirmwareFileName, out int pResult)
{
throw new NotImplementedException();
}

public int UpdateFirmware(string FirmwareFileName)
{
throw new NotImplementedException();
}

public int OpenResult => throw new NotImplementedException();

public string CheckHealthText => throw new NotImplementedException();

public bool Claimed => throw new NotImplementedException();

public bool DeviceEnabled { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public bool FreezeEvents { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

public int ResultCode => throw new NotImplementedException();

public int ResultCodeExtended => throw new NotImplementedException();

public int State => throw new NotImplementedException();

public string ControlObjectDescription => throw new NotImplementedException();

public int ControlObjectVersion => throw new NotImplementedException();

public string ServiceObjectDescription => throw new NotImplementedException();

public int ServiceObjectVersion => throw new NotImplementedException();

public string DeviceDescription => throw new NotImplementedException();

public string DeviceName => throw new NotImplementedException();

public int MaximumWeight => throw new NotImplementedException();

public int WeightUnit => throw new NotImplementedException();

public int WeightUnits => throw new NotImplementedException();

public int BinaryConversion { get => throw new NotImplementedException(); set => throw new NotImplementedException();  }

public bool CapDisplay => throw new NotImplementedException();

public bool AutoDisable { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

public int CapPowerReporting => throw new NotImplementedException();

public int DataCount => throw new NotImplementedException();

public bool DataEventEnabled { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public int PowerNotify { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

public int PowerState => throw new NotImplementedException();

public bool AsyncMode { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

public bool CapDisplayText => throw new NotImplementedException();

public bool CapPriceCalculating => throw new NotImplementedException();

public bool CapTareWeight => throw new NotImplementedException();

public bool CapZeroScale => throw new NotImplementedException();

public int MaxDisplayTextChars => throw new NotImplementedException();

public decimal SalesPrice => throw new NotImplementedException();

public int TareWeight { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public decimal UnitPrice { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

public bool CapStatisticsReporting => throw new NotImplementedException();

public bool CapUpdateStatistics => throw new NotImplementedException();

public bool CapCompareFirmwareVersion => throw new NotImplementedException();

public bool CapUpdateFirmware => throw new NotImplementedException();

public bool CapStatusUpdate => throw new NotImplementedException();

public int ScaleLiveWeight => throw new NotImplementedException();

public int StatusNotify { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public bool ZeroValid { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
}
}
.NET FRAMEWORK 4.8

Код: Выделить всё

Regasm name.dll /codebase Команда 
работает успешно. И сторонний тестер OPOS показывает мой драйвер в своем списке. Но выбирая драйвер, я получаю (см. картинку ниже):
введите сюда описание изображения
Что я делаю не так? Я слышал, что нет необходимости явно указывать пути в реестре или это необходимо? Пожалуйста, помогите!!
Я пытался не показывать пути явно, но таким образом тест OPOS вообще не видит мой драйвер.
Я пытался зарегистрировать dll с помощью regsvr32 . Таким образом я получаю "точка входа в DllRegisterServer не найдена!"
Извините за мой английский))

Подробнее здесь: https://stackoverflow.com/questions/790 ... ster-dll-c
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C#»