I'm trying to learn the basics of tying up unmanaged C++ and .NET. So, I've got the DLL compiled and callable from C#. Great. Now I run into this weird problem:
Here's my C++ file, Main.cpp
:
#include <stdio.h>
extern "C" __declspec(dllexport) void DisplayHelloFromDLL()
{
printf ("Hello from the World of 1986!\n");
}
and C# file, Program.cs
:
using System; using System.Runtime.InteropServices;
namespace FancyApp {
class Program
{
[DllImport("ConsoleApp.dll")]
public static extern void DisplayHelloFromDLL();
static void Main()
{
Console.WriteLine("Hello form the World of 2008!");
DisplayHelloFromDLL();
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
}
}
Simple enough. When build, I get ConsoleApp.dll
from the C++ side, and FancyApp.exe
from C#.
When run, it outputs
Hello form the World of 2008!
Hello from the World of 1986!
Press any key to exit
as it should, except in Release mode from VS2008 (Press F5), I get
Hello form the World of 2008!
Press any key to exit
Now, if I go to Explorer and run the release build of FancyApp.exe
without VS, it runs fine.
Ideas?
I've uploaded my solutions folder here (180kb).