2014-10-07 30 views
0

我在VB.Net中創建了一個用於Visual Foxpro應用程序的DLL。最近,我添加了一些功能來幫助清理數據並清除用戶控件的輸入並重新構建項目。我目前使用Regasm來註冊DLL,這似乎工作正常。但是,當我註冊的DLL,新功能不顯示,使它看起來像一個仍在使用舊的,以前註冊的DLL。有沒有事情我做得不對? 下面是代碼的摘錄。添加的功能沒有出現在COM對象中

<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 
+0

您是否在註冊新註冊之前取消註冊舊程序集?您是否確定在註冊時指向新的程序集? – 2014-10-07 20:41:58

+0

是的。註銷和註冊是從批處理文件完成的。我甚至去創建和註冊.tlb文件,但似乎沒有任何工作 – Jay 2014-10-13 14:26:00

回答

0

不確定您的消毒DLL/COM的問題,而是你的sanitize串,我不知道爲什麼你不只是用VFP的功能STRTRAN()

someString = [什麼是布萊恩]

? STRTRAN(someString, 「'」, 「 ''」)

將導致

什麼是布萊恩''上

Help on StrTran() function

Another cool one is CHRTRAN(),具有廣泛的利益,從通過將字符串中的每個字符替換爲其他字符,將字符串中的無效字符剝離爲僞加密...

+0

DLL在vb.net中創建幷包含捕獲和保存數據所需的所有功能。使用此DLL的軟件是在vfp中完成的。這就是爲什麼我沒有使用這些功能 - STRTRAN()和CHRTRAN() – Jay 2014-10-13 14:30:16

+0

@Jay ...正確..如果您使用VFP來完成這項工作並調用VB.net DLL,那麼您不需要VB .net DLL。這些是默認內置在VFP中的功能,您可以直接使用它們。不需要外部DLL功能。 – DRapp 2014-10-13 15:28:42

+0

我需要實現的任務不能從VFP完成,因此需要.NET dll。 Vfp只是簡單地使用dll,因爲原始軟件是在VFP9中完成的 – Jay 2014-10-14 09:58:41