C# DllImport not returning on Windows 10

  Kiến thức lập trình

I am developing on Windows 11 and have been given an unmanaged C dll.
The C library function code signature is:

int connectToDeviceBySerial(const char * const serialNumber, uintptr_t* deviceContextPtr)

I am using DllImport like so:

internal const string laserTackDllPath = @"External Dependenciesspectrlib_core_shared.dll";

[DllImport(laserTackDllPath, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)]
static private extern int connectToDeviceBySerial(string serial, ref ulong deviceHandle);

and I am calling it in my code like this:

private void ConnectToDeviceInternal()
    int response = connectToDeviceBySerial(SerialNumber, ref DeviceHandle);
    if (response != OK) { throw new OESException(response); };

which is working perfectly fine on Windows 11. However, when I am using the same code on Windows 10, the function connectToDeviceBySerial never returns. I don’t get an error, it’s just that nothing happens and the program flow does not continue. As this code is part of an application with UI, this is executed in the background and the application does not freeze.

Is there anything I need to change for Windows 10? Does DllImport work differently on Windows 10?