Note that there are some explanatory texts on larger screens.

plurals
  1. POcreating C .dll and using it in C#
    text
    copied!<p>As a C# developper I'm trying to learn some C now. It seemed me fun to create a C dll and then use the functions I created in a C# project, just to get familiar with the language.</p> <p>For developping the c dll I use DEV-C++ and obviously for C# Visual Studio.</p> <p>This is what I've come up with so far:</p> <p>C</p> <pre><code>#include &lt;windows.h&gt; #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #define NAG_CALL __stdcall #define NAG_DLL_EXPIMP __declspec(dllexport) NAG_DLL_EXPIMP void NAG_CALL Scalars(double, double*); NAG_DLL_EXPIMP void NAG_CALL Scalars(double in, double *out) { *out = in; } </code></pre> <p>And in C#</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; namespace TestMyOwnCDLL { public static class MyCDLLWrapper { [DllImport("TestDLL1.dll")] private static extern void Scalars(double invar, ref double outvar); public static double CallScalars(double invar) { double outvar = (double)0.0; Scalars(invar, ref outvar); return outvar; } } } </code></pre> <p>I've added TastDLL1.dll to the assembly and marked 'Always copy'. However, when calling the function i get a BadImageFormatException. This means that the dll is found but it can't execute the dll for some reason.</p> <p>Any ideas? I've used the examples from: <a href="http://www.drdobbs.com/cpp/calling-c-library-dlls-from-c/184406285" rel="nofollow">http://www.drdobbs.com/cpp/calling-c-library-dlls-from-c/184406285</a></p> <p>Kind regards.</p>
 

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