interop

Better way to cast object to int

自闭症网瘾萝莉.ら 提交于 2019-11-27 06:01:57
This is probably trivial, but I can't think of a better way to do it. I have a COM object that returns a variant which becomes an object in C#. The only way I can get this into an int is int test = int.Parse(string.Format("{0}", myobject)) Is there a cleaner way to do this? Thanks Joel Coehoorn You have several options: (int) — Cast operator. Works if the object already is an integer at some level in the inheritance hierarchy or if there is an implicit conversion defined. int.Parse()/int.TryParse() — For converting from a string of unknown format. int.ParseExact()/int.TryParseExact() — For

Should cookie values be URL encoded?

流过昼夜 提交于 2019-11-27 05:59:16
问题 When setting cookies, PHP url-encodes the cookie value (at least when not using setrawcookie ) and it url-decodes the cookie value before making it available to the application in $_COOKIE . Is this an accepted standard? If I set a raw cookie value of a%3Db , would I get back a=b in most web programming languages (through their respective cookie-reading mechanisms)? 回答1: Yes. While it's not required per the spec, the following is mentioned in RFC6265 (emphasis is in the original document, not

Making a C# kill event for a vb6 app?

↘锁芯ラ 提交于 2019-11-27 05:41:48
I have a VB6 app that processes for a very, very long time. Killing it directly is not feasible, so I would like to set some sort of flag in the VB6 app. If in my C# app I decide to shut it down, I would like to toggle this flag to let the VB6 app know that a shutdown has been requested. Now, I also need something that is named because there will be several of the VB6 apps spun up as activex exes. Does anyone have any idea how to implement something like this? The workflow follows below C# app - Spin up mulitple VB6 activex.exes in separate threads, Initialize the app with something

How well does WPF blend with XNA in real life?

自作多情 提交于 2019-11-27 05:26:13
问题 I understand that there are several ways to blend XNA and WPF within the same application. I find it enticing to use WPF for all GUI and HUD stuff in my XNA games. Does anyone have any practical experience on how well this approach works in real life using .NET 3.5 SP1 ? Any pitfalls (such as the "airspace problem")? Any hint on what appoach works best? 回答1: There is an addition in 3.5 SP1 that allows better interaction between DirectX and WPF (D3DImage), and one way to get to that is through

Set System Time Zone from .NET

天涯浪子 提交于 2019-11-27 05:03:02
Does anyone have some code that will take a TimeZoneInfo field from .NET and execute the interop code to set the system time zone via SetTimeZoneInformation? I realize that it's basically mapping the TimeZoneInfo members to the struct members, but it does not appear obvious to me how the fields will map exactly or what I should care about beyond the bias. BigBlackDog I don't know if this is what you are looking for, but there is some information on how to use the Win32 functions to get and set the timezone information at http://www.pinvoke.net/default.aspx/kernel32/GetTimeZoneInformation.html

p/invoke C function that returns pointer to a struct

二次信任 提交于 2019-11-27 04:43:33
问题 How do I declare in C# a C function that returns a pointer to a structure? I believe following is one way to do that, followed by Marshal.PtrToStructure to get actual structure value. // C-function SimpleStruct * Function(void); // C# import [DllImport("MyDll.dll")] public static extern IntPtr Function(); Am I correct about that? Are there other ways to accomplish the same? (It would be OK to get struct back by value) 回答1: Since the function returns a pointer (hopefully not a locally

Python for .NET “unable to find assembly” error

瘦欲@ 提交于 2019-11-27 04:41:42
问题 I'm using CPython and I have a C# dll. I'm trying to use Python for .NET to make them talk. I can't use IronPython because I need to integrate this into an existing CPython system. I'm completely new to Python for .NET, and I actually have very little experience with Python and no experience with C#. So please forgive me if my question seems very basic. I'm using Python 2.7.3, and I downloaded pythonnet-2.0-alpha2-clr2.0_131_py27_UCS2 and unzipped it into a folder named pyfornet_test, which

Marshalling a big-endian byte collection into a struct in order to pull out values

泄露秘密 提交于 2019-11-27 04:40:46
There is an insightful question about reading a C/C++ data structure in C# from a byte array , but I cannot get the code to work for my collection of big-endian (network byte order) bytes. (EDIT: Note that my real struct has more than just one field.) Is there a way to marshal the bytes into a big-endian version of the structure and then pull out the values in the endianness of the framework (that of the host, which is usually little-endian)? (Note, reversing the array of bytes will not work - each value's bytes must be reversed, which does not give you the same collection as reversing all of

How do you call a Scala singleton method from Java?

主宰稳场 提交于 2019-11-27 04:34:07
问题 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

WinWord.exe won't quit after calling Word.Documents.Add - Word .NET Interop

我是研究僧i 提交于 2019-11-27 04:24:15
I'm running into the classic scenario where, when creating Word COM objects in .NET (via the Microsoft.Office.Interop.Word assembly), the WinWord process won't exit even though I'm properly closing and releasing the objects . I've narrowed it down to the use of the Word.Documents.Add() method. I can work with Word in other ways without a problem (opening documents, modifying contents, etc) and WinWord.exe quits when I tell it to. It's once I use the Add() method (and only when adding a template ) that the process is left running. Here is a simple example which reproduces the problem: Dim word