CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2008
    Posts
    2

    Cannot marshal class array in function

    I am getting an error in visual basic.net code when calling a function that returns an array of classes from the dll compiled in managed C++


    Error:
    "An unhandled exception of type 'System.Runtime.InteropServices.MarshalDirectiveException' occurred in toolbartest.exe

    Additional information: Can not marshal return value."

    **********
    C Code:
    **********

    #using <mscorlib.dll>
    public __gc class gwindow {
    public:
    System::Int64 hwnd;
    System::Int64 ipid;
    System::String *szWindowText;
    System::String *szClassText;
    System::String *szExecFile;
    };


    gwindow *__declspec(dllexport) foo() __gc [];

    gwindow * wn = new gwindow();
    wn->hwnd = (System::Int64)(tempWind->hwnd);
    wn->ipid = (System::Int64)(tempWind->pid);
    arr->Add(wn);

    gwindow *gwindows __gc [];
    gwindows =
    static_cast<__gc class gwindow * []>(arr->ToArray(__typeof( __gc class gwindow)));

    return (gwindows);



    *************
    VB Code:
    *************

    Public Class gwindow
    Dim hwnd As Int64
    Dim ipid As Int64
    Dim szWindowText As String
    Dim szClassText As String
    Dim szExecFile As String
    End Class

    <DllImport("library.dll")> _
    Friend Shared Function foo() As gwindow()
    End Function

  2. #2
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: Cannot marshal class array in function

    You don't need to use DllImport : this is for interfacing with native c++ classes.

    Just add your dll as a reference to your VB.NET project and you get access to all 'public' __gc classes in it directly.

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  3. #3
    Join Date
    Mar 2008
    Posts
    2

    Talking Re: Cannot marshal class array in function

    I see. I never tried that before but i hope it works. Thank you so much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured