Board index » delphi » Calling a Delphi DLL from VBA?

Calling a Delphi DLL from VBA?

Hi to all Dephians

Has anyone had a go at calling a DLL created in Delphi from VBA?

I will elaborate on my problem. I have created a form which displays
customer addresses stored in a Paradox table. The idea is that someone using
Word can access this form, select the appropriate customer and have the
address inserted into the Word Document.

I have only managed to get the form displayed in Word but have not yet
retrieved the data so that I can insert it into the document. The procedure
contained in the DLL which is used to access the form is declared as
follows:

  procedure InsertCustomer(Address: PChar; AddressLength: Integer); Export;
StdCall;

Calling this routine should result in the address being passed in the
Address variable.

I think my problems stem from converting the different types between Delphi
and VBA.

Thank you  in advance!

Kevin Parsons.

 

Re:Calling a Delphi DLL from VBA?


Allocate the memory in VB by using a string variable and setting it's size
using String$(" ", <strlen>)...

When you declare the function in VB, do it like so...

declare sub InsertCustomer lib "<dllname>" (ByVal lpszAddress as string,
ByRef lpcbAddress as Long)

Then, when calling the function, limit the string length using the following
line after the call is completed:

<stringvar--address> = Left$(<stringvar--address>, <longvar--size>)

By the way, you may want to return a value from your procedure/function to
indicate success or failure, so the caller will know whether the variable
contains a valid address...

If you need more help, let me know.

Kelly Leahy
schut...@yahoo.com

Kevin Parsons D??? ???Y??
<6rmgcd$3r...@nclient1-gui.server.{*word*269}.net> ...

Quote
>Hi to all Dephians

>Has anyone had a go at calling a DLL created in Delphi from VBA?

>I will elaborate on my problem. I have created a form which displays
>customer addresses stored in a Paradox table. The idea is that someone
using
>Word can access this form, select the appropriate customer and have the
>address inserted into the Word Document.

>I have only managed to get the form displayed in Word but have not yet
>retrieved the data so that I can insert it into the document. The procedure
>contained in the DLL which is used to access the form is declared as
>follows:

>  procedure InsertCustomer(Address: PChar; AddressLength: Integer); Export;
>StdCall;

>Calling this routine should result in the address being passed in the
>Address variable.

>I think my problems stem from converting the different types between Delphi
>and VBA.

>Thank you  in advance!

>Kevin Parsons.

Re:Calling a Delphi DLL from VBA?


Your problem is a simple one.
 in the Win32 you can no longer have applications use a pointer to a
Data areas of a DLL file to obtain strings ect,.,.,.
  The OS sets up a very simple 256 byte block area that gets randomly
used when DLLS return a pointer to a string, the OS will copie up to
256 bytes into this short structure then change the pointer to actully
point to the global memory block..
 what may work better for you is to use a globel memory chunk and pass the
address that back.
 or you can use the in memory File system interchanging chunks of
memory between apps and DLL's
 in Win32, the Data of and DLL is not accessible to apps, what you will get
would be garbage, all DLL's get there own Virtual Data space as so do the
Applications.
 using a memory file which just passes back a pointer is the best way.
 in the example of a DLL file that comes with your D compiler, they have an

whole explenation of this problem..
  Your best bet would be to use the memory file or allocate a chuck of
moveable Globel memory..

Quote

>   procedure InsertCustomer(Address: PChar; AddressLength: Integer);
Export;
> StdCall;

> Calling this routine should result in the address being passed in the
> Address variable.

> I think my problems stem from converting the different types between
Delphi
> and VBA.

> Thank you  in advance!

> Kevin Parsons.

Re:Calling a Delphi DLL from VBA?


In article <01bdce50$6c7d52e0$394f36d1@default>, Maynard Philbrook
(Jamie) (ja...@{*word*104}zone.net) says...

Quote
> Your problem is a simple one.
>  in the Win32 you can no longer have applications use a pointer to a
> Data areas of a DLL file to obtain strings ect,.,.,.
>   The OS sets up a very simple 256 byte block area that gets randomly
> used when DLLS return a pointer to a string, the OS will copie up to
> 256 bytes into this short structure then change the pointer to actully
> point to the global memory block..

Wrong.

M.

--
Ettertraktet kaffe, er det ekstra god kaffe?
mailto:martin.lars...@delfidata.no.NOSPAM
http://www.delfidata.no/users/~martin

Other Threads