interop

Interop COM(-isch) interface marshaling results in AccessViotlationException on simple call

断了今生、忘了曾经 提交于 2019-12-02 13:59:32
问题 I am trying to write a managed interop library for a native C++ plugin standard. This native C++ library uses a COM-compatible interface design. It does NOT however, do any of the class registration stuff. As with COM, all interfaces derive from IUnknown (called FUnknown but same 3 methods anyway). I have written a simple C++ console app that loads my managed test plugin and retrieves the initial (root) interface (an object factory pattern - much like com) through an exported method. I use a

How to search for a specific font in a Word document with iterop

我怕爱的太早我们不能终老 提交于 2019-12-02 13:48:22
问题 I use something like this: doc.Content.Find.Font.Name = "Times New Roman"; but when I step through the code the Name property doesn't change. thanks. I'm working with VS2010 and MS Word 2007 and I want to find and replace all "Times New Roman" fonts with "Arial". Here's what happens: Word.Application wordApp = new Word.Application(); Word.Documents docs = wordApp.Documents; doc = docs.Open(fileName, Visible: false); doc.Content.Find.ClearFormatting(); doc.Content.Find.Replacement

How can I write a signature on C# for a wrapped C++ method having a pointer to a function it its arguments?

送分小仙女□ 提交于 2019-12-02 12:56:27
问题 I'm writing a wrapper for a dll. The dll has a method whose signature resembles the following: unsigned long aMethod(void *anyParameter, void (*anotherMethod)(const char *, void *)) I've searching at google for a tutorial to give me insight on how to write the signature on C# so the framework can do the marshalling process. How can it be written? Do you know about any tutorial, book or documentation on this subject? 回答1: [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate void

Loading .net 3.5 wpf-forms in a .net 2.0 application

对着背影说爱祢 提交于 2019-12-02 11:07:11
I'm trying to load and host a WPF control in a .net 2.0 windows forms application. The WPF control should only be loaded if .net 3.5 is installed. I found a link to Hosting WPF Content in an MFC Application and that is about what I'm trying to do but my C++ knowledge isnt sufficient to be able to 'translate' it to .net. Anyway, here is another link: Hosting WPF Content in a Java Application that doest the same again but I dont know where to start writing that code in .net. To host a WPF control in a Win32 form you need to use the ElementHost control. Drop this control on the Window and set it

Connect to Outlook calendar from C# using Interop

China☆狼群 提交于 2019-12-02 10:25:28
Ok I am trying to connect to an Outlook calendar from C# using the following code: using Outlook = Microsoft.Office.Interop.Outlook; Outlook.Application msOutlook = new Outlook.Application(); Outlook.NameSpace ns = msOutlook.GetNamespace("MAPI"); Outlook.MAPIFolder folder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar); foreach (Outlook.MAPIFolder subfolder in folder.Folders) { MessageBox.Show(subfolder.Name); } However, despite having two Calendars, the piece of code above doesn't see any! I'm thinking I may have more luck with the below code: Outlook.MAPIFolder folder = ns

Why cudaGLSetGLDevice failed, even though it's called in the first line of main function

不羁的心 提交于 2019-12-02 10:01:30
I want to use interoperability between OpenGL and CUDA. I know, as some tutorials said, the first step is to choose device. However, when I called the cudaGLSetGLDevice(0) in the first line of the main function, the program exited with the information "cudaSafeCall() Runtime API error 36: cannot set while device is active in this process." Actually, even though I use cudaDeviceProp and cudaChooseDevice before calling cudaGLSetDevice, the error still exists. Believe me, my computer just has one GPU, 9800GT. And I do know that the calling of cudaGLSetGLDevice should be prior to any other CUDA

Passing a struct with a byte array inside to a interop-ed method

限于喜欢 提交于 2019-12-02 09:59:30
I have a situation where I have to pass a struct to a C method (declared as extern in my C# file). This struct however is quite complicated. I already used successfully the approach with AllocHGlobal, but I would like to understand if is possible to make it works in this way, by only passing a reference to the struct. [StructLayout(LayoutKind.Sequential)] struct lgLcdBitmapHeader { public Formats Format; } [StructLayout(LayoutKind.Explicit)] struct lgLcdBitmap { [FieldOffset(0)] public lgLcdBitmapHeader hdr; [FieldOffset(0)] public lgLcdBitmap160x43x1 bmp_mono; [FieldOffset(0)] public

Register C# COM Object without having a real file for RegAsm

假如想象 提交于 2019-12-02 09:46:18
I have a wierd application loading mechanism. I have a boostrapping exe file with all the other DLLs and the application itself inside it's resources. These files (assemblies) are extracted from resources and loaded ond emand because i'm attaching to the Assemblyresolve event of the current AppDomain. [STAThread] static void Main() { // if the command line contains extract then extract the dlls, next run will resolve assemblies from disk bool saveDllsToDisk = new List<string>(Environment.GetCommandLineArgs()).Contains("extract"); // if the command line contains bin then use the bin folder

Attempting to convert C++ into C# with interop

南楼画角 提交于 2019-12-02 08:40:24
I've got a program that calls to EGL in C++. I want to make the same call in C#, but there doesn't seem to be an equivalent concept in C#. I'm getting a read/write access denied error when the execution context enters the C++ EGL code. This is the code in the C++ program that I'm trying to convert to C#: PropertySet^ surfaceCreationProperties = ref new PropertySet(); surfaceCreationProperties->Insert(ref new String(EGLNativeWindowTypeProperty), somethingOtherThanAWindow); mEglSurface = eglCreateWindowSurface(mEglDisplay, config, reinterpret_cast<IInspectable*>(surfaceCreationProperties),

How to check if .net interoperability for excel is installed

折月煮酒 提交于 2019-12-02 08:04:11
I am using .net Primary Interoperability Assembly for Excel in my code. But, the application can be run on machine which doesn't have .net PIA for Excel installed. I want to give an error message if it is not installed Even though I am checking in GAC, to see if PIA is installed and only if it is present I am using Microsoft.Office.Interop.Excel related code. I am getting an error. My problem is - I am getting error which is - Unhandled Exception - can't find could not load file or assembly Microsoft.Office.Interop.Excel Any solution? Thanks in advance! I've used this Building block to load