Using CoCreateObjectDotNet to Access and Use .NET Assemblies in InstallScript
2011-04-18 15:42
711 查看
http://kb.flexerasoftware.com/selfservice/viewContent.do?externalID=Q112220
STEP 1. Create the DLL
using System;
using System.Runtime.InteropServices;
namespace ViewerCentral
{
[ClassInterface(ClassInterfaceType.AutoDispatch)]
[Guid("4E0697CB-209A-40c5-939D-709924CC9AFB")]
public class IISUtils: I_IISUtils
{
public IISUtils() {}
public stri
4000
ng GetStringSites()
{
return "Test";
}
}
[Guid("B464E841-D49A-4f5b-8701-0C40544CF110")]
public interface I_IISUtils
{
string GetStringSites();
}
}
Several notes here:
- Don't return to InstallScript complex classes or objects, but only simple types that can be recognized, like ( int, string, etc.).
- NO registration for COM Interop is necessary, however, as you see the DLL must be in the COM Interrop format.
STEP 2. Use DLL in InstallScript
1. Add your DLL to Support Files (I have added it to Language Independent).
2. Define a path to the DLL:
#define DLL_FILE SUPPORTDIR ^ "IISUtils.dll"
3. Use the DLL by calling one of its methods.
object oIISUtils;
string szSites;
set oIISUtils = CoCreateObjectDotNet( DLL_FILE, "ViewerCentral.IISUtils" );
szSites = oIISUtils.GetStringSites();
Hope this helps pull this out faster. This certainly worked for me. Good Luck!
Q112220: CODE: Using CoCreateObjectDotNet to Access and Use .NET Assemblies in InstallScript |
InstallShield 11.5 Premier, InstallShield 11.5 Professional, InstallShield 12 Premier, InstallShield 12 Professional, InstallShield 2008 Premier, InstallShield 2008 Professional |
Basic MSI, InstallScript MSI |
CoCreateObjectDotNet calls functions within assemblies that are creating using .NET. CoCreateObjectDotNet creates an object that references a method of a .NET assembly. Each method you wish to use will require a separate call into CoCreateObjectDotNet. Note: Assemblies built with Visual Studio 2005 require that the attribute ComVisible be set to true for each class that will be called from CoCreateObjectDotNet. |
The code below demonstrates a sample implementation of CoCreateObjectDotNet assuming you've created a DLL using .NET 2.0 that has a class named OutputInfo with the method DisplaySystemInfo().try set dotNet = CoCreateObjectDotNet(SUPPORTDIR ^ "SampleClass.dll","SampleClass.OutputInfo"); dotNet.DisplaySystemInfo(); catch SprintfBox(INFORMATION,"CoCreateObjectDotNet Error","ERROR: %s NUMBER: %d",Err.Description,Err.Number); endcatch; |
For additional help with the ComVisible attribute, please reference MSDN article ComVisibleAttribute Class. For additional information on InstallScript, see the InstallScript Language Reference in the InstallShield Help Library. |
Last Modified Date: 11-30-2009 ID: Q112220 |
STEP 1. Create the DLL
using System;
using System.Runtime.InteropServices;
namespace ViewerCentral
{
[ClassInterface(ClassInterfaceType.AutoDispatch)]
[Guid("4E0697CB-209A-40c5-939D-709924CC9AFB")]
public class IISUtils: I_IISUtils
{
public IISUtils() {}
public stri
4000
ng GetStringSites()
{
return "Test";
}
}
[Guid("B464E841-D49A-4f5b-8701-0C40544CF110")]
public interface I_IISUtils
{
string GetStringSites();
}
}
Several notes here:
- Don't return to InstallScript complex classes or objects, but only simple types that can be recognized, like ( int, string, etc.).
- NO registration for COM Interop is necessary, however, as you see the DLL must be in the COM Interrop format.
STEP 2. Use DLL in InstallScript
1. Add your DLL to Support Files (I have added it to Language Independent).
2. Define a path to the DLL:
#define DLL_FILE SUPPORTDIR ^ "IISUtils.dll"
3. Use the DLL by calling one of its methods.
object oIISUtils;
string szSites;
set oIISUtils = CoCreateObjectDotNet( DLL_FILE, "ViewerCentral.IISUtils" );
szSites = oIISUtils.GetStringSites();
Hope this helps pull this out faster. This certainly worked for me. Good Luck!
相关文章推荐
- Using SiteMap and MasterPages to set META Tags in ASP.NET and C#
- Steps to Create Setup and Deployment Project in Dot Net VS 2008
- Preview Word files (docx) in HTML using ASP.NET, OpenXML and LINQ to XML
- How To Use the ODBC .NET Managed Provider in Visual C# .NET and Connection Strings
- Preview Word files (docx) in HTML using ASP.NET, OpenXML and LINQ to XML
- how to save a c++ object in java object and use it
- Understanding and Using Assemblies and Namespaces in .NET
- Setting the Reply-To Header in an Email using CDONTS.NewMail Object and CDO Message
- using an enumerable built-in Ruby to access and manipulate nested data
- Send and Receive JSON objects to Web Service Methods using jQuery AJAX in ASP.Net
- How to use Bundle&Minifier and bundleconfig.json in ASP.NET Core
- How To Use ADO.NET to Retrieve and Modify Records in an Excel Workbook With Visual Basic .NET(利用Ado.net导出到Excel)
- An Introduction to JavaScript Object Notation (JSON) in JavaScript and .NET
- Use ASP.NET and DotNetZip to Create and Extract ZIP Files
- How to create aligned partitions in Linux for use with NetApp LUNs, VMDKs, VHDs and other virtual di
- 采用ADO.NET存取Excel数据(Use ADO.NET to Retrieve and Modify Records in an Excel Workbook)
- Data Transfer between Business and Data Access Components in Enterprise Applications using .Net
- Use Office Web Components to Load Excel and perform calculations in ASP.NET
- How to use HttpWebRequest and HttpWebResponse in .NET
- How to Access and Use the Windows Hosts File in Windows 7 and Vista