Mail Archives: cygwin/2003/06/05/09:04:03
Thanks to all who replied. In case anyone is interested, through
experiments, here is what I found with passing strings from VB .NET to my
cygwin dll.
In my vb code, I changed the declaration of the dll function to:
Declare Function myTest Lib
"c:\cygwin\home\Administrator\test_dll\test.dll" (ByVal s1 As Char(), ByVal
i1 As Long) As Integer
Then, I get a character array (declared as Char( )) from my original string
calling ToCharArray(). Example:
Dim test As String
Dim charArray As Char()
.
.
test = "my string"
charArray = test.ToCharArray(0, test.Length())
Then call the dll function passing the variable "charArray" as the character
paramemeter.
LibWrap.myTest(charArray, x)
Note that the Char( ) appears to be an array of 16 bit characters that
accommodates Unicode. The default marshaling appears to convert this to an
8 bit null terminated character string (char *) in my C dll. To preserve
Unicode, you probably declare your function with Short( ) variable and
convert the character array to a short array before calling the dll
function. Of course this implies changing the DLL function signature and
implementation.
I don't know if this is the prescribed way to handle this. But thought I
would share what I found.
Tom
-----Original Message-----
From: cygwin-owner AT cygwin DOT com [mailto:cygwin-owner AT cygwin DOT com]On Behalf Of
Danny Smith
Sent: Wednesday, June 04, 2003 7:21 PM
To: thoban AT verbalogic DOT com
Cc: cygwin AT cygwin DOT com
Subject: Re: Calling gcc built DLL from .NET (Visual Basic)
From: "Thomas X. Hoban" <thoban at verbalogic dot com>
----------------------------------------------------------------------------
----
> Does anyone have a good example that shows how to create a DLL using
> cygwin/gcc and call it using VB .NET? I am specifically interested in an
> example that shows how to pass a String variable. In the example that I
> show below, I am able to call a C function. I can successfully pass a
long
> integer. But the string that I pass shows garbage in the called function.
>
> My dll code looks like...
>
>
> (test.c)
>
> #include <stdio.h>
> #include <wtypes.h>
>
> define EXPORT __declspec(dllexport)
>
> EXPORT int myTest(char *s1, long i1) {
>
> printf("Here is the string %s, here is the integer %ld.\n",s1, i1);
>
> }
>
>
I think VB wants stdcall symbols. Add WINAPI to above..
>
> I then compile as follows:
>
> $ gcc -c test.c
> $ gcc -shared -o test.dll test.o
and -Wl,--add-stdcall-alias when building dll to get undecorated symbol too.
I don't have a clue about char* -> STRING marshalling. I would have just
used
BSTR.
Danny
http://mobile.yahoo.com.au - Yahoo! Mobile
- Check & compose your email via SMS on your Telstra or Vodafone mobile.
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
- Raw text -