Questions tagged [pinvoke]
P/Invoke is an implementation specification created by Microsoft of the Common Language Infrastructure (CLI) for invocation of native code libraries from managed code.
pinvoke
3,788
questions
0
votes
0
answers
46
views
Low level mouse hook handles mouse scroll in Windows, but not Fallout 4 [duplicate]
The idea is to caputre the mouse scroll and then return handled, entirely disabling it. The issue is that it doesn't work in-game for some reason.
Pseudo-code to explain how my code works:
var handle =...
3
votes
1
answer
83
views
How do I marshal a C# struct with delegate fields?
I'm writing a C# wrapper for SDL3. I'm currently trying to implement the following struct:
typedef struct SDL_VirtualJoystickDesc
{
Uint16 type; /**< `SDL_JoystickType` */
Uint16 ...
0
votes
0
answers
125
views
Interop Delphi dll / C# - bad memory allocation or marshaling
I'm making a wrapper to call a Delphi dll in a C# app, and I'm struggling to make it work. It doesn't crash but the returned result is random data from memory.
I don'tknow if the problem is coming ...
2
votes
1
answer
51
views
Why would I need `DangerousAddRef`/`DangerousRelease` around `DangerousGetHandle`?
I've been looking into the Microsoft.Windows.CsWin32 NuGet package and comparing the P/Invoke code it generates to what I would write by hand. In some cases it uses SafeHandle.DangerousAddRef/...
0
votes
0
answers
49
views
PInvoke memory management: strings inside structs passed by reference
I have a question about the releasing of memory when marshalling structs containing strings across pInvoke
I want to return a result struct by reference, since the calling code can not directly return ...
1
vote
0
answers
37
views
Move top menu from a hosted program to the main wpf app
I'm making a wpf app (,net framework) which hosts an external app (mfc program), to host it I'm using a WindowsFormsHost control and the SeParent function from pInvoke like that:
int style = ...
-2
votes
1
answer
132
views
DllImport not executing functions in library but no error codes [closed]
I am developing on Windows 11 and have been given an unmanaged C dll. However I am running into the issue that I am unable to execute the functions in the library. I do not get any errors, the ...
4
votes
1
answer
221
views
Distribute DLLs in Nuget
I am working on a C# library (LLamaSharp) which wraps a C++ library (llama.cpp).
As part of the nuget package we're including DLLs compiled with all the various types of hardware support (CUDA, OpenCL,...
-1
votes
1
answer
85
views
How to marshal a struct with a nested array of structs when using P/Invoke C#
I have the following C function declaration which I would like to call from C# (Note I cannot access the source code of the dll):
int setData(OuterStruct *data);
And the relevant structs for this C ...
2
votes
1
answer
230
views
CsWin32 how to create an instance of PWSTR for e.g. GetWindowText
I just started using CsWin32 and one of the Win32 functions I want to use it GetWindowText which gets mapped to
I know how to work with the first and last parameter, but I don't know what to do with ...
0
votes
1
answer
79
views
.NET app call unmanged DLL, parameters contains strange characters
I am wring a .NET app to call an unmanaged DLL(Unicode).
Below is the header for the unmanaged DLL:
#pragma once
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
// Callback ...
0
votes
0
answers
13
views
Working with errno in a cross-platform way in .NET
I am writing a cross-platform .NET library which relies on P/Invoke into system libraries. I need to handle errors which invoked functions report through the errno variable. This variable can be ...
-1
votes
1
answer
39
views
Direct2D Clear/DrawBitmap Throwing Exception
In a C++ DLL I've got Direct2D initialized and then some draw functions. When calling pRenderTarget->Clear(...) it throws an AccessViolationException (Trying to access protected memory ...).
Here ...
1
vote
0
answers
98
views
How to send a WM_IME_REQUEST message from C#
I'm working on an IME tool. To figure out the caret position of the foreground window, I'm supposed to use SendMessage() to send a WM_IME_REQUEST (0x0288) message, along with the parameters:
wParam: ...
1
vote
1
answer
147
views
Lifetime of a temporary
I am encountering some sporadic crashes when calling into a C++ library (not under my control) from C#.
The internal code of the C++ library is roughly like this:
#include <string>
#include <...