This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Runtime GNU-DLL with MSVC


There is a binary incompatibility between MSVC 4.2 & 5.0 . This bit the 
last project I was on a couple times. Hence my question: in the FAQ it 
states that MSVC & gcc objects can be mixed (I know that's not exactly 
what's happening here, but it's close); Was this determined with MSVC 4.2 ? 
I saw this problem before using an executable built with 4.2 and a DLL from 
5.0. What it amounted to was that the two use different calling conventions 
for DLLs, so the executable would think that the function in the DLL 
cleaned up the stack but the DLL thought the caller would do it, or maybe 
it was the other way around. In any case, the solution was to build 
EVERYTHING with MSVC 5.0 . Not elegant, but then again I don't think having 
that kind of binary incompatibility was either.

Hope this helps!
Terry

-----Original Message-----
From:	ISGStuttgart
Sent:	Wednesday, February 11, 1998 8:26 AM
To:	GNU-Win32
Subject:	Runtime GNU-DLL with MSVC

Hallo,

we have the following problem:
We want to use a DLL (generated with gnu-win32) with a program generated
with MSVC 5.0.
We can load the library and we can get the ProcAdress of the function in
the DLL. By calling the function the program crashes. Compiling the same
program with gnu-win32 the program works fine. We tried all byte
allignments in MSVC, but nothing happens.

Here's what we've done:

--------------------------------------------------------------------------
// ***** File foo.c *****
--------------------------------------------------------------------------

// Test file to check out building DLLs with gnuwin32
// This uses printf from the std lib


#include <stdio.h>


//* function declarations: ***
int doit (int i);

int doit (int i)
{
  printf("In foo.c inside of doit with printf\n");
  return( 4 );
}

--------------------------------------------------------------------------
// ***** File init.c *****
--------------------------------------------------------------------------

#include <windows.h>

extern int WINAPI dll_entry (HANDLE h, DWORD reason, void *ptr);

int WINAPI dll_entry (HANDLE h,
DWORD reason,
void *ptr)
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
return 1;
}

--------------------------------------------------------------------------
//***** file fixup.c ******
--------------------------------------------------------------------------

/* This is needed to terminate the list of import stuff */
/* Copied from winsup/dcrt0.cc in the cygwin32 source distribution. */
asm(".section .idata$3\n" ".long 0,0,0,0, 0,0,0,0");

--------------------------------------------------------------------------
// **** File foo.def ****
--------------------------------------------------------------------------

EXPORTS
        doit            @1
        dll_entry@12    @2

--------------------------------------------------------------------------
// Main file to try linking with a DLL under gnuwin32
--------------------------------------------------------------------------

// Updated to load dll at runtime (as opposed to loadtime), using
// win32 dll load functions
#include <stdio.h>
#include <windows.h>

int (*doitptr)(int); // pointer to the doit routine

int
main()
{

char filename[]="foo.dll";
HINSTANCE dllhandle; // handle to the dll

// Load the dll into memory:
if( (dllhandle = LoadLibraryExA(filename, NULL,
LOAD_WITH_ALTERED_SEARCH_PATH ))
== NULL){
printf("Error, Could not load %s\n",filename);
exit(0);
}

doitptr = GetProcAddress(dllhandle, "doit");
if( doitptr == NULL){
printf("Error, Could not load doit symbol\n");
}
printf("doit(5) returns %d\n", (*doitptr)(5));

}

--------------------------------------------------------------------------
#Compile and Link Sequence for foo.dll
--------------------------------------------------------------------------

gcc -g -c foo.c
gcc -c init.cc
gcc -c fixup.c

# Link DLL.
ld --base-file foo.base --dll -o foo.dll foo.o init.o fixup.o \
$LIBPATH/libcygwin.a -e _dll_entry@12
dlltool --as=as --dllname foo.dll --def foo.def --base-file foo.base
--output-exp foo.exp
ld --base-file foo.base foo.exp --dll -o foo.dll foo.o init.o fixup.o \
$LIBPATH/libcygwin.a -e _dll_entry@12
dlltool --as=as --dllname foo.dll --def foo.def --base-file foo.base
--output-exp foo.exp
ld foo.exp --dll -o foo.dll foo.o init.o fixup.o\
$LIBPATH/libcygwin.a -e _dll_entry@12


--------------------------------------------------------------------------
# Generating main
--------------------------------------------------------------------------
gcc -g main.c -o main.exe

Gerd from ISGStuttgart
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]