سؤال

I have a problem with marshalling SSL_ctrl func from OpenSsl 1.0.2 beta.

This func is

long  SSL_ctrl(SSL *ctx, int cmd, long larg, void *parg);

I'm trying to marshal it as

[DllImport(SSLDLLNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern long SSL_ctrl(IntPtr /* SSL* */ ssl,
                               int cmd,
                               long larg,
                               IntPtr parg);

I've enabled native code debugging in my Visual Studio.

The problem is the last argument.

I've tried to call that func with different pointers (non zero) but result is always same: native code accepts parg, but parg is equal to 0x0.

I've tried to pass strings (got pointer by calling Marshal.StringToHGlobalAnsi(serverName)), tried to pass some generated non-zero pointer, but the result is always same. parg is 0x0 in the native code.

Could you please help me with that issue?

هل كانت مفيدة؟

المحلول

long in C# is the equivalent of int64_t in C. The size of long in C depends on implementation, and with most Win32 implementations it is equivalent to int32_t. Therefore, the value parg you observe in your unmanaged code is the value of upper 32 bits of larg in your managed code.

In general, it is not advisable to use implementation-dependent types in C interoperability interfaces.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top