我想要实现的目标是将旧的VB6代码慢慢模块化为C# 我在VB6中创建一个测试来按下一个按钮并执行我的c#表单并传回一个字符串值 我昨天有工作,某种方式改变了,它不再有效。以下是我遇到问题的C#代码。
#define USE_COM
using System;
using System.Linq;
using System.Windows.Forms;
namespace CMS_DB_Operator_Input
{
static class Program
{
/// <summary>
/// Open the OperatorInput Form
///
/// Note: Will output the result to console out on success
/// </summary>
/// <param name="args">0: The Default Filter to Use</param>
/// <returns>
/// 0: Failure to Select
/// 1: Successfully Selected an Item
/// </returns>
[STAThread]
static int Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
string displayName = (args.Length > 1) ? args[1] : null;
string result = "";
displayName = "CBU35PN42";
//displayName = "";
#if USE_COM
CMS_DB_GateKeeper.IGateKeeperUI api = new MS_DB_GateKeeper.GateKeeperUI();
result = api.AskOperatorInput(displayName); // <- INVALID CAST EXCEPTION was unhandled
#else
CMS_DB_GateKeeper.CMS_DB_GateKeeper_OperatorInput op = new CMS_DB_GateKeeper.CMS_DB_GateKeeper_OperatorInput(displayName);
if (displayName == null)
{
Application.Run(op);
if (op.SelectedDisplayName != null)
{
result = op.GetXmlResult(op.SelectedDisplayName); // Success
}
}
else
{
result = op.GetXmlResult(displayName);
}
#endif
Console.WriteLine(result);
return 0;
}
}
}