Note that there are some explanatory texts on larger screens.

plurals
  1. POTroubleshooting VC++ DLL in VB.Net
    text
    copied!<p>I'm trying to make a solution in Visual Studio that consists of a VC++ DLL (C++/CLI) and a VB.Net application. To figure this out, I created a VC++ Class Library project, with the following code (I removed all the junk the wizard creates):</p> <p>mathfuncs.cpp:</p> <pre><code>#include "MathFuncs.h" namespace MathFuncs { double MyMathFuncs::Add(double a, double b) { return a + b; } } </code></pre> <p>mathfuncs.h:</p> <pre><code>using namespace System; namespace MathFuncs { public ref class MyMathFuncs { public: static double Add(double a, double b); }; } </code></pre> <p>This compiles quite happily. I can then add a VC++ console project to the solution, add a reference to the original project for this new project, and call it as follows:</p> <p>test.cpp:</p> <pre><code>using namespace System; int main(array&lt;System::String ^&gt; ^args) { double a = 7.4; int b = 99; Console::WriteLine("a + b = {0}", MathFuncs::MyMathFuncs::Add(a, b)); return 0; } </code></pre> <p>This works just fine, and will build to test.exe and mathsfuncs.dll.</p> <p>However, I want to use a VB.Net project to call the DLL. To do this, I add a VB.Net project to the solution, make it the startup project, and add a reference to the original project. Then, I attempt to use it as follows:</p> <pre><code>MsgBox(MathFuncs.MyMathFuncs.Add(1, 2)) </code></pre> <p>However, when I run this code, it gives me an error: </p> <blockquote> <p>Could not load file or assembly 'MathFuncsAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.</p> </blockquote> <p>Do I need to expose the method somehow? </p> <p>I'm using Visual Studio 2008 Professional.</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