Board index » delphi » Linking Microsoft Visual C++ .OBJ file to Delphi????

Linking Microsoft Visual C++ .OBJ file to Delphi????

I've got some C source which I compile with Microsoft Visual C++ 6 to create
a .OBJ file.
However when I then try to link the file into a Delphi project with e.g. {$L
release\test.obj} I get the error message 'Bad File Format: test.obj'

The Delphi help page lists a number of restrictions on .OBJ file formats but
I've NO idea which one the MSVC compiler might be breaking nor really where
to change it in MSVC anyway?!

Is it possible to link a MSVC .OBJ to Delphi at all?
If so what project options/settings should I use in MSVC?
(I currently am trying to use a 'Win32 Static Library' project in MSVC)

Any help GREATLY appreciated :-)

 

Re:Linking Microsoft Visual C++ .OBJ file to Delphi????


If I remember right, MSVC is breaking a particularly important restriction
of delphi : Microsoft objetc file format and Inprise one are differents. So
IMHO you cannot link delphi code to microsoft .obj. What you can do is
create a DLL (with MSVC) and use it within Delphi (or use an ActiveX or a
COM object).

Re:Linking Microsoft Visual C++ .OBJ file to Delphi????


I have exactly the same experience. I've made a dll from the c object files.
Delphi can use dlls correctly.
George

Quote
Martin Bryant <marti...@colossus.demon.co.uk> wrote in message

news:945697675.321.0.nnrp-14.9e98176c@news.demon.co.uk...
Quote
> I've got some C source which I compile with Microsoft Visual C++ 6 to
create
> a .OBJ file.
> However when I then try to link the file into a Delphi project with e.g.
{$L
> release\test.obj} I get the error message 'Bad File Format: test.obj'

> The Delphi help page lists a number of restrictions on .OBJ file formats
but
> I've NO idea which one the MSVC compiler might be breaking nor really
where
> to change it in MSVC anyway?!

> Is it possible to link a MSVC .OBJ to Delphi at all?
> If so what project options/settings should I use in MSVC?
> (I currently am trying to use a 'Win32 Static Library' project in MSVC)

> Any help GREATLY appreciated :-)

Re:Linking Microsoft Visual C++ .OBJ file to Delphi????


On Mon, 20 Dec 1999 13:39:18 -0000, "Martin Bryant"

Quote
<marti...@colossus.demon.co.uk> wrote:
>I've got some C source which I compile with Microsoft Visual C++ 6 to create
>a .OBJ file.
>However when I then try to link the file into a Delphi project with e.g. {$L
>release\test.obj} I get the error message 'Bad File Format: test.obj'

You may want to take a look to Econos Software ".OBJ patcher", a
freeware tool that tries to fix this kind of problem. I don't have the
URL, though.

Manuel Algora
m...@encomix.es

Re:Linking Microsoft Visual C++ .OBJ file to Delphi????


Quote
Martin Bryant wrote in message

<945697675.321.0.nnrp-14.9e981...@news.demon.co.uk>...

Quote
>Is it possible to link a MSVC .OBJ to Delphi at all?

I don't believe so. As I recall, MS uses COFF format
(Common Object File Format), and Borland uses
OMF. Totally different formats.

I think you need to wrap the VC functions in a DLL

Re:Linking Microsoft Visual C++ .OBJ file to Delphi????


You are correct, at least insofar as that the object file formats are
incompatible between Microsoft and Borland compilers. The names sound
familiar as well, but I can never remember who uses what, so I'll take your
word for it ;)
Creating a DLL and calling that would indeed seem to be the answer (if you
have access to MSVC, that is), or try to get a Borland compatible version of
the OBJs (if it will compile with BC...).

--
J.T. Wenting

www.hornet.demon.nl

"Ron Ruble" <r a f f l e s 2...@worldnet.att.net> wrote in message
news:83lpki$l11$1@bgtnsc03.worldnet.att.net...

Quote

> Martin Bryant wrote in message
> <945697675.321.0.nnrp-14.9e981...@news.demon.co.uk>...
> >Is it possible to link a MSVC .OBJ to Delphi at all?

