using an MSVC C DLL with Cygwin gcc

Daniel Brown
Sat Aug 18 01:33:00 GMT 2012

Hi all,

So I have a C dll written in MSVC which is being called by a Cygwin 
programmed compiled with gcc. So far it all works ok apart from when I 
try and pass an array that the dll should then change. For example I 
have this in the dll:

__declspec(dllexport) void array_read_write(double *src, double *dest, 
size_t length){
     int i;

     for(i=0; i<length; i++){
         dest[i] = src[i];

When I call this from my Cygwin program I pass the src array as 
1,2,3...10 and then print the output.

  int main(){
     int i;
     double a[10],b[10];

         a[i] = i+1;

     array_read_write(a, b, 10);

         printf("%d\n", b[i]);

I compile the program by calling

  gcc test.c -L. -lmydll

The dll is a Win32 one just a normally compiled through VS2010. The 
output I get is all 0's in b[].

Am I correct in assuming that the dll and program share the same address 
space so should both be able to access each others memory? When 
attaching a debugger to the program, the dll can correctly read the 
input array values (1,2,3,4,...10) and watching the destination array 
also shows it changing value. It is only once it returns to the program 
that b[] goes back to being all 0's. Am I doing something obviously 
wrong here?

Searching around I found a lot of previous questions about using Cygwin 
DLL's in MSVC, not so much the other way around.


Problem reports:
Unsubscribe info:

More information about the Cygwin mailing list