pinvoke

why IntPtr.size is 4 on Windows x64?

痞子三分冷 提交于 2020-01-02 00:18:08
问题 I think I should get 8 when I use IntPtr.Size. However I still get 4 on x64 machine with Widnows 7 x64, why? 回答1: check your file CPU architecture, is it x86? It should be CPU any / 64bit 回答2: The 64 bit operating system implements an emulated environment known as WOW64 which emulates the 32 bit Windows environment. You are building your program targeting x86, i.e. 32 bit. That means that your process runs under the emulator as a 32 bit process and of course pointers are 4 bytes wide. If you

How do I access printer specific fonts in .NET?

走远了吗. 提交于 2020-01-01 21:58:32
问题 This question is along the same lines as Retrieving Device Context from .NET print API... I have a Datacard 295 embosser / mag stripe encoder. In order to write to the Mag Stripe or Embosser wheel, you must write your text in a special "pseudo-font", which the printer driver will recognize and handle appropriately. There are multiple fonts, depending on whether you want to write to track 1, track 2, big embosser letters or small. Unfortunately, .NET only directly supports OpenType and

SetForegroundWindow doesn't work with minimized process [duplicate]

只谈情不闲聊 提交于 2020-01-01 19:07:22
问题 This question already has answers here : Bring to forward window when minimized (2 answers) Closed 5 years ago . Couldn't find any good answer on this topic, so maybe someone can help me out. I'm making a small personal program where I want to bring a certain application to the foreground. It already works, but there is one small problem. When the process is minimized my code doesn't work. The process won't get showed on the foreground like it does when it is not minimized. Here is a snippet

SetForegroundWindow doesn't work with minimized process [duplicate]

谁说我不能喝 提交于 2020-01-01 19:07:04
问题 This question already has answers here : Bring to forward window when minimized (2 answers) Closed 5 years ago . Couldn't find any good answer on this topic, so maybe someone can help me out. I'm making a small personal program where I want to bring a certain application to the foreground. It already works, but there is one small problem. When the process is minimized my code doesn't work. The process won't get showed on the foreground like it does when it is not minimized. Here is a snippet

P/Invoke, Pinning, and KeepAlive Best Practices

一世执手 提交于 2020-01-01 13:31:50
问题 At work we have a native C code responsible for reading and writing to a proprietary flat file database. I have a wrapper written in C# that encapsulates the P/Invoke calls into an OO model. The managed wrappers for the P/Invoke calls have grown in complexity considerably since the project was started. Anecdotally the current wrapper is doing fine, however, I'm thinking that I actually need to do more to ensure correct operation. A couple of notes brought up by the answers: Probably don't

DLLImport Int** - How to do this if it can be done

狂风中的少年 提交于 2020-01-01 10:33:36
问题 I am trying to use a third party DLL that wants an int** as one of the parameters to the method. It describes the parameter as the address of the pointer that will point to the memory allocation. Sorry for any confusion. The parameter is two-way I think. The DLL is for talking to an FPGA board and the method is setting up DMA transfer between the host PC and the PCI board. 回答1: Use a by-ref System.IntPtr. [DllImport("thirdparty.dll")] static extern long ThirdPartyFunction(ref IntPtr arg);

DLLImport Int** - How to do this if it can be done

喜欢而已 提交于 2020-01-01 10:33:10
问题 I am trying to use a third party DLL that wants an int** as one of the parameters to the method. It describes the parameter as the address of the pointer that will point to the memory allocation. Sorry for any confusion. The parameter is two-way I think. The DLL is for talking to an FPGA board and the method is setting up DMA transfer between the host PC and the PCI board. 回答1: Use a by-ref System.IntPtr. [DllImport("thirdparty.dll")] static extern long ThirdPartyFunction(ref IntPtr arg);

DLLImport Int** - How to do this if it can be done

喜夏-厌秋 提交于 2020-01-01 10:33:04
问题 I am trying to use a third party DLL that wants an int** as one of the parameters to the method. It describes the parameter as the address of the pointer that will point to the memory allocation. Sorry for any confusion. The parameter is two-way I think. The DLL is for talking to an FPGA board and the method is setting up DMA transfer between the host PC and the PCI board. 回答1: Use a by-ref System.IntPtr. [DllImport("thirdparty.dll")] static extern long ThirdPartyFunction(ref IntPtr arg);

How do I call an unmanaged function that has a char[] as OUT parameter from C#?

送分小仙女□ 提交于 2020-01-01 09:42:21
问题 Say, I've got that prototype of a function that is exposed on a DLL: int CALLBACK worker (char* a_inBuf, int a_InLen, char** a_pOutBuf, int* a_pOutLen, char** a_pErrBuf, int* a_pErrLen) I'm sure that it's ridiculously easy to call that DLL function from my C# code but it doesn't work with this code: [DllImport("mydll.dll")] public static extern int worker( [In, MarshalAs(UnmanagedType.LPArray)] byte[] inBuf, int inputLen, [Out, MarshalAs(UnmanagedType.LPArray)] byte[] outBuf, out int

C#/C++ pInvoke tips

a 夏天 提交于 2020-01-01 06:06:08
问题 Whats the best way to go about modifying a C++ program to be used with pInvoke from C#.NET CF? I have a large C++ codebase which makes extensive use of STL. Namely iterators, container classes, and standard strings. On top of this many lightweight classes are passed around by value. I want to build a C# gui ontop of this codebase for windows mobile touch devices. Is it worth it? I have managed to get some examples working using pInvoke to call C++ code from C#.NET, but writing wrappers for