interop

C DLL doesn't load in C#

好久不见. 提交于 2019-12-10 08:53:53
问题 I have a simple C DLL (not COM). I have also a C# 2.0 application that runs it (dllimport). The dll is placed in the exe of the application. I know that the dll is ok and also that my application that calls it success reading it, but when I move them to another computer it says that it can load the dll. The error : "Unable to load the dll name.dll . This application has failed to start because the application configuration is incorrect." I used visual studio 2005 to create the dll. The targer

Sync system time to domain controller using .NET code

佐手、 提交于 2019-12-10 04:22:54
问题 I have time based tests to run that require changing the system time multiple times during the test. I want to be able to resync the time to the domain controller time at the end of the test. I there any way to do that using .NET code (C#). I am changing the time using the p-invoke function found in: Set time programmatically using C# Thanks 回答1: One easy way would be to launch a process and run the NET TIME command (copied from http://blogs.msdn.com/sanket/archive/2006/11/02/synchronizing

C# C++ Interop callback

风格不统一 提交于 2019-12-10 03:12:38
问题 I have recently been tinkering around with C# to C++ interop, in particularly setting up a callback function which is called from the C++ DLL. namespace TomCSharpDLLImport { class Program { public delegate void TomDelegate(int a, int b); [DllImport("TomDllNative.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void GetData(); [DllImport("TomDllNative.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void SetCallback(TomDelegate aCallback); static

How do I call this c function in c# (unmarshalling return struct)?

会有一股神秘感。 提交于 2019-12-10 02:58:44
问题 I want to use c# interop to call a function from a dll written in c. I have the header files. Take a look at this: enum CTMBeginTransactionError { CTM_BEGIN_TRX_SUCCESS = 0, CTM_BEGIN_TRX_ERROR_ALREADY_IN_PROGRESS, CTM_BEGIN_TRX_ERROR_NOT_CONNECTED }; #pragma pack(push) #pragma pack(1) struct CTMBeginTransactionResult { char * szTransactionID; enum CTMBeginTransactionError error; }; struct CTMBeginTransactionResult ctm_begin_customer_transaction(const char * szTransactionID); How do I call

How to call a C++ function with a struct pointer parameter from C#?

前提是你 提交于 2019-12-10 02:31:25
问题 Okay one more function that it's not yet working. I am basically calling some C++ functions from C# by using P/Invoke. The problematic function does query a show laser device for some device related information, such as minimal and maximal scan rates and maximal points per second. The problematic function is: int GetDeviceInfo(DWORD deviceIndex, DeviceInfo* pDeviceInfo); Here's the C++ header file that I was given. That's a link to the very brief C++ SDK description. I don't have the sources

Where can I find Microsoft.Office.Interop.Word.dll (2010)?

本小妞迷上赌 提交于 2019-12-10 02:06:29
问题 I got the sources of a .NET project that I am trying to compile. Although, the project uses the reference (namespace) Microsoft.Office.Interop.Word from Office 2010 that I cannot find anywhere. I was able to download the file microsoft.office.interop.word.dll but apparently the one from Office 2007 since it still doesn't compile because the project uses the function Document.SaveAs2 (which is from Office 2010 library). I have Office 2007 on my computer and Visual Studio 2012 Express for

System.Runtime.InteropServices.ComTypes.IStream to System.IO.Stream

痴心易碎 提交于 2019-12-09 22:08:52
问题 In a .NET 3.0 project, I need to make some calls via P/Invoke (specifically to the PrintTicket Provider functions like PTConvertPrintTicketToDevMode() ). The framework has a managed definition of the COM IStream interface: System.Runtime.InteropServices.ComTypes.IStream I need this as System.IO.Stream so that I can easily use .NET classes (like XmlDocument) with the output of these imported functions. But I can't see a less painful way of converting this back and forth to System.IO.Stream

How can I add a VC++ DLL as a reference in my C# Visual Studio project?

半城伤御伤魂 提交于 2019-12-09 18:34:06
问题 I want to add a VC++ DLL reference into my C# Visual Studio project. But when I try to add it I see, "It is not a valid assembly or COM component". Please suggest how I can use the VC++ DLL as a reference in a C# project. 回答1: There are two options for using a C++ DLL from C#: either COM interop, or P/Invoke. COM Interop involves creating a COM object in your C++ DLL, and then adding it as a reference. You can use the COM object like a C# object (for the most part) at this point. P/Invoke

How to release COM objects in Silverlight 4

纵饮孤独 提交于 2019-12-09 18:08:10
问题 When using COM Interop with Office (usually Excel), I always carefully ensure I call Marshal.ReleaseComObject on every reference, to avoid the problem where Excel doesn't quit as described in this KB article. How can I ensure Excel quits when I use Interop from an OOB Silverlight application (with AutomationFactory.CreateObject )? Silverlight doesn't have a Marshal.ReleaseComObject method and even calling GC.Collect and GC.WaitForPendingFinalizers doesn't help. Surely Microsoft hasn't added

C# sizeof(enum) alternative? (to workaround resharper false error)?

扶醉桌前 提交于 2019-12-09 17:46:40
问题 In C# I've got some "safe" API code related to UAC elevation. It involves getting the size of an enum (as follows) int myEnumSize = sizeof (MyEnum); The code itself is valid, compiles, works correctly etc. But Resharper falsely flags it as a an error ("Cannot use unsafe construct in safe context") within the solution. (Starting with version 2.0 of C#, applying sizeof to built-in types no longer requires that unsafe mode be used.) I love Resharper, and I love the solution analysis, but with