32bit DLL Import into 32bit

dve83

New member
Joined
Sep 6, 2012
Messages
1
Programming Experience
3-5
Hello,

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) So far as I can see a x86 version (also installed in program files x86)

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




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace ConsoleApplication1
{
class Program
{
[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";
Environment.SetEnvironmentVariable("PATH", path);

MyProc(5);
System.Console.Write("a");
}
}
}

I Get the following Error


An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

I have also tried a COM object with a simple test function as follows:

FunctionTIQEntAPICom.IQ_API_Test(aValue:Integer): HRESULT;beginShowMessage('Test With Value ['+IntToStr(aValue)+']');Result:=0;end;

I have instantiated and called the function as follows;

pIQEntAPICom.IQEntAPIComClass F =new pIQEntAPICom.IQEntAPIComClass(); F.IQ_API_Test(6);However when executing the application, I get

Retrieving the COM class factory for component with CLSID {052F5458-886B-48E3-A4CC-5C8FF6570057} failed due to the following error:80040154.Any help would be greatly appreciated.


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, so ignore for now. I have checked project options and dont seem to have a Target Architecture to change (64bit / x86).
 

Latest posts

Back
Top Bottom