1

The following line is generating a runtime error in a C# GUI:

int x = myclass.number_from_dll(); 

I'm using Microsoft Visual Studio 2008.

The code in C# is:

class myclass { [DllImport("strat_gr_dll.dll", EntryPoint = "number_from_dll")] public static extern int number_from_dll(); } 

The code in the C++ .dll is:

// This is an example of an exported function. DLL int number_from_dll(void) { return 42; } 

The runtime error from .NET is:

An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) 
1
  • Do you export that function with a friendly name? Commented Aug 2, 2010 at 19:13

1 Answer 1

4

Project + Properties, Build tab, Platform Target = x86.

Your C/C++ DLL was compiled in 32-bit mode. But your C# program is running on a 64-bit version of Windows and will run in 64-bit mode. That mix don't match. Creating a 64-bit version of you DLL is another solution. Build + Configuration Manager, Platform combo, New, x64.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you soooooo much - I just spent the last 4 hours trying to track down this problem, you're a legend!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.