Tag: c ++

在Windows Universal中将文件写入外部闪存驱动器

我在Raspberry PI上使用Windows IoT编写应用程序。 我想将数据写入连接到其中一个USB端口的外部闪存驱动器。 我已经找到了如何在PI中写入SD卡的示例,但最终产品中无法访问SD卡。 我可以获取闪存驱动器的根文件夹名称,但是当我尝试向其写入文件时,我收到了拒绝访问的消息。 如果我切换到SD卡一切正常。 有人能指出一个允许访问外部闪存驱动器的示例吗?

IsLittleEndian字段报告错误,但它一定是Little-Endian?

我在英特尔计算机(Win7 64位)上运行,根据我读到的英特尔正在使用Little-Endian。 我在C#中尝试使用以下代码: byte[] b2 = new byte[] { 0, 1 }; short b2short = BitConverter.ToInt16(b2, 0); 和Little-Endian预期的b2short == 256。 然后我在.NET中读到,BitConverter.IsLittleEndian应该反映系统正在使用的endian,当我在Visual Studio中检查变量时,它报告为false ,即它不是Little-Endian。 这与64位操作系统有什么关系吗? 有任何想法吗? 编辑:我的同事,坐在我对面,做了相同的测试(Win Vista 32位),得到了相同的结果 编辑2:这真的很奇怪。 每当我运行代码,并在BitConverter完成它之后中断,IsLittleEndian == false。 但是,如果我添加Console.WriteLine(BitConverter.IsLittleEndian)行; 之后它是真的: byte[] b2 = new byte[] { 0, 1 }; short b2short = BitConverter.ToInt16(b2, 0); Console.WriteLine(BitConverter.IsLittleEndian); // Now the IsLittleEndian is true […]

如何使用FileSavePicker保存现有的StorageFile?

我正在尝试将现有文件保存到另一个地方。 这是某种副本,但我想允许用FileSavePicker为用户选择新目的地。 这是我的代码: StorageFile currentImage = await StorageFile.GetFileFromPathAsync(item.UniqueId); var savePicker = new FileSavePicker(); savePicker.FileTypeChoices.Add(“JPEG-Image”,new List() { “.jpg”}); savePicker.FileTypeChoices.Add(“PNG-Image”, new List() { “.png” }); savePicker.SuggestedSaveFile = currentImage; savePicker.SuggestedFileName = currentImage.Name; var file = await savePicker.PickSaveFileAsync(); 之后,将创建文件,但它为空(0 KB)。 如何正确保存文件?

c#中的Google协议缓冲区

我们正在考虑使用Google的Protocol Buffers来处理c ++应用程序和ac#应用程序之间的序列化。 我的问题是,我为c#找到了几个不同的修改。 两者看起来都不错,但是,有没有人知道两者之间有什么不同(如果有的话) protobuf网 jskeet / dotnet-protobufs

C#中的PInvoke DLL

我想将结构传递给C函数,我编写以下代码。 当我运行它时,第一个函数Foo1正在工作,然后函数Foo获得exception。 你能帮我理解问题是什么吗?… C代码: typedef struct { int Size; //char *Array; }TTest; __declspec(dllexport) void Foo(void *Test); __declspec(dllexport) int Foo1(); void Foo(void *Test) { TTest *X = (TTest *)Test; int i = X->Size; /*for(int i=0;iSize;Test++) { Test->Array[i] = 127; }*/ } int Foo1() { return 10; } C#代码: using System; using System.Runtime.InteropServices; using System.Collections.Generic; using System.Linq; […]

C ++回调将文本发送回C#

我是C ++的新手。 我被告知使用C ++的“回调”是最好的解决方案。 这是我的情况。 我有一个用C ++编写的DLL 这个DLL有一个方法来启动通过C#代码运行的服务(这很好) 当DLL中的服务运行时,我希望DLL将文本传回C#代码,这只是进度代码,例如“第一阶段开始”和“第一阶段完成” 我环顾四周,并被告知实现这一点的最好方法是使用回调,我真的不知道如何实现这一点。 有没有人有任何建议或文章我可以看看? 请包含C ++,因为我没有C ++经验。 干杯

流畅的NHibernate强制在外键引用上不可为空

刚刚尝试了一些流畅的NHibernate AutoMap惯例,并遇到了一些我无法弄清楚的事情。 我假设我只是没有找到正确的位置…基本上尝试在一对多关系的“多”方面强制执行NOT-NULL。 看来,使用自动化,它总是使父属性Id在数据库中可以为空。 我在StackOverFlow上做了一些搜索并发现了类似的问题,但是没有任何与AutoMapping和Conventions相关的内容(除非我错过了)。 快速举例…… public class Group // One Group { public Group() { this.Jobs = new List(); } public virtual Guid Id { get; set; } public virtual string Name { get; set; } public virtual IList Jobs { get; protected set; } } public class Job // Has many Jobs { […]

将数组从C#COM对象传递给JavaScript?

与此类似如何将一个字符串数组从ActiveX对象返回到JScript但在C#中。 我有一个COM控件,将一个字符串数组传递给javascript。 似乎javascript无法理解它是什么我传回来并且javascript中的数组总是未定义的。 使用Javascript: try { keystore.openKeyStore(“MY”, true, false); var fNames = new Array(); fNames = keystore.getAllFriendlyNames(); document.getElementById(‘par’).innerHTML = fNames[0]; } catch(err) { document.getElementById(‘err’).innerHTML = err.description; } 这为fNames[0];输出’undefined’ fNames[0]; C#: public object[] getAllFriendlyNames() { if (!keystoreInitialized) throw new Exception(“Key store has not been initialized”); X509Certificate2Collection allCerts = certificateStore.Certificates; int storeSize = allCerts.Count; if (storeSize == […]

如何使用AutoMapper避免循环引用?

我有以下模型(和相应的DTO): public class Link { public int Id {get; set;} public int FirstLinkId {get; set;} public int SecondLinkId {get; set;} public virtual Link FirstLink {get; set;} public virtual Link SecondLInk {get; set;} } public class OtherObject { public int Id {get; set;} public int LinkId {get; set;} public string Name {get; set;} public virtual Link […]

c ++从hbitmap获取原始像素数据

我是一个相当新的使用p / invoke调用,我想知道是否有人可以指导我如何从hbitmap检索原始像素数据(unsigned char *)。 这是我的情景: 我在C#端加载一个.NET Bitmap对象,并将它的IntPtr发送到我的非托管c ++方法。 一旦我在C ++端收到hbitmap ptr,我想访问Bitmaps的像素数据。 我已经创建了一个接受unsigned char *的方法,它表示来自c#的原始像素数据但是我发现从c#中提取byte []相当慢。 这就是为什么我想发送Bitmap ptr而不是将Bitmap转换为byte []并将其发送到我的C ++方法。 用于获取Bitmap IntPtr的C#代码 Bitmap srcBitmap = new Bitmap(m_testImage); IntPtr hbitmap = srcBitmap.GetHbitmap(); 用于导入c ++方法的C#代码 [SuppressUnmanagedCodeSecurityAttribute()] [DllImport(“MyDll.dll”, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)] public static extern int ResizeImage(IntPtr srcImg); 将接收Hbitmap处理程序的C ++方法 int Resize::ResizeImage(unsigned char* srcImg){ //access srcImgs […]