Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Calling legacy C library from c#, usafe, fixed, two return parameters

$
0
0

I cannot find a way to resolve this.

The dll routine is written in C.  It accepts one input and returns two values.

In the code block that references the routine, as written I get:

"Cannot pass 'Socket' as a ref or out argument because it is a 'fixed variable' "

But if I change the call to:

if (DB_Get_VecSockAddr(acName, out &soc[0], out &len) != 0)
byte []soc = new byte[52];

Then I get:

"You can only take the address of an unfixed expression inside of a fixed statement initializer"


      [DllImport("ENVDBLDll.dll", EntryPoint = "DB_Get_VecSockAddr", CharSet = CharSet.Ansi)]
      unsafe public static  extern int DB_Get_VecSockAddr(char * acVecName, out byte* soc, out int* len);


...........


           unsafe
            {
                int len = 0;
                fixed ( char *acName = &acVECname[0] )
                {
                    fixed (byte* Socket = &soc[0])
                    {
                        if (DB_Get_VecSockAddr(acName, out Socket, out &len) != 0)
                        {
                        }
                    }
                }
            }


I'm confused.

How is this supposed to work?

I am using VS 2010, c#

Boyd


BDM


Viewing all articles
Browse latest Browse all 31927

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>