您的位置:首页 > 移动开发 > Objective-C

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

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!
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