Tag: c ++

T-SQL:将新的INSERT标识返回给C#

我正在使用存储过程将值放入SQL Server。 过程将向添加的行添加ID。 我需要将此ID返回到我的代码中。 目前我可以在Visual Studio的OUTPUT窗口中看到输出ID,但似乎无法在我的代码中捕获它。 以下是proc的摘要版本: SQL : CREATE PROCEDURE dbo.DoSomething ( @var1 INT = NULL, @var2 INT = NULL, @var3 DATE = NULL ) AS BEGIN INSERT INTO atable ( vara, varb, varc ) VALUES ( @var1, @var2, @var3 ) RETURN SCOPE_IDENTITY() END C#: int result = 0; /// create command SqlCommand cmd […]

检查Windows安装程序mutex的可用性

在我的一个集成测试中,我有两个线程卸载然后安装程序但是当按顺序运行时它们会生成错误Failed to grab execution mutex. System error 258. Failed to grab execution mutex. System error 258. 为了解决这个问题,我必须在卸载后睡觉。 我试着检查msiexec进程是否正在运行但是一直有2-3个因此它不是一个好的指标。 有没有办法检查msiexec执行互斥锁是否可用?

将C#Jagged数据编组到C ++

我正在尝试将2D C#锯齿状数组( double[][] jaggedArray ) double[][] jaggedArray到C ++ dll中,我已将接收变量指定为double** 。 但是,我收到的消息是: 嵌套数组没有编组支持。 如果没有扁平化锯齿状arrays,有没有办法在C ++ dll中使用C#中的锯齿状数组?

超类构造函数中的虚拟化

我认为根据OOP的设计,虚拟化在超类构造函数中不起作用。 例如,请考虑以下C#代码。 using System; namespace Problem { public class BaseClass { public BaseClass() { Console.WriteLine(“Hello, World!”); this.PrintRandom(); } public virtual void PrintRandom() { Console.WriteLine(“0”); } } public class Descendent : BaseClass { private Random randomValue; public Descendent() { Console.WriteLine(“Bonjour, Monde!”); randomValue = new Random(); } public override void PrintRandom() { Console.WriteLine(randomValue.NextDouble().ToString()); } public static void […]

从Windows Phone 7中读取文件

我的项目中有一个名为data/的文件夹,其中包含txt files 。 我将Build Action配置为所有文件的resources 。 我试过这些不同的方式: 方法1 var resource = Application.GetResourceStream(new Uri(fName, UriKind.Relative)); StreamReader streamReader = new StreamReader(resource.Stream); Debug.WriteLine(streamReader.ReadToEnd()); 方法2 IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication(); string[] fileNames = myIsolatedStorage.GetFileNames(“*.txt”); 方法3 using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) { using (StreamReader fileReader = new StreamReader(new IsolatedStorageFileStream(fName, FileMode.Open, isf))) { while (!fileReader.EndOfStream) { string line = fileReader.ReadLine(); al.Add(line); Debug.WriteLine(line); […]

将C ++二维固定长度char数组封装为结构成员

我试图调用一个非托管C ++函数,它有一个结构作为输入参数。 结构在头文件中定义如下: struct MyStruct { int siOrder; char aaszNames[6][25]; int siId[6]; int siTones[6]; }; 我试图将托管结构声明如下: [StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Ansi)] public struct MyStruct { public int siOrder; [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst=150)] public string aaszNames; [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst=6, ArraySubType=UnmanagedType.I4)] public int[] siId; [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst=6, ArraySubType=UnmanagedType.I4)] public int[] siTones; } 但没有任何成功。 我猜测编组失败了,因为aaszNames实际上是一个由六个25长的空终止字符串组成的数组。 我尝试将aaszNames声明为 [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst=150)] public char[] aaszNames; 必要时用空值填充数组。 但是,再一次,没有。 有什么我想念的吗? 我错了什么? […]

C#SendKeys.Send

我正在使用C#SendKeys.Send方法运行一个问题。 我正在尝试用其他键替换键盘键,例如当我在键盘中按“a”时,我希望该键为“s”,例如,当我在我的代码中执行此操作时: if ((Keys)keyCode== Keys.A) { SendKeys.Send(“s”); } 现在我只在我的记事本中打印出“sa”字符,但在这种情况下我不需要打印“sa”而只需要“s”字符,因为当我按下键盘上的“a”时,必须更换“a”与“s”。 我尝试通过添加以下行删除最后一个字符: SendKeys.Send(“{BS}”); 但我得到的只是“s”字符被移除,而“a”字符就在那里。 我怎样才能防止这种情况发生?

你能在UWP的C#代码中使用C ++ DLL吗?

我在Visual Studio中编写了一个C ++类库,它只定义了一个调用Python的函数: #pragma once #include extern “C” __declspec(dllexport) void python() { Py_Initialize(); PyRun_SimpleString(“2 + 2″); } 我在同一个C#Blank Universal应用程序的解决方案中创建了另一个项目。 我试图引用我提到的上一个项目生成的DLL: using System; … namespace StartupApp { … sealed partial class App : Application { private const string CPPPythonInterfaceDLL = @”pathtodll”; [DllImport(CPPPythonInterfaceDLL, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] private static extern void python(); public static void […]

如何为名称中带空格的列创建复杂的数据类型?

我有一个存储过程,返回列名称中带有空格和短划线的列。 我不能简单地使用“获取列信息”按钮为该存储过程自动生成复杂类型。 如何处理字段名称中的空格和破折号,因为它们不是C#中字段名称的合法字符?

在ASP.NET 4.5中将值设置为HiddenField

我在ASP.NET 4.5中为HiddenField设置值时遇到了一些问题。 从我所看到的,我已经尝试了以下没有任何运气: 在ASPX中: function SetHiddenField() { var vv = “HELLO WORLD”; document.getElementById(”).value = vv; } 在代码隐藏中: ScriptManager.RegisterStartupScript(this.Page, this.GetType(), “SetHiddenField”, “SetHiddenField();”, true); ScriptManager.RegisterStartupScript(this.Page, this.GetType(), “alert”, “alert(‘” + HiddenField.ClientID + “‘);”, true); 这会在ClientID中警告垃圾。 我尝试过的另一个解决方案如下。 在.ASPX中: function SetHiddenField() { var vv = “HELLO WORLD”; document.getElementById(‘HiddenField’).value = vv; } 这里的一个问题是.ValueOf在IntelliSense中不存在,只有.ValueOf 。 在代码隐藏中: ScriptManager.RegisterStartupScript(this.Page, this.GetType(), “SetHiddenField”, “SetHiddenField();”, true); ScriptManager.RegisterStartupScript(this.Page, […]