September 4th, 2012, 04:53 AM
Using 32Bit Library in 32Bit Visual C#
I have a 32bit Delphi Coded DLL File (Simple DLL Binary - not COM / OCX). This DLL exposes certain methods for use. It does not depend on Sharemem libraries of some kind of runtime environment (besides native windows DLLs).
My Visual Studio is VS Express 2008 (.Net 3.5)
I have the following code that tries to import thei Library into a C# Console application (console for simplicity only).
The Delphi declared / exposed function has the following declaration
Procedure MyProc(aVal: Integer); stdcall;
As you can see, it takes an Integer value and will simply show a message containing the received value.
Herewith my C# code
I Get the following Error
[DllImport("MyDLL.DLL", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, EntryPoint = "MyProc")]
public static extern void MyProc(int aVar);
static void Main(string args)
string path = Environment.GetEnvironmentVariable("PATH") ?? string.Empty;
path += ";c:\\iobox\\csharp";
Any help would be greatly appreciated.
An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
PS: I understand 64bit processes cannot call 32bit processes - but this doesnt seem like the problem. And the section on Environment Variables was part of problem solving.
September 7th, 2012, 04:57 AM
It seems I was mistaken. I downloading the .NET SDK and used CorFlags to force my EXE to 32bit - and it all started to work :-)
Hence 2008 Express Edition default compiles to 64bit and has no setting to change it - thus I use corflags on the binary after compiling.