Importing a function from a DLL compiled using another language

Started by jm, Today at 07:50:22 PM

Previous topic - Next topic

jm

This is purely a research exercise on my part with limited knowledge.  I'd be grateful if someone could tell me if there's a way in which I can import a function from a Windows DLL that I created using a non-C language compiler on Windows.

The other language compiler has understandably given me only a .DLL and a .LIB but the examples I've seen, where a DLL is used within C, appear to show a .H header is needed.  What should I create in the .H file, or is there another way?

The DLL I created is called JDL.DLL and it contains a function called myfunction() to accept a float value and return the result also as a float.  Can anyone help with this please, thanks.

Vortex

Hi jm,

The .h file, the header file contains the prototypes of the functions exported by your DLL. Strictly, you don't need a header file. All what you need is to translate correctly your function prototypes in that language to C.

As an example, consider the source code of this simple FreeBASIC DLL named testdll.dll :

Function sum Cdecl Alias "sum" (Byval x As Integer, Byval y As Integer) As Integer Export
   
    Return(x+y)
   
End Function

Function subs Cdecl Alias "subs" (Byval x As Integer, Byval y As Integer) As Integer Export
   
    Return(x-y)
   
End Function

Pelles C code with the function prototypes :

#include <stdio.h>

extern int __cdecl sum(int x,int y);

extern int __cdecl subs(int x,int y);

int main(void)
{
printf("70 + 30 = %d\n",sum(70,30));
printf("70 - 30 = %d",subs(70,30));
return 0;
}

Code it... That's all...