In an attempt to learn to use PInvoke in C#, I'm a little unsure how to handle various cases with pointers involving simple value types.
I'm importing the following two functions from an unmanaged DLL:
public int USB4_Initialize(short* device);
public int USB4_GetCount(short device, short encoder, unsigned long* value);
The first fun...
When I create a signature that refers to user32.dll for example should I be building this with user64.dll if the target is a 64-bit computer?
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool ChangeClipboardChain(
IntPtr hWndRemove,
IntPtr hWndNewNext);
Currently this isn't a problem as I'm targeting ...
Hi All:
I am trying to PInvoke UpdateProcThreadAttribute() on Windows 7 but my attempts just keep returning FALSE with a Last Win32 Error of 50.
Function declaration (from MSDN)
BOOL WINAPI UpdateProcThreadAttribute(
__inout LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList,
__in DWORD dwFlags,
__in DWORD_PTR Attribute...
Hi:
Most sample code on the web for calling CreateProcessAsUser() has a similar PInvoke signature to the following:
public static extern bool CreateProcessAsUser(IntPtr hToken,
string lpApplicationName,
string lpCommandLine,
ref SECURITY_ATTRIBUTES lpProcessAttributes,
ref SECURITY_ATTRIBUTES lpThre...
In the process of learning P/Invoke, I asked this previous question:
How to P/Invoke when pointers are involved
However, I don't quite understand the implications of using P/Invoke in C# over creating a wrapper in Managed C++. Creating the same DLL using P/Invoke in C# definately resulted in a cleaner interface since I could use DL...
Hi,
I am trying to PInvoke CreateDesktop in a way that passes the flag to inherit the desktop by child processes. The declaration is as follows:
[DllImport("user32", EntryPoint = "CreateDesktopW", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr CreateDesktop(string lpszDesktop, IntPtr lpszDevice, In...
I am writing a small C# app to disable a device (my laptop touchpad) whenever another mouse device is detected, and enable the touchpad again if a mouse is not detected. I am not even able to disable the touchpad in device manager (it is running on the default mouse class driver).
I am getting into device driver development so I though...
This is my first time using C#, so I'm very much out of my element. But I have faith that the wonderful people here at Stack Overflow can help me out! I've come up with the following code (below) based on some other pieces of code I found floating around on the internet. What I am trying to do is to look up all the "text" DNS records (TX...
http://msdn.microsoft.com/en-us/library/ms182161%28VS.80%29.aspx
Are the three classes described on this paged handled specially in the .NET Framework? (NativeMethods, SafeNativeMethods and UnsafeNativeMethods)
The reason I'm asking is I'm wondering if it is alright to create categories of NativeMethods classes. For example:
ComNati...
Hello,
I have a dll that is written in c++. And I am p/invoking to call the functions.
I have this c++ declaration.
int dll_registerAccount(char* username, char* password);
I have done this dllimport declaration:
[DllImport("pjsipDlld")]
static extern int dll_registerAccount(IntPtr username, IntPtr password);
Would my DllImport b...
As a side project, I am implementing a MIDI matrix to interconnect a number of MIDI keyboards with sound sources. The key requirement here is to echo MIDI data received on an input port to a selected output port.
Having created the necessary P/Invoke declarations & wrappers, I notice that the Win32 MIDI documentation for MidiInProc state...
Both LogonUserExEx() and LsaLogonUser() accept a PTOKEN_GROUPS pTokenGroups parameter. I am having trouble marshalling my structure correctly for this parameter.
I have the following structures defined:
[StructLayout(LayoutKind.Sequential)]
public struct TOKEN_GROUPS
{
public UInt32 GroupCount;
// Followed by this:
public S...
I am having a lot of trouble getting a basic scenario to work on windows mobile 5.0 emulator. I have a winforms app that eventually calls into native code. Deployment works fine and all the native DLLs are copied in the same folder as the winforms .exe. I also verified this is the case with Remote File Viewer tool.
However when I lau...
There is an enum of all supported processor architectures here: http://msdn.microsoft.com/en-us/library/system.reflection.processorarchitecture.aspx
Is there any way to determine which one corresponds to the running environment? System.Reflection.Assembly.GetExecutingAssembly().ProcessorArchitecture returns MSIL -- obviously wrong.
EDI...
Hello *,
I am currently investigating how Thread.Interrupt plays together with P/Invoke or native calls. I have read in MSDN that it is not possible to abort (Thread.Abort) a thread which is in the native call (other use cases might apply as well). But I did not find any reference which states the same for native threads which are in Wa...
Hi,
I am using DllImport to call method in c wrapper library from my own .net class. This method in c dll creates a string variable and returns the pointer of the string.
Something like this;
_declspec(dllexport) int ReturnString()
{
char* retval = (char *) malloc(125);
strcat(retval, "SOMETEXT");
strcat(retval, "SOMETEXT MORE");
...
I have a C api and I am using p/invoke to call a function from the api in my C# application. The function signature is:
int APIENTRY GetData (CASHTYPEPOINTER cashData);
Type definitions:
typedef CASHTYPE* CASHTYPEPOINTER;
typedef struct CASH
{
int CashNumber;
CURRENCYTYPE Types[24];
} CASHTYPE;
typedef struct CURRENCY
{
char ...
I am working with a system that uses GUIDs as keys in most database tables. The guids are created using UuidCreateSequential, in order to be nice to the database indexes.
C++ syntax, according to http://msdn.microsoft.com/en-us/library/aa379322%28VS.85%29.aspx :
RPC_STATUS RPC_ENTRY UuidCreateSequential(
UUID __RPC_FAR *Uuid
);
p...
I'm about to start working on a ClickOnce app targeted at internal customers for use on the organization's intranet. I want to ease the setup process, so I thought that developing the app to be partially trusted would be a good idea, but now I'm not so sure.
One thing that the users have specifically asked for is (boiled down to) a Tex...
I would like to know if a file is open by any process (including the caller) There are a number of suggestions already posted, which tend to revolve around trying to open the file exclusively and catching the exception.
This has not proven to be a fool-proof method in my instance. I beleive in my specific situation I can get by with s...