Utworzyłem bibliotekę DLL w języku C# przy użyciu środowiska .NET 3.0.Wykonaj kod .NET 3.0 z pakietu Office 2003
Poniżej znajduje się kod mojego DLL
namespace CompanyName.Net
{
[Guid("F7075E8D-A6BD-4590-A3B5-7728C94E372F")]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ProgId("CompanyName.Net.Webrequest")]
public class WebRequest
{
public string Result { get; private set; }
public string Url { get; set; }
public string StatusDescription { get; private set; }
public HttpStatusCode StatusCode { get; private set; }
public WebRequest()
{
//explicit constructor
}
public string GetResponse(string url)
{
System.Net.WebRequest webreq = System.Net.WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse) webreq.GetResponse();
// Store the status.
StatusDescription = response.StatusDescription;
StatusCode = response.StatusCode;
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
Result = reader.ReadToEnd();
// Cleanup the streams and the response.
reader.Close();
dataStream.Close();
response.Close();
//return the response
return Result;
}
}
}
Próbuję uzyskać ten kod do uruchomienia pakietu Office 2003 z kodu VBA. Biblioteka DLL została podpisana przy użyciu domyślnego podpisu programu Visual Studio 2008.
udało mi się odwołać mój zespół, tworząc plik .tlb korzystając
regasm /tlb c:\CompanyName.Net.dll
Ale gdy chcę utworzyć instancję obiektu:
Private Sub Command0_Click()
Dim o As Object
Set o = CreateObject("CompanyName.Net.WebRequest")
Dim s As String
s = o.GetResponse("http://www.google.be")
MsgBox s
End Sub
pojawia się następujący błąd :
ActiveX component can't create Object
Co robię źle?
Maszyna, którą testuję, ma zainstalowaną platformę .NET do architektury .NET 3.5.
Jest to najbardziej zwięzły i jedyny kompletny przewodnik po tym problemie, który znalazłem po wielu godzinach próbowania, aby to zadziałało. Dziękuję Ci. –