Tag: c ++

如何从Windows 7服务启动会话1中的进程

我在Windows 7中运行了一项服务。在Windows 7中,所有服务都在会话0中运行。从该服务我想创建一个交互式用户会话(在会话0以外的会话中)并在该会话中启动一个应用程序。 我的问题是,当我调用LogonUser启动交互式用户会话,然后使用CreateProcessAsUser启动应用程序时,应用程序最终在会话0中运行。 我的所有代码都是C#。 这是相关的代码: [DllImport(“advapi32.dll”, SetLastError=true)] static extern bool LogonUser( string principal, string authority, string password, UInt32 logonType, UInt32 logonProvider, out IntPtr token); [DllImport(“advapi32.dll”, SetLastError=true)] static extern bool CreateProcessAsUser( IntPtr hToken, string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles, int dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, ref STARTUPINFO lpStartupInfo, ref PROCESS_INFORMATION lpProcessInformation); […]

如何在C ++项目中使用C#代码

我在C#中有一些代码,我想在其他项目中使用(用C ++编写)。 根据我的研究,我需要创建一个.lib,但MSVS只创建.dll(我认为..)。 我认为可以通过在C ++上使用LoadLibrary()来使用.dll,但似乎不是很友好。 1 – 我可以在MSVS中创建.lib吗? 如果没有,我该如何创建它。 2 – 集成代码的最佳方法是什么? 通过.lib或使用.dll + LoadLibrary()?

拦截Ninject实例激活?

我试图在WP7和Ninject上使用Caliburn Micro。 一切都很直接。 但是,一旦实例被Ninject激活,我就会被困在如何解决事件。 这是Caliburn Micro的SimpleContainer中的ActivateInstance方法,它是手机CM附带的IoC容器。 protected virtual object ActivateInstance(Type type, object[] args) { var instance = args.Length > 0 ? Activator.CreateInstance(type, args) : Activator.CreateInstance(type); Activated(instance); return instance; } 我在Ninject中注册我的类型,当它们被激活时,我需要激活Activated事件。 我看了拦截可能是要走的路,但我不认为动态代理和林福将在手机上工作。 为了澄清更多,我没有使用SimpleContainer,上面是显示SimpleContainer在激活实例时所做的事情。 我有一个NinjectBootstrapper和一个实现IPhoneContainer的NinjectContainer。 我无法弄清楚如何实现event Action Activated; 与Ninject。 更新: .OnActivation()看起来像票。 Kernel.Bind().To().InSingletonScope().OnActivation();

如何在Windows Phone 8.1 Universal App中获取街道地址的地理位置?

我的Windows Phone用户将在文本字段中输入街道地址。 我需要获取该地址字符串的地理位置,以便稍后我可以计算该地理位置的距离和电话的当前地址。 所以,我的问题是: 如何在Windows Phone 8.1 Universal App中获取街道地址的地理位置? 我在这个stackoverflow答案中找到了一个解决方案,但是,它适用于旧的Silverlight应用程序,而不是我目前正在使用的新的Universal Store应用程序API。

以编程方式将焦点设置为Windows Phone中的TextBox

在Windows Phone应用程序中,我有一个TextBox和一个Button 。 用户将一些文本写入TextBox并点击Button,TextBox中的文本将添加到列表中。 点击按钮后,TextBox失去焦点。 我想要做的是在点击按钮后将焦点设置回TextBox,这样用户就可以继续编写另一个文本,而无需点击TextBox。 我尝试在Button处理程序中调用TextBox的Focus()方法,但这不起作用。 是否还有另一种方法可以做到这一点?

P /调用函数传递StringBuilder

在C#文件中我有一个 class Archiver { [DllImport(“Archiver.dll”)] public static extern void archive(string data, StringBuilder response); } 字符串数据是一个输入,StringBuilder响应是函数写入的东西 归档函数原型(用C编写)如下所示: void archive(char * dataChr, char * outChr); 它在dataChr中接收一个字符串,然后执行a strcpy(outChr,”some big text”); 从C#我称之为: string message = “some text here”; StringBuilder response = new StringBuilder(10000); Archiver.archive(message,response); 这是有效的,但问题是,你可能会看到我给StringBuilder大小一个值,但是归档函数可能会返回一个(方式)更大的文本,而不是我给我的StringBuilder的大小。 有任何解决这个问题的方法吗?

我可以在没有Visual Studio的情况下编译DLL吗?

我的目的是使用C ++库 ,使用SWIG ( alt。链接 )将其包装为C#,并将C ++和C#组件编译为Unity 5的DLL。(C#DLL为Unity提供了与C ++ DLL的接口。) 据我所知,编译C ++和C#DLL总是需要Visual Studio(或VS之类的msbuild工具)。 但是,我目前正在努力安装VS,这让我质疑这个假设。 是否还有其他选项可以在Windows上编译Unity-ready DLL? (即使我安装了VS,我仍然很想知道。)

ServiceContractGenerator CodeDomProvider编译错误

我正在尝试使用ServiceCodeGenerator和CodeDomProvider来动态创建服务引用。 使用CodeDomProvider编译代码时,会抛出以下错误。 它看起来只适用于特定的Web服务。 我能够编译其他Web服务,但是这个会抛出下面的编译错误。 知道如何编辑源代码或忽略错误吗? CS0579:复制’System.CodeDom.Compiler.GeneratedCodeAttribute’属性99 CS0579:复制’System.Diagnostics.DebuggerStepThroughAttribute’属性101 CS0579:复制’System.CodeDom.Compiler.GeneratedCodeAttribute’属性191 CS0579:复制’System.Diagnostics.DebuggerStepThroughAttribute’属性193 代码如下: Uri address = new Uri(url + “?wsdl”); MetadataExchangeClientMode mexMode = MetadataExchangeClientMode.HttpGet; MetadataExchangeClient metadataExchangeClient = new MetadataExchangeClient(address, mexMode); metadataExchangeClient.ResolveMetadataReferences = true; //Trust all certificates System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true); ICredentials networkCredential = new NetworkCredential(“username”, “password”, “domain”); metadataExchangeClient.HttpCredentials = networkCredential; MetadataSet metadataSet = metadataExchangeClient.GetMetadata(); […]

使用带有Delegate.CreateDelegate的值类型的C#

使用Jon Skeet的文章使reflection飞行和探索代表作为指导,我试图使用Delegate.CreateDelegate方法将属性复制为委托。 这是一个示例类: public class PropertyGetter { public int Prop1 {get;set;} public string Prop2 {get;set;} public object GetPropValue(string propertyName) { var property = GetType().GetProperty(propertyName).GetGetMethod(); propertyDelegate = (Func)Delegate.CreateDelegate(typeof(Func), this, property); return propertyDelegate(); } } 我遇到的问题是当我调用GetPropValue并传入”Prop1″作为参数时,我在调用Delegate.CreateDelegate时收到ArgumentException ,并显示消息”Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type.” […]

每个查询的新sql连接?

我正在编写一个与本地sql server通信的服务器应用程序。 每个客户端都需要读取或写入数据库。 拥有一个可以在单个sql连接上排队并执行sql命令的线程安全类会更好吗? 或者我应该为每个命令打开一个新连接? 性能是否重要?