delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2003/06/03/17:24:06

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
From: "Thomas X. Hoban" <thoban AT verbalogic DOT com>
To: <cygwin AT cygwin DOT com>
Subject: Calling gcc built DLL from .NET (Visual Basic)
Date: Tue, 3 Jun 2003 16:21:25 -0500
Message-ID: <DLEPIMCBMLJEPMIPNAEDMEEACAAA.thoban@verbalogic.com>
MIME-Version: 1.0
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
Importance: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165

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 then compile as follows:

$ gcc -c test.c
$ gcc -shared -o test.dll test.o

(I have also tried several combinations of linking and compiling with
different options).

In my Visual Basic .NET console application, I create a class that wraps the
"myTest" function and then call it from main as follows:

Public Class LibWrap
    Declare Function myTest Lib
"c:\cygwin\home\Administrator\test_dll\test.dll" (ByRef s1 As String, ByVal
i1 As Long) As Integer
End Class
Module Module1

    Sub Main()
        Dim test As String
        test = "My String"
        LibWrap.myTest(test, 6432)
        LibWrap.myTest(test, 20)
        LibWrap.myTest(test, 3000)
    End Sub

End Module

I also modified the "path" environment variable so vb finds the class path
to cygwin.

As I mentioned, I am able to pass integers successfully, but strings don't
seem to get marshaled to (char *).  I recognize that the .NET String
implementation is different, but thought the .NET marshaling would take care
of conversion.  A simple working example would be extremely helpful.

Thanks


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


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019