From: Anand, V. R <vai...@bo...> - 2004-06-02 23:24:17
|
Ted: Why would you want to use the Cygwin compiler at all ? If you have installed the MinGW package, then I would suggest that you use the MinGW compiler instead. Let's say you have functions func1.c,func2.c. Then you simply do the following (as per Mumit Khan's procedure): gcc -c -DBUILDING_DLL=3D1 -mrtd -g -O2 func1.c gcc -c -DBUILDING_DLL=3D1 -mrtd -g -O2 func2.c dllwrap -s --export-all --output-def myfuncs.def --driver-name gcc -o myfuncs.dll func1.o func2.o =20 The resulting DLL should be usable from VB. I have done just this to create DLL's that can be called from MS Excel inside a VB macro and the DLL works just fine, provided you declare the DLL functions correctly (return value and arguments) inside the macro using the Declare statement. Further, this approach works for DLL's created from both C and Fortran code; I was able to take the fftpack package from the Netlib collection and easily build it into an Excel-callable DLL and successfully use it inside VB. The only thing you have to be careful about is sending/receiving pointer-based data from the DLL. While this is easily handled in C, de-referencing pointers in VB is slightly roundabout and involves using the "RtlMoveMemory" function from kernel32.dll (it does the same job as memcpy()) and possibly the VarPtr() function inside VB. VB wasn't designed to allow easy pointer manipulation! Hope this helps. =20 Regards, =20 Anand -----Original Message----- From: Unnikumaran, Ted [mailto:ted...@mi...]=20 Sent: Wednesday, June 02, 2004 3:03 PM To: min...@li... Subject: [Mingw-users] Call Mingw DLL from a Visual Basic application =09 =09 My goal is to create a dll created in mingw that I can call from a Visual Basic application. The code was initially written on a Linux box and I'm trying to get it to work on Windows. It compiles in cygwin, but I would like to create a Visual Basic front end. =20 What I first did was the following: $gcc -shared -mrtd -mno-cygwin -o foo.dll foo.c =20 I was able to get foo.dll to work. However, I had problems using the -mno-cygwin flag when I tried to compile other components. =20 I read what Mumit Khan suggested and added his files to /usr/local/mingw, and then tried to compile again with "-mno-cygwin" flag with the -I/usr/local/mingw/include and the -L/usr/local/mingw/lib options. However, this still failed to fully compile. =20 I then installed mingw into c:/mingw and followed the directions in the FAQ - "How do I use MinGW with Cygwin?" =20 However, I'm not too sure what options to give my gcc compiler. Do I just get rid of the -mno-cygwin flag? I tried that and the simplest case of foo.dll now doesn't work. It compiles, but when I try to use it from the VB application, it crashes. =20 I then tried to follow the directions in the FAQ "How can an MSVC program call a MinGW DLL, and vice versa?" What I did was run the following commands: $gcc -shared -o foo.dll foo.c -Wl,--output-def,foo.def,--out-implib,libfoo.a $lib /machine:i386 /def:foo.def $cl foo.c foo.lib =20 This creates the file foo.exe and foo.obj. The exe works, and I can execute it from the command line. However, I want a dll that I can call from a VB program. The dll that is created using the above 3 steps depends on cygwin1.dll, and even with it doesn't seem to work, as it crashes my VB program. =20 Any suggestions would be appreciated. =20 Thanks, Ted =20 |