This is the mail archive of the cygwin 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]
Other format: [Raw text]

using an MSVC C DLL with Cygwin gcc


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];

    for(i=0;i<10;i++)
        a[i] = i+1;

array_read_write(a, b, 10);

    for(i=0;i<10;i++)
        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.

Thanks,
Daniel


-- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple


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