🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
7 messages
7 total messages Started by Sue King Sun, 14 Oct 2007 22:44
Using __stdcall
#1229
Author: Sue King
Date: Sun, 14 Oct 2007 22:44
19 lines
1416 bytes
Hi,

I have some old C code that I wish to compile using the 2007 C/C++ in 
RAD Studio Professional.  This links to a dll that uses __stdcall and 
gives names such as _Function@4 in the .lib file.

I don't seem to be able to get the compiler to pick up the mangled name. 
  The error is [ILINK32 Error]Error: Unresolved external 'Function' 
referenced from xx.obj

I tried unchecking the name mangle option under General Compatability 
but still no joy.

Can someone please point me to some documentation/examples, or explain 
what I have missed ? (Or the correct newsgroup if this is not the right one)

TIA

Sue King
Re: Using __stdcall
#1230
Author: Bob Gonder
Date: Sun, 14 Oct 2007 23:51
38 lines
2172 bytes
Sue King wrote:

>I have some old C code that I wish to compile using the 2007 C/C++ in 
>RAD Studio Professional.  This links to a dll that uses __stdcall and 
>gives names such as _Function@4 in the .lib file.

Matching Google links:
http://groups.google.com/group/borland.public.cppbuilder.winapi/browse_thread/thread/3f81609418611afd
http://tinyurl.com/37zs7z

http://groups.google.com/group/borland.public.cpp.borlandcpp/browse_thread/thread/87925e78fe34c6c5
http://tinyurl.com/2n3jbn

>I don't seem to be able to get the compiler to pick up the mangled name. 
>  The error is [ILINK32 Error]Error: Unresolved external 'Function' 
>referenced from xx.obj

What does the function delcaration look like?
It should look something like this

#define MYDLLAPI __declspec(dllimport)
#ifdef __cplusplus
extern "C" {
#endif
	MYDLLAPI  BOOL __stdcall Function( /*ParamList*/ );
#ifdef __cplusplus
	}
#endif

Another thing, in Borland, __stdcall removes the leading _ that
C normally places in front of function names. So you might try
using _Function() in your application.

Or fixup a .DEF file as Ed suggests in the above lnks.

>(Or the correct newsgroup if this is not the right one)

The .IDE group would be ideal for settings.
Re: Using __stdcall
#1231
Author: Sue King
Date: Mon, 15 Oct 2007 04:35
85 lines
3732 bytes
Bob Gonder wrote:
> Sue King wrote:
> 
>> I have some old C code that I wish to compile using the 2007 C/C++ in 
>> RAD Studio Professional.  This links to a dll that uses __stdcall and 
>> gives names such as _Function@4 in the .lib file.
> 
Hi Bob,

Thanks for replying.
I've read the posts and think I almost understand what is happening/not 
happening.  (Pity I put __ in my google search for stdcall/cdecl)

> Matching Google links:
> http://groups.google.com/group/borland.public.cppbuilder.winapi/browse_thread/thread/3f81609418611afd
> http://tinyurl.com/37zs7z
> 
> http://groups.google.com/group/borland.public.cpp.borlandcpp/browse_thread/thread/87925e78fe34c6c5
> http://tinyurl.com/2n3jbn
> 
>> I don't seem to be able to get the compiler to pick up the mangled name. 
>>  The error is [ILINK32 Error]Error: Unresolved external 'Function' 
>> referenced from xx.obj
> 
> What does the function delcaration look like?
> It should look something like this
> 
> #define MYDLLAPI __declspec(dllimport)
> #ifdef __cplusplus
> extern "C" {
> #endif
> 	MYDLLAPI  BOOL __stdcall Function( /*ParamList*/ );
> #ifdef __cplusplus
> 	}
> #endif

Yes it does.

#ifdef __cplusplus
extern "C"{
#endif
__declspec(dllimport) mystruct * __stdcall Function(void);
#ifdef __cplusplus
}
#endif

Previously I didn't have the #ifdef cplusplus as I am not using any c++ 
but I've added it in anyway.
> 
> Another thing, in Borland, __stdcall removes the leading _ that
> C normally places in front of function names. So you might try
> using _Function() in your application.

I tried this but no joy. Same error _Function unresolved.
> 
> Or fixup a .DEF file as Ed suggests in the above lnks.

I've tried this but am missing something.

What I did was create a .def file using impdef.  The file has entries 
such as
Function = _Function@0

So then I included it in my project, but it made no difference.

The second reference refers to a lib command to create the .lib file 
from the .def.
What is this for Borland ?  I tried 'lib' but this picked up a lib 
command for another compiler I have installed, and the creation of a 
.lib from the .def is invalid for this command.  Or if it is the correct 
command, where does it live ?  I looked in CodeGear ... \bin and could 
not find an exe that seemed appropriate.  Ihave one in a VStudio 8 
directory but as I don't have Vstudio 8 installed it won't run. (Think 
these are there because of MSDN stuff).

It looks like Jeff ended up using cdecl instead of stdcall.

> 
>> (Or the correct newsgroup if this is not the right one)
> 
> The .IDE group would be ideal for settings.
> 