> I don't believe so. As I recall, MS uses COFF format
> (Common Object File Format), and Borland uses
> OMF. Totally different formats.

> I think you need to wrap the VC functions in a DLL

Re:Linking Microsoft Visual C++ .OBJ file to Delphi????


On Mon, 20 Dec 1999 09:33:13 -0500, "Ron Ruble" <r a f f l e s

Quote
2...@worldnet.att.net> wrote:
>Martin Bryant wrote in message
><945697675.321.0.nnrp-14.9e981...@news.demon.co.uk>...
>>Is it possible to link a MSVC .OBJ to Delphi at all?

>I don't believe so. As I recall, MS uses COFF format
>(Common Object File Format), and Borland uses
>OMF. Totally different formats.

I have not tried with Borland's linker, so I can't say whether this
one can also do it, but MS's linker does convert automatically an OMF
format into COFF as needed. So the other way round should be possible:
linking a Delphi .OBJ with a MSVC main.

Manuel Algora
m...@encomix.es

Re:Linking Microsoft Visual C++ .OBJ file to Delphi????


Thanks for all the information. Typical Microsoft :-(

Does anyone know if the latest Borland C++ compiler can produce static
linkable .OBJ files into Delphi?

Quote
Martin Bryant <marti...@colossus.demon.co.uk> wrote in message

news:945697675.321.0.nnrp-14.9e98176c@news.demon.co.uk...
Quote
> I've got some C source which I compile with Microsoft Visual C++ 6 to
create
> a .OBJ file.
> However when I then try to link the file into a Delphi project with e.g.
{$L
> release\test.obj} I get the error message 'Bad File Format: test.obj'

> The Delphi help page lists a number of restrictions on .OBJ file formats
but
> I've NO idea which one the MSVC compiler might be breaking nor really
where
> to change it in MSVC anyway?!

> Is it possible to link a MSVC .OBJ to Delphi at all?
> If so what project options/settings should I use in MSVC?
> (I currently am trying to use a 'Win32 Static Library' project in MSVC)

> Any help GREATLY appreciated :-)

Re:Linking Microsoft Visual C++ .OBJ file to Delphi????


Quote
Martin Bryant wrote in message

<945978006.19238.0.nnrp-12.9e981...@news.demon.co.uk>...

