X-Recipient: archive-cygwin@delorie.com
X-SWARE-Spam-Status: No, hits=-4.2 required=5.0	tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,KHOP_RCVD_TRUST,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE
X-Spam-Check-By: sourceware.org
Message-ID: <502EE59A.4080805@gmail.com>
Date: Sat, 18 Aug 2012 01:45:14 +0100
From: Daniel Brown <danielbrown87@gmail.com>
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20120713 Thunderbird/14.0
MIME-Version: 1.0
To: cygwin@cygwin.com
Subject: using an MSVC C DLL with Cygwin gcc
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

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