Thanks
Sue
Re: Using __stdcall
#1232
Author: Sue King
Date: Mon, 15 Oct 2007 04:52
47 lines
2470 bytes
Bob Gonder wrote:
> Sue King wrote:
> 
>> I have some old C code that I wish to compile using the 2007 C/C++ in 
>> RAD Studio Professional.  This links to a dll that uses __stdcall and 
>> gives names such as _Function@4 in the .lib file.
> 
> Matching Google links:
> http://groups.google.com/group/borland.public.cppbuilder.winapi/browse_thread/thread/3f81609418611afd
> http://tinyurl.com/37zs7z
> 
> http://groups.google.com/group/borland.public.cpp.borlandcpp/browse_thread/thread/87925e78fe34c6c5
> http://tinyurl.com/2n3jbn
> 
>> I don't seem to be able to get the compiler to pick up the mangled name. 
>>  The error is [ILINK32 Error]Error: Unresolved external 'Function' 
>> referenced from xx.obj
> 
> What does the function delcaration look like?
> It should look something like this
> 
> #define MYDLLAPI __declspec(dllimport)
> #ifdef __cplusplus
> extern "C" {
> #endif
> 	MYDLLAPI  BOOL __stdcall Function( /*ParamList*/ );
> #ifdef __cplusplus
> 	}
> #endif
> 
> Another thing, in Borland, __stdcall removes the leading _ that
> C normally places in front of function names. So you might try
> using _Function() in your application.
> 
> Or fixup a .DEF file as Ed suggests in the above lnks.
> 
>> (Or the correct newsgroup if this is not the right one)
> 
> The .IDE group would be ideal for settings.
> 
> 
I've just found another post relating to linking gcc DLL's with Borland 
C and am trying more things from this.

It includes a link showing how to create the .lib from the .def.

Sue
Re: Using __stdcall
#1234
Author: Jeff Kish
Date: Mon, 15 Oct 2007 12:26
19 lines
1548 bytes
<snip>
>> The .IDE group would be ideal for settings.
>> 
>> 
>I've just found another post relating to linking gcc DLL's with Borland 
>C and am trying more things from this.
>
>It includes a link showing how to create the .lib from the .def.
>
>Sue
did it work?

>I have some old C code that I wish to compile using the 2007 C/C++ in 
>RAD Studio Professional.  This links to a dll that uses __stdcall and 
>gives names such as _Function@4 in the .lib file.
I assume you did not write and don't have access to writing/compiling
the dll?

Jeff Kish
Re: Using __stdcall
#1236
Author: Bob Gonder
Date: Mon, 15 Oct 2007 23:53
14 lines
1493 bytes
Sue King wrote:

>The second reference refers to a lib command to create the .lib file 
>from the .def.
>What is this for Borland ?  I tried 'lib' but this picked up a lib 
>command for another compiler I have installed, and the creation of a 
>.lib from the .def is invalid for this command.

The other 2 "lib" commands are implib  and tlib.

implib is the lib version of impdef:
creates a Borland .lib link file from a dll or .def.

TLIB is the librarian that creates static libraries from .obj files.
Re: Using __stdcall
#1237
Author: Sue King
Date: Tue, 16 Oct 2007 08:06
50 lines
3319 bytes
Sue King wrote:

Thanks Bob and Jeff.

In answer to Jeff's question, I do have the source to the dll mangling 
the names, but do not wish to move it as it contains embedded sql code 
and the original ide supports the appropriate preprocessor (Open Watcom 
and Sybase sql).  If really necessary it can be changed, but I would 
really rather leave it as is, as it is simpler to make and is very 
rarely changed.

I think I am on top of it now thanks to your help and the previous posts.

What I have found is that by running impdef followed by implib I can 
create an appropriate lib file to use instead of the one created by OW. 
    There were no manual changes required.  The OW lib pointed a mangled 
name to a mangled name and that works fine for OW compiling and linking. 
  The RAD Studio lib points 'clean' name to mangled name, and RAD C now 
compiles and links (and runs although I haven't done in depth testing).

Most of the application is actually written in Delphi, and it doesn't 
really matter which way the names are specified, as that can be given 
directly by linking a Delphi procedure to the dll one directly 
specifying the dll and entry point.  The issue is with a C dll that I 
can't leave with OW as it uses rpc code and that has changed with new 
security with later Windows versions and I am not expert enough with C 
to work out the changes needed to OW to make it work with new Microsoft 
libraries and procedures. (And I have to try out my new RAD C anyway)

On looking at some other code (this was all written by other people no 
longer here), I found that there is another solution.  In this code, the 
procedures are defined with a pragma as follows (I don't completely 
understand it, but you probably will).

#pragma aux __torrens "*"\
   parm routine [] \
   value struct struct caller [] \
   modify [eax ecx edx]
#pragma AUX (__torrens) Function
int __export Function(short limit);

Is this just as valid ?  Will the memory still be freed properly ?  I'm 
not really familiar with assembler (unfortunately the only assembler I 
really got the hang of was old IBM 360/370 mainframe assembler, showing 
my age!!).

I prefer the lib method, as it makes the C easier to follow.

Regards
Sue
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads