create ATL dll using C++ .NET 2003

Hi,

I need help for a problem.

I am trying to creat a ATL dll using C++ (VC7) from .NET 2003 and access the dll from C#.

New Project -> ATL Project -> Add Class (ATL Simple Object) -> Add a Method to the interface.

I want to send a number to the dll which manipulates it and returns it back to the C#

The problem is the out, retval field in the Add Method field are disabled (in the Add Method tab). I try to manually add them in the files.

[id(2), helpstring("method myatlp2")] HRESULT myatlp2(float a, [out,retval]float *b);

It gets compiled but in my C# I can only see - myatlp2(float a)    ( I've tried add reference from both COM and NET wrapper)

Any thoughts

 

Thanks,



Answer this question

create ATL dll using C++ .NET 2003

  • George2

    This is normal, the [out,retval] IDL attributes specifies the function return value that the COM client sees. For example:
    IDL: HRESULT myatlp2(float a, [out,retval] float* b) => C#: float myaltp2(float a)
    IDL: HRESULT myatlp2(float a, float b) => C#: void myatlp2(float a, float b)

    The out and retval checkboxes in the Add Method wizard will be disabled until you pick a pointer parameter type. If you type "float" by hand, you'll see them enabled as soon as you type "*".



  • The_Postman

    If you want to do it that way then declare it like this:
    IDL: HRESULT myatlp2(float a, [in,out] float* b) => C#: void myatlp2(float a, ref float b);
    or
    IDL: HRESULT myatlp2(float a, [out] float* b) => C#: void myatlp2(float a, out float b);




  • LPastor

    thanks, nobugz

    but as in your reply:

    IDL: HRESULT myatlp2(float a, [out,retval] float* b) => C#: float myaltp2(float a)

    how would I get the reyurn value in C#

    I expect to use ref b in C# to get the return value:

    myatl1.Cmyatlclass1Class d = new myatl1.Cmyatlclass1Class();

    d.myatlp2(a, ref b);

    but C# only see - float myaltp2(float a)

    Thanks


  • create ATL dll using C++ .NET 2003