Board index » delphi » Trouble accessing a dll written in Visual C++

Trouble accessing a dll written in Visual C++

If anyone can help me out with this one, I'd be really thankful!

I've got a dll written in Visual C++, with a function declared in the
header as this:
void DLLAPI GetRadixLibVer(LPSTR sp);

In my unit I'm declaring the function as:
procedure GetRadixLibVer(version : PChar); pascal; external 'RadixLib'
index 1;

and I'm using it like this
var
  version : array[0..100] of char;
...
  GetRadixLibVer(version);
...

However, running this line makes an access violation in module
'radixlib'

What have I done wrong???
(let me know if I've let out some important information)

 

Re:Trouble accessing a dll written in Visual C++


If your using D2 or 3 then you need to put the StdCall phrase in the
declaration line
along with the rest of it..
procedure GetRadixLibVer(version:Pchar);external; StdCall  'RadixLib.DLL'
index 1;

 also take note that you are absolutly sure that this address is the at
index 1 ?

Quote
> void DLLAPI GetRadixLibVer(LPSTR sp);

> In my unit I'm declaring the function as:
> procedure GetRadixLibVer(version : PChar); pascal; external 'RadixLib'
> index 1;

> and I'm using it like this
> var
>   version : array[0..100] of char;
> ...
>   GetRadixLibVer(version);
> ...

> However, running this line makes an access violation in module
> 'radixlib'

> What have I done wrong???

Re:Trouble accessing a dll written in Visual C++


Thanks for the tip, but unfortunately I've still got problems... With StdCall
instead of Pascal in the declaration I get the following message:
Project Estimato.exe raised exception class EAccessViolation with message
'Access violation at address 10001093 in module 'RADIXLIB.DLL'. Read of
address FFFFFFFF.'
I'm using D3, and I'm pretty sure that I've got the correct index
Anyone with any ideas??
Quote
Maynard Philbrook (Jamie) wrote:
> If your using D2 or 3 then you need to put the StdCall phrase in the
> declaration line
> along with the rest of it..
> procedure GetRadixLibVer(version:Pchar);external; StdCall  'RadixLib.DLL'
> index 1;

>  also take note that you are absolutly sure that this address is the at
> index 1 ?

> > void DLLAPI GetRadixLibVer(LPSTR sp);

> > In my unit I'm declaring the function as:
> > procedure GetRadixLibVer(version : PChar); pascal; external 'RadixLib'
> > index 1;

> > and I'm using it like this
> > var
> >   version : array[0..100] of char;
> > ...
> >   GetRadixLibVer(version);
> > ...

> > However, running this line makes an access violation in module
> > 'radixlib'

> > What have I done wrong???

Re:Trouble accessing a dll written in Visual C++


Make sure you are have ShareMem as the first unit you use in the Project's
.dpr file.

simon

Quote
?yvind Kolnes wrote:
> If anyone can help me out with this one, I'd be really thankful!

> I've got a dll written in Visual C++, with a function declared in the
> header as this:
> void DLLAPI GetRadixLibVer(LPSTR sp);

> In my unit I'm declaring the function as:
> procedure GetRadixLibVer(version : PChar); pascal; external 'RadixLib'
> index 1;

> and I'm using it like this
> var
>   version : array[0..100] of char;
> ...
>   GetRadixLibVer(version);
> ...

> However, running this line makes an access violation in module
> 'radixlib'

> What have I done wrong???
> (let me know if I've let out some important information)

Re:Trouble accessing a dll written in Visual C++


OK, I've put the ShareMem as the first unit in my Project-file (I had no idea
I had to do that, still learning.... thanks, Simon!), but I still get the very
same error. I thought that maybe the dll is lacking something similar, but
I've got a program written in VB which uses the dll with great success...
Quote
Simon wrote:
> Make sure you are have ShareMem as the first unit you use in the Project's
> .dpr file.

Re:Trouble accessing a dll written in Visual C++


null terminate the string?
ie
pass it as
pchar(<stringhere>+chr(0))
If the c dll is expecting a char * argument (rather than an explicit array
of chars) then
it may be performing some string library functions on there, and if there
are no null terminating
characters in your string then it will freak out and cause an access
viollation.

Re:Trouble accessing a dll written in Visual C++


I wonder if this is a compatibility problem with the DLL. Not all DLLs can be
used between C & Pascal because of differing methods of name resolution.
AIUI, you can even have problems using a C DLL from a C program under a
different compiler.
If this is the case, there's not much you can do about it, unless Delphi
supports this DLL's name resolutio method.

Has anyone ever had experience with this?

James

In article <907672958.29104.0.nnrp-06.d4e48...@news.demon.co.uk>,
  "MIGHTYMOONLORD" <q...@qwe.qwe> wrote:

Quote
> null terminate the string?
> ie
> pass it as
> pchar(<stringhere>+chr(0))
> If the c dll is expecting a char * argument (rather than an explicit array
> of chars) then
> it may be performing some string library functions on there, and if there
> are no null terminating
> characters in your string then it will freak out and cause an access
> viollation.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    

Other Threads