public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* using an MSVC C DLL with Cygwin gcc
@ 2012-08-18  1:33 Daniel Brown
  2012-08-18  1:46 ` Daniel Colascione
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Brown @ 2012-08-18  1:33 UTC (permalink / raw)
  To: cygwin

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: using an MSVC C DLL with Cygwin gcc
  2012-08-18  1:33 using an MSVC C DLL with Cygwin gcc Daniel Brown
@ 2012-08-18  1:46 ` Daniel Colascione
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Colascione @ 2012-08-18  1:46 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 150 bytes --]

On 8/17/2012 5:45 PM, Daniel Brown wrote:
>     for(i=0;i<10;i++)
>         printf("%d\n", b[i]);
                 ^^^^^^

You want %g or %f.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 259 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-08-18  0:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-18  1:33 using an MSVC C DLL with Cygwin gcc Daniel Brown
2012-08-18  1:46 ` Daniel Colascione

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).