Web lists-archives.org

[Mingw-users] Creating a C DLL to be used with VB




Hi,
 
I'm a newbie in C and MinGw. I reserched the Net and I would like to ask the experts if this is the right procedure to make a C DLL to be used with VB6 for Windows with MinGw.
 
I create, for instance, a file mydll.c that looks as follows (with two functions): (example taken from http://www.emmestech.com/software/cygwin/pexports-0.43/moron2.html)
 
#include "mydll_dll.h"
#include <stdio.h>

EXPORT int equ( char *str1, char *str2 )
{
  if ((str1 == NULL)&&(str2 == NULL)) return (1);
  if ((str1 == NULL)&&(str2 != NULL)) return (0);
  if ((str2 == NULL)&&(str1 != NULL)) return (0);
  // Above since strcmp seems to have trouble operating on null strings.
  if  (strcmp( str1, str2 ) == 0) return (1);
  else return (0);
}

EXPORT char *func2(char *s1 )
{
  
  int i,k,dun;
  char *pos[80], *def, s3[80];
  
  strcpy( s3, s1);
  ....
  ....
}
Then I create a mydll_dll.h with the following:
#ifdef __cplusplus
     #define cppfudge "C"
#else
     #define cppfudge
#endif

#ifdef BUILD_DLL
     // the dll exports
     #define EXPORT __declspec(dllexport)
#else
     // the exe imports
     #define EXPORT extern cppfudge  __declspec(dllimport)
#endif

EXPORT int equ( char *str1, char *str2 ) ;
EXPORT char *func2(char *s1 ) ;
 
And I compile using:
 
gcc -DBUILD_DLL -c mydll.c
gcc --disable-stdcall-fixup -mdll -DBUILD_DLL -o junk.tmp -Wl,--base-file,base.tmp mydll.o
rm junk.tmp
dlltool --dllname mydll.dll --base-file base.tmp --output-exp temp.exp --input-def mydll.def
rm base.tmp
gcc --enable-stdcall-fixup -mdll -DBUILD_DLL -o mydll.dll mydll.o -Wl,temp.exp
rm temp.exp
 
Is this correct?
 
Kind regards,
 
Rui Fernandes
Porto - Portugal

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users