【问题标题】:Added functionality not showing up in a COM object添加的功能未显示在 COM 对象中
【发布时间】:2014-10-07 08:44:02
【问题描述】:

我在 VB.Net 中创建了一个用于 Visual Foxpro 应用程序的 dll。最近我添加了一些功能来帮助清理数据和清除来自用户控件的输入并重新构建项目。我目前正在使用 Regasm 注册 dll,这似乎工作正常。但是,当我注册 dll 时,没有显示新功能,看起来好像仍在使用旧的、以前注册的 dll。有什么我做的不对吗? 这是代码的摘录。

    <ClassInterface(ClassInterfaceType.AutoDispatch), ProgId("LPFPasserelle.FicheEtablissement")>
    Public Class FicheEtablissement
      Private mCreateInstitution As New CreateInstitution
       <ComRegisterFunction()>
    Public Shared Sub RegisterClass(ByVal key As String)

    Dim sb As StringBuilder = New StringBuilder(key)
    sb.Replace("HKEY_CLASSES_ROOT\", "")

    '// Open the CLSID\{guid} key for write access  
    Dim k As RegistryKey = Registry.ClassesRoot.OpenSubKey(sb.ToString(), True)
    Dim ctrl As RegistryKey = k.CreateSubKey("Control")
    ctrl.Close()

    '// Next create the CodeBase entry - needed if not string named and GACced.  
    Dim inprocServer32 As RegistryKey = k.OpenSubKey("InprocServer32", True)
    inprocServer32.SetValue("CodeBase", Assembly.GetExecutingAssembly().CodeBase)
    inprocServer32.Close()

    k.Close()
End Sub

<ComUnregisterFunction()>
Public Shared Sub UnregisterClass(ByVal key As String)

    Dim sb As StringBuilder = New StringBuilder(key)
    sb.Replace("HKEY_CLASSES_ROOT\", "")

    '// Open HKCR\CLSID\{guid} for write access  
    Dim k As RegistryKey = Registry.ClassesRoot.OpenSubKey(sb.ToString(), True)

    '// Delete the 'Control' key, but don't throw an exception if it does not exist  
    If k Is Nothing Then
        Return
    End If
    k.DeleteSubKey("Control", False)

    '// Next open up InprocServer32  
    Dim inprocServer32 As RegistryKey = k.OpenSubKey("InprocServer32", True)

    '// And delete the CodeBase key, again not throwing if missing   
    inprocServer32.DeleteSubKey("CodeBase", False)

    '// Finally close the main key   
    inprocServer32.Close()
    k.Close()

End Sub

我添加的清理字符串数据的功能如下。

 Function SanitizeStringData(ByVal StringToSanitize As String)
    Dim mSanitizedString As String = String.Empty
    mSanitizedString = Trim(StringToSanitize)
    If Trim(StringToSanitize).Contains("'") Then
        mSanitizedString = Trim(StringToSanitize).Replace("'", "''")
    End If
    Return mSanitizedString
End Function

【问题讨论】:

  • 您是否在注册新程序集之前取消注册旧程序集?您确定在注册时指向新程序集吗?
  • 是的。注销和注册是从批处理文件完成的。我什至已经创建和注册了 .tlb 文件,但似乎没有任何效果

标签: vb.net com visual-foxpro


【解决方案1】:

不确定你的清理 dll/COM 问题,但对于你的清理字符串,我不知道你为什么不只是使用 VFP 的函数 STRTRAN()

someString = [发生了什么]

? STRTRAN(someString, "'", "''" )

会导致

发生了什么

Help on StrTran() function

Another cool one is CHRTRAN() 并通过将字符串中的每个字符替换为其他字符来从字符串中剥离无效字符到伪加密,从而具有广泛的好处......

【讨论】:

  • 该 dll 在 vb.net 中创建,包含捕获和保存数据所需的所有功能。使用这个 dll 的软件是在 vfp 中完成的。这就是为什么我没有使用这些函数 - STRTRAN() 和 CHRTRAN()
  • @Jay... 正确.. 如果您使用 VFP 完成工作并调用 VB.net dll,则不需要 vb.net DLL。这些是 INTO VFP 默认内置的功能,您可以直接使用它们。无需外部 dll 功能。
  • 我需要完成的任务无法从 VFP 完成,因此是 .NET dll。 Vfp 只是在消耗 dll,因为原始软件是在 VFP9 中完成的
猜你喜欢
  • 2017-04-14
  • 2011-03-27
  • 1970-01-01
  • 2012-11-11
  • 2013-09-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-01
相关资源
最近更新 更多