Quote
>Thanks for all the information. Typical Microsoft :-(

Oddly enough, switching to COFF format was an attempt
to -open up- compatibility. MS did that when they switched
to Win32, because COFF is a cross-platform standard.

They also implemented COFF debugging information at
the same time. Borland retained OMF because they
were still supporting a 16-bit compiler. I assume it
simplified maintaining the code base.

Quote
>Does anyone know if the latest Borland C++ compiler can produce static
>linkable .OBJ files into Delphi?

I would assume so. Check the Borland newsgroups
to be sure.

Re:Linking Microsoft Visual C++ .OBJ file to Delphi????


Quote
Martin Bryant wrote:

> Thanks for all the information. Typical Microsoft :-(

Oh come on. No compiler produces portable object code. Be fair to the
Redmond software giant <g>.

Quote
> Does anyone know if the latest Borland C++ compiler can produce static
> linkable .OBJ files into Delphi?

Why not make a dll out of your code? Then you've got no problem. Or,
perhaps, a Com 'object'? Delphi 'knows' how to read those and you won't
have to bother with object formats. Of course, with the dll, you'll
still have to{*word*222}with the import library (should you prefer to use it
vs. run-time loading, which I'm sure you would.) But that is a bit
easier to overcome by reconstructing the .def file. With a Com component
you'll have nothing to struggle with at all, so, imo, that is the best
solution for your predicament.

Re:Linking Microsoft Visual C++ .OBJ file to Delphi????


yes, the borland compilers generate Intel Obj files.
Vc can also do this if you configure it i do beleve.
Quote
Martin Bryant wrote:
> Thanks for all the information. Typical Microsoft :-(

> Does anyone know if the latest Borland C++ compiler can produce static
> linkable .OBJ files into Delphi?

> Martin Bryant <marti...@colossus.demon.co.uk> wrote in message
> news:945697675.321.0.nnrp-14.9e98176c@news.demon.co.uk...
> > I've got some C source which I compile with Microsoft Visual C++ 6 to
> create
> > a .OBJ file.
> > However when I then try to link the file into a Delphi project with e.g.
> {$L
> > release\test.obj} I get the error message 'Bad File Format: test.obj'

> > The Delphi help page lists a number of restrictions on .OBJ file formats
> but
> > I've NO idea which one the MSVC compiler might be breaking nor really
> where
> > to change it in MSVC anyway?!

> > Is it possible to link a MSVC .OBJ to Delphi at all?
> > If so what project options/settings should I use in MSVC?
> > (I currently am trying to use a 'Win32 Static Library' project in MSVC)

> > Any help GREATLY appreciated :-)

Re:Linking Microsoft Visual C++ .OBJ file to Delphi????


I have a different problem. I also created a c dll, but I can't seem to call
the functions from within Delphi. I have done everything like it says in the
book, but it just doesn't work. How did you do it?

Quote
Gy{*word*39} Balogh wrote in message <83lh8h$l7...@ultra.kfki.hu>...
>I have exactly the same experience. I've made a dll from the c object
files.
>Delphi can use dlls correctly.
>George

Re:Linking Microsoft Visual C++ .OBJ file to Delphi????


Quote
s.laurijssen <se...@circe.demon.nl> wrote in message

news:946583798.7618.0.pluto.d4ee0942@news.demon.nl...

Quote
> I have a different problem. I also created a c dll, but I can't seem to
call
> the functions from within Delphi. I have done everything like it says in
the
> book, but it just doesn't work. How did you do it?

Two likely possibilities:

1) you failed to export the function at all
2) you exported the function and the compiler and linker conspired against
you to rename it

If your problem is #1, it's time to go back to that book. :-) You can tell
by building a C language caller. If that works that's the problem.

If your problem is #2, try this:

VC/C++ comes with a handy utility called DUMPBIN (dump binary executable).

Enter the command

    dumpbin /exports mycdll.dll

If you have successfully exported your C function names you'll see some
vaguely familiar names

    _myCFunc@nn

where myCFunc is the name you assigned to your function in the source and nn
is a small integer

Now create a file with the same name as your DLL and a .DEF (module
definition file) extension

LIBRARY   myDLL

EXPORTS
             myCFunc  = _myCFunc@nn

Add this file to your project in the IDE. Rebuild.

If all goes well this will alias your function names by removing the
decoration. When Delphi tries to access the function with the undecorated
name it should find it. If it has some other decoration scheme then you can
alias it differently in the DEF file.

Regards,
Will

Re:Linking Microsoft Visual C++ .OBJ file to Delphi????


Thanks a lot! I got it working now.
I forgot to put the extern "C" identifier in the C-source before the
exported functions. This way I could only call them from C-programs.
I also learned a lot from your explanation (I am a Delphi beginner, so
that's not very hard)

Quote

>Two likely possibilities:

>1) you failed to export the function at all
>2) you exported the function and the compiler and linker conspired against
>you to rename it

>If your problem is #1, it's time to go back to that book. :-) You can tell
>by building a C language caller. If that works that's the problem.

>If your problem is #2, try this:

>VC/C++ comes with a handy utility called DUMPBIN (dump binary executable).

>Enter the command

>    dumpbin /exports mycdll.dll

>If you have successfully exported your C function names you'll see some
>vaguely familiar names

>    _myCFunc@nn

>where myCFunc is the name you assigned to your function in the source and
nn
>is a small integer

>Now create a file with the same name as your DLL and a .DEF (module
>definition file) extension

>LIBRARY   myDLL

>EXPORTS
>             myCFunc  = _myCFunc@nn

>Add this file to your project in the IDE. Rebuild.

>If all goes well this will alias your function names by removing the
>decoration. When Delphi tries to access the function with the undecorated
>name it should find it. If it has some other decoration scheme then you can
>alias it differently in the DEF file.

>Regards,
>Will

Other Threads