pinvoke

Returning strings from Windows C functions

好久不见. 提交于 2019-12-23 01:36:08
问题 I am a complete novice at pure Windows API-level functions in C and C++ and have been experimenting recently with .NET interoperability. I have built a simple library which has successfully returned numeric values (int/float, etc.) to a .NET caller, but I am not having as much luck with strings. I have tried a variety of different data types, but none appear to work: LPSTR, LPCSTR, LPCTSTR, and LPCWSTR. Admittedly, I haven't tried char*. Also, once a method is set up to return a string, does

waveout sometimes memory issue

情到浓时终转凉″ 提交于 2019-12-23 01:35:24
问题 This code works to output a piano tone for 2 seconds using winmm.dll via platform invocation services, it seems to work fine on XP but waveoutopen fails in windows 7 rc updated based on feedback from John Knoeller Imports System.Runtime.InteropServices Public Class AudioStream <StructLayout(LayoutKind.Sequential)> _ Private Structure WAVEHDR Public lpData As Integer Public dwBufferLength As Integer Public dwBytesRecorded As Integer Public dwUser As Integer Public dwFlags As Integer Public

Can't get SendInput() to work

 ̄綄美尐妖づ 提交于 2019-12-23 01:11:08
问题 I'm kind of desperate. I have been trying for hours now, but I just can't get SendInput() to work. To be honest, I can't even get it to be recognized. It always says: Error 1 The type or namespace name 'INPUT' could not be found (are you missing a using directive or an assembly reference?) And I just can't find out which libraries to use. There's almost zero information about what to include for this, all I can find is for C++ or is simply not existing when I try using it. Please Help! I'm

What is the difference between structures containing bool vs uint when using PInvoke?

半城伤御伤魂 提交于 2019-12-22 22:53:28
问题 Ok, I'm now very confused. After my last question had several people comment about changing bool to uint I verified they are the same size by: Console.WriteLine("sizeof bool = {0}", Marshal.SizeOf(typeof(bool))); Console.WriteLine("sizeof uint = {0}", Marshal.SizeOf(typeof(uint))); Which of course prints: sizeof bool = 4 sizeof uint = 4 That said, I then broke down and gave their suggestions a try anyway... Changing a single bool inside a structure to a uint. What I can't figure out for the

Using p/invoke and win-api to monitor audio line-in (C#)

让人想犯罪 __ 提交于 2019-12-22 18:19:13
问题 In the last few days I was trying to write small program to monitor the audio line-in using win-api (winmm.dll). I can pinvoke api functions such as waveInOpen but I can't figure out how to use these functions to achieve my target. the question is - can someone can briefly tell me how can I get the data from the audio line in using these API (C#). 回答1: Well I finally found what I was looking for here. http://www.codeguru.com/forum/archive/index.php/t-264694.html Although this is a C code

How can I capture all application/window messages from start of process? [closed]

蓝咒 提交于 2019-12-22 17:42:20
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 6 years ago . I am trying to figure out exactly how I can capture all window messages of a process/window, from the time it was launched in c#. The process would not be my own so I would need to use some kind of hook. My goal is to start capturing all messages in real time from before the

How can I capture all application/window messages from start of process? [closed]

随声附和 提交于 2019-12-22 17:42:12
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 6 years ago . I am trying to figure out exactly how I can capture all window messages of a process/window, from the time it was launched in c#. The process would not be my own so I would need to use some kind of hook. My goal is to start capturing all messages in real time from before the

C++ unmanaged DLL in c#

99封情书 提交于 2019-12-22 17:38:32
问题 I've been asked to intergrate webcam ZoneTrigger in my project. The SDK provided in the site is C++ also the sample. I've been able to get few functions to work. the place i've been stuck is a function where char* is a parameter passed. I did a lot of digging and have come to know that MarshalAs has to be used... the function i'd like to import from c++ code //header file struct ZT_TRIG_STRUCT { int aSize; //STRUCT size int CameraIndex; int SpotIndex; int SpotType; char SpotName[32]; DWORD

P/Invoke from C to C# without knowing size of array

眉间皱痕 提交于 2019-12-22 17:37:26
问题 Right know in my code I have structure declared as like this, with fixed this 16, know at compile time. struct CONSOLE_SCREEN_BUFFER_INFOEX { [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public int ColorTable[]; } but what I need is to be able to have this structure: struct CONSOLE_SCREEN_BUFFER_INFOEX { int arraySize; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 0)] public int ColorTable[]; } get the arraySize from C function response, initialize ColorTable array with proper

Identifying if a user is in the local administrators group

穿精又带淫゛_ 提交于 2019-12-22 12:43:30
问题 My Problem I'm using PInvoked Windows API functions to verify if a user is part of the local administrators group. I'm utilizing GetCurrentProcess , OpenProcessToken , GetTokenInformation and LookupAccountSid to verify if the user is a local admin. GetTokenInformation returns a TOKEN_GROUPS struct with an array of SID_AND_ATTRIBUTES structs. I iterate over the collection and compare the user names returned by LookupAccountSid . My problem is that, locally (or more generally on our in-house