Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A couple of things jump out at me. First of all I don't see why you need to use unsafe. Secondly, you probably have a calling convention mismatch, cdecl in the C++ and stdcall in the C#.</p> <p>I'd do it like this:</p> <p><strong>C++</strong></p> <pre><code>struct RESOURCE_PARAMETERS{ unsigned int uSurfaceHeight; unsigned int uSurfaceDepth; unsigned int uSurfaceWidth; unsigned int uMSAAHeight; unsigned int uMSAAWidth; unsigned int uArraySize; unsigned int uNumSamples; unsigned int uMaxLod; unsigned int uBpp; unsigned int uprefFlag; unsigned int uusageFlag; RESOURCE_TYPE_REC ResourceType; int ResourceFormat; int iBuildNumber; }; int function(RefPar &amp;parameters) { } </code></pre> <p><strong>C#</strong></p> <pre><code>[StructLayout(LayoutKind.Sequential)] public struct RESOURCE_PARAMETERS { uint uSurfaceHeight; uint uSurfaceDepth; uint uSurfaceWidth; uint uMSAAHeight; uint uMSAAWidth; uint uArraySize; uint uNumSamples; uint uMaxLod; uint uBpp; uint uprefFlag; uint uusageFlag; [MarshalAs(UnmanagedType.U4)] ResourceType ResourceType; int ResourceFormat; int iBuildNumber; } [DllImport("VistaGMMDLL.dll", CallingConvention = CallingConvention.Cdecl)] static extern int function(ref RESOURCE_PARAMETERS parameters); RESOURCE_PARAMETERS parameters = new RESOURCE_PARAMETERS(); int result = function(ref parameters); </code></pre> <p>I'm not sure how big the enum is on the C++ size. That's why I've put an explicit MarshalAs in the C# code. If it's just a single byte, then use UnmanagedType.U1 instead. I trust you get the idea.</p> <p>If your C++ function treats its parameter as an in/out parameter then using ref on the C# side is correct. If its actually an out parameter then change the code to be like this:</p> <pre><code>[DllImport("VistaGMMDLL.dll", CallingConvention = CallingConvention.Cdecl)] static extern int function(out RESOURCE_PARAMETERS parameters); RESOURCE_PARAMETERS parameters; int result = function(out parameters); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload