Subject: RE: GCC and Visual Basic
From: [email-masked] (Kevin Healey)

2 Jul 1998 08:26:45 -0700
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
To: [email-masked]

Well, actually I'm trying access my DLL from Visual Basic for Excel 97.  I
have also tried to access it from PowerBuilder (which I believe uses the
same calling convestions as VB).

The main problem seems to be that the DLL is not loading properly.  The
error that I get from Visual Basic is:

"Run-time error '7': File not found: bar"

The error that I am getting from PowerBuilder is:

"Error opening DLL library bar.dll for external function."

These are the same errors that I get if the DLL (bar.dll) is not in the DOS
PATH.  However, I am ABSOLUTLY certain that the DLL in is the DOS PATH.  It
is also interesting to know that these are the same errors I get if I
replace the DLL with a non-DLL file - like a text file.

These are not the errors that I get from a "good" DLL if the function is
spelled incorrectly or its name has been mangled.

Its as if the system doesn't think that bar.dll is really a DLL, or there
is something wrong with the way the DLL was compiled.

Furthermore, I HAVE been able to access the functions in bar.dll from an
executable that was complided with GCC!

So here are the steps that I have taken to create my dll (remember that I
am using mingw32):

1) Create DLL source:
===> bar.c <========================================
//Testing the creation of a DLL

#include <windows.h>

int WINAPI doit (int i)
{
     return(i + 10);
}

2) Create .DEF  file:
===> bar.def <======================================
EXPORTS
doit=doit@4
==================================================

Notice here that I have exported the function name "doit" for the internal
function name "doit@4".  The @4 comes from using the STDCALL calling
convension (or WINAPI).  I have done it this way because this is the only
way I have been able to get an executable to link to the DLL with GCC.

3) Run shell script to create the DLL (stright off of Colin Peter's Web
Page):
===> makedll <======================================
#create bar.o
gcc -c bar.c

#create base.tmp (and junk.tmp which is then deleted)
gcc -mdll -o junk.tmp -Wl,--base-file,base.tmp bar.o
rm junk.tmp

#create temp.exp
dlltool --dllname bar.dll --base-file base.tmp --output-exp temp.exp --def
bar.def

#crete bar.dll
gcc -mdll -o bar.dll bar.o -Wl,temp.exp

#delete temp.exp because we don't need it anymore
rm temp.exp
===================================================

This will create bar.dll that can be linked to a GCC compiled executable as
follows:

1) Create source:
===> main.c <======================================
// Main file to try linking with a DLL under mingw32

int
main()
{
        printf("doit(5) returns %d\n", doit(5));
}
====================================================

2) Run shell script to create main:
===> main.def <======================================
#create main.o
gcc -c main.c

#create libbar.a (import library for bar.dll)
dlltool --dllname bar.dll --def bar.def --output-lib libbar.a

#create main.exe using libbar.a
gcc -o main.exe main.o -lbar
====================================================

So, why can't I call doit() from my Visual Basic application?

Sergey Okhapkin <[email-masked]> on 06/30/98 12:35:22 PM

To:   "[email-masked]" <[email-masked]>, Kevin Healey/CACI
cc:
Subject:  RE: GCC and Visual Basic

Kevin Healey wrote:
> I have compiled from both the full Cygwin GNU-WIN32 and MINGW32.  I have
> been able to create a DLL that I can link with other GCC compiled
> executables.  But I can't get the DLL to work with VB.
>

What does "can't get the dll to work with VB" mean?

--
Sergey Okhapkin, http://www.lexa.ru/sos
Moscow, Russia

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".