interop

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 08:03:56
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? [UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate void AnotherMethodDelegate(string s, IntPtr anyParameter); [DllImport("dllname", CallingConvention = CallingConvention

Get the colour of the screen's current colour filter

有些话、适合烂在心里 提交于 2019-12-02 07:02:00
问题 The following code SETS the colour filter of the screen to a specific colour. How can I instead GET the colour of the screen? [DllImport("GDI32.dll")] private unsafe static extern bool SetDeviceGammaRamp(IntPtr hdc, void* ramp); private static IntPtr hdc; public unsafe bool SetLCDbrightness(Color c) { short red = c.R; short green = c.G; short blue = c.B; Graphics gg = Graphics.FromHwnd(IntPtr.Zero); hdc = gg.GetHdc(); short* gArray = stackalloc short[3 * 256]; short* idx = gArray; short

COM->.NET - can't access overloaded method

情到浓时终转凉″ 提交于 2019-12-02 06:57:02
I'm trying to access a .Net library (The Image Resizer) from COM (jscript). I've tried both IDispatch and class interface generation, as well as [ClassInterface( ClassInterfaceType.AutoDual)] on the class in question. There is a method with 3 overloads: Bitmap Build(object, ResizeSettings settings) void Build(object source, object dest, string settings) void Build(object source, object dest, ResizeSettings settings) Calling Build("file",s); //works The following both generate "Wrong number of arguments or invalid property assignment" (JScript runtime error) Build("file","file", s) Build("file"

.NET mshtml: How to pass a BSTR SAFEARRAY?

北慕城南 提交于 2019-12-02 06:20:33
问题 The class mshtml.HTMLDocumentClass in Microsoft.mshtml.dll assembly has a method: public virtual void write(params object[] psarray); Avoiding the real question for a moment, what code would you use to call write() ? Would you use: String html = "<html><body>Hello, world!</body></html>"; mshtml.HTMLDocumentClass doc; ... doc.write(html); or would you use: String html = "<html><body>Hello, world!</body></html>"; mshtml.HTMLDocumentClass doc; ... object[] params = new Object[1]; params[0] =

How do you call a Scala singleton method from Java?

旧城冷巷雨未停 提交于 2019-12-02 06:09:06
I'm trying to inject some Scala code into my existing Java app. (So, being said, I want some more fun). I create a singleton stuff in Scala ScalaPower.scala package org.fun class ScalaPower object ScalaPower{ def showMyPower(time:Int) = { (0 to time-1).mkString(", ") } } Now, inside OldJava.java class OldJava { public void demo(){ System.out.println(?) } } What should I fill in ? so that Java will call the showMyPower method? I tried both org.fun.ScalaPower.showMyPower(10) and org.fun.ScalaPower.getInstance().showMyPower(10) but none work. (Decompile the class file using Jad show me nothing

Why isn't my IE MIME filter being created or called?

百般思念 提交于 2019-12-02 05:55:20
问题 I'm trying to create a MIME filter to do some custom processing of resources received with web pages before passing them to the web browser control in our Windows application. The application is written in C#, and I'd like to write the MIME filter in managed code as well, if possible. I'm having trouble with it though: my filter object doesn't seem to be getting called at all. Here's my code. Sorry it's so long, but I think I might be defining something incorrectly in the COM interfaces, so I

Powerpoint issue when quitting

放肆的年华 提交于 2019-12-02 05:19:28
I have some c# code which opens a Powerpoint slide, refreshes the graphs, and then quits. This works fine, unless the user already has a Powerpoint slide open, in which case it will close down their existing session (losing any changes they may have made!) once the exe has run. So, the issue is if you have PPT’s open in the background, run my EXE which runs the below code (opening up a template, refreshing some graphs, saving and closing), upon application exit it disposes of the variable ppApp which seems to close down every running PPT. This is even the case if I omit ppApp.Quit();

Call to external DLL from C# with integer pointer

前提是你 提交于 2019-12-02 04:51:00
问题 I'm trying to call an external .dll function from c#. The doc for the dll defines the function: int funcName(int *retVal) I've tried various configurations and always the unbalanced stack error from p/invoke; My c# code currently looks like this: [DLLImport("dllName"); unsafe static extern int funcName(ref IntPtr retVal); unsafe IntPtr retNum; int status = funcName(ref retNum); Any ideas are appreciated! 回答1: Your p/invoke declaration has the wrong parameter type. ref Int32 is the correct

Detect Outlook installed and load dynamically INterop.Outlook

自闭症网瘾萝莉.ら 提交于 2019-12-02 03:20:30
问题 I have a Windows Forms application in VS2010. It has a reference to Interop.Outlook (2003). Then, I have reinstalled Windows XP and VS2010, but not install Outlook. Now, the project not compiles. I think this, my application will not work if Outlook not installed in machine that my program executes on. I need to know if I detect Outlook installed, and load dynamically Interop.Outlook.dll (for using the Outlook PIA or Embedded Interop types in .NET 4). If the machine has Outlook (2003, 2007,

Determine if a Word cell is merged

家住魔仙堡 提交于 2019-12-02 03:04:49
问题 I need to programmatically add and remove rows from a Word 2010 table. Unfortunately the header of the table contains merged cells, both horizontally and vertically merged. That causes an error when using the Row.Add and Row.Delete methods. I have tested and discovered that I can programmically remove the merged cells (Cell.Split) and then do the .Add and .Delete methods and then restore the merged cells. The problem I'm having is identifying which cells that are merged. ---------------------