Board index » delphi » Using BC++ DLLs in BP7 DOS DPMI

Using BC++ DLLs in BP7 DOS DPMI

I have some C code that I would interface with my Borland Pascal 7 DOS
protected mode program, and I am first trying to make a simple 16-bit
Windows DLL with Borland C++ 5.02 to test the connection. But when I try to
run and use a function from that DLL, all it says is "Runtime error: invalid
entrypoint called". That function does nothing more than taking no
paramteres, and no return values, just set a=b....

In BP, the function is defined as:
procedure Hello; external 'MyDll' name 'HELLO';

And in the C DLL file, it is exported as:
void FAR PASCAL _export HELLO(void)
{
   int a=10;
   int b;

   b=a;

Quote
}

among also WEP and LibMain, which both simply returns 1;

Does it exist a template/FAQ/any kind of documentations or somebody who can
tell me exactly how this should be done?

Ola

 

Re:Using BC++ DLLs in BP7 DOS DPMI


Quote
Ola Presterud wrote:

> I have some C code that I would interface with my Borland Pascal 7 DOS
> protected mode program, and I am first trying to make a simple 16-bit
> Windows DLL with Borland C++ 5.02 to test the connection. But when I try to
> run and use a function from that DLL, all it says is "Runtime error: invalid
> entrypoint called".

The DLL does not export the same name as the one you are linking to,
or does not export it at all.

Quote
> In BP, the function is defined as:
> procedure Hello; external 'MyDll' name 'HELLO';

I understand this procedure is in the interface part, or you compile
in {$F+} mode (if neither, BP will barf anyway).

Quote
> And in the C DLL file, it is exported as:
> void FAR PASCAL _export HELLO(void)
> {

FAR and PASCAL are not C keywords, I hope they map to their lowercase
equivalents. (Check that, they may well be replaced by void, depending
on the compilation options like -A).

Quote
> somebody who can tell me exactly how this should be done?

You are on the right track (I just did it without problem).

One obvious point is that with BCC, you have to compile in
C mode, not C++ (because C++ mangles name). Read about "mangling"
in the documentation to learn further if you are interrested.
When it comes to DLLs, mangling have to be avoided...

Next, what probably causes trouble is that BCC is not lauched
with the correct options. The key one is to type:
  bcc -WDE -ml ... source.c

This way, bcc will automatically contruct the correct .DEF options,
hence exporting really 'HELLO'. You can check that with:
  impdef con MyDll

which will list at screen what is really exported from the DLL
(you can also save it as MyDLL.DEF, and then using it as template
for a real efficient .DEF, for further linking).

If HELLO really appears in the impdef output, without any decoration,
then I do not see any reason why your DPMI program won't start.
Particularly since mine does...

Antoine

Re:Using BC++ DLLs in BP7 DOS DPMI


"Antoine Leca" <Antoine.L...@renault.fr> skrev i melding
news:3A1D4AD7.84C5A28D@renault.fr...

Quote
> Next, what probably causes trouble is that BCC is not lauched
> with the correct options. The key one is to type:
>   bcc -WDE -ml ... source.c

Thanks for the help!

I tried with the above commandline, and then it worked perfectly!

Ola

Other Threads