Exporting Managed Code as Flat API to Unmanaged World

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Saad

    Exporting Managed Code as Flat API to Unmanaged World

    Hi,

    I have a MC++dll, whose functions i want to use in unmanaged c++. I
    read that one of the ways to use the managed functions in unmanaged
    world is by exposing the managed api as flat api.
    I tried that and with simple data types it worked. But now i need to
    export a function which needs to take a gc struct as parameter, and
    then fill some values in it, and then the unmanaged c++ will use that
    info.

    Here's what i did

    //My gc struct
    [StructLayout(La youtKind::Seque ntial,CharSet=C harSet::Ansi)]
    public __gc struct STLayout {
    public:
    [MarshalAs(Unman agedType::LPTSt r)]
    String* ID;
    };
    //End

    Now i'm trying to export this through a funtion like this:-

    __declspec(dlle xport) int
    ExportL([MarshalAs(Unman agedType::Struc t)]STLayout*& Layout)

    And when i compile this dll. i'm getting the following error:-

    error C3395: __declspec(dlle xport) cannot be applied to a function
    with the __clrcall calling convention

    Now im stuck....
    what i dont understand is that

    1) why isn't the MarshalAs attribute working here.....
    2) What is the preferred way of exporting the managed types to c+
    +....other than the COM interop, mixed-mode solutions......

    Any other ideas...

    Thanks in advance...
    Saad
  • Massood

    #2
    Re: Exporting Managed Code as Flat API to Unmanaged World

    On Sep 26, 2:21 pm, Saad <saadthel...@gm ail.comwrote:
    Hi,
    >
    I have a MC++dll, whose functions i want to use in unmanaged c++. I
    read that one of the ways to use the managed functions in unmanaged
    world is by exposing the managed api as flat api.
    I tried that and with simple data types it worked. But now i need to
    export a function which needs to take a gc struct as parameter, and
    then fill some values in it, and then the unmanaged c++ will use that
    info.
    >
    Here's what i did
    >
    //My gc struct
    [StructLayout(La youtKind::Seque ntial,CharSet=C harSet::Ansi)]
    public __gc struct STLayout {
    public:
    [MarshalAs(Unman agedType::LPTSt r)]
    String* ID;};
    >
    //End
    >
    Now i'm trying to export this through a funtion like this:-
    >
    __declspec(dlle xport) int
    ExportL([MarshalAs(Unman agedType::Struc t)]STLayout*& Layout)
    >
    And when i compile this dll. i'm getting the following error:-
    >
    error C3395: __declspec(dlle xport) cannot be applied to a function
    with the __clrcall calling convention
    >
    Now im stuck....
    what i dont understand is that
    >
    1) why isn't the MarshalAs attribute working here.....
    2) What is the preferred way of exporting the managed types to c+
    +....other than the COM interop, mixed-mode solutions......
    >
    Any other ideas...
    >
    Thanks in advance...
    Saad
    As I know, functions with managed types cannot be exported as flat
    API. Maybe I'm wrong(??).
    But you can pass the struct members separately as simple data type
    variables to the function, or you can try an unmanaged struct
    corresponding the managed one, and then convert it to a managed one
    inside the function.

    Comment

    Working...