0

I have a class in C#

public class RequestInfo
{
    public string barcode { get; set; }
    public string title { get; set; }
    public string name { get; set; }
}

I am calling a C# function from C++

TResult.RequestInfo RequestInfo();

I registered the C# using REGASM which created a TLB file and on C++ compile I get a TLH file.

RequestInfo in C++ is shown as follows in the generated TLH file:

struct __declspec(uuid("e2e15930-fd1a-31de-a166-bf330e327677"))
/* dual interface */ _RequestInfo;

and the C# function as follows in the TLH File:

  virtual HRESULT __stdcall RequestInfo (
    /*[out,retval]*/ struct _RequestInfo * * pRetVal ) = 0;

I call the C# function from C++ as follows:

_RequestInfo *info;
pICS->RequestInfo(&info);

The function is called and no errors generated; however:

  1. I do not know if I am defining the info variable correctly
  2. I do not know how to read the info variable with the data that the C# function filled.

Help Please!

  • 1
    Looks right so far. You can look at the generated TLH to see what the RequestInfo class looks like on the C++ side. Probably something use something like info->GetName( &name ); and name would be a BSTR type – Joel Lucsy Jul 23 '18 at 16:47
  • The #import directive you used also generated a TLI file to make this easier to write. And smart pointers that take care of the memory management, `_RequestInfoPtr` for this one. Can't really ignore `_com_error`, the exception that is raised when a call fails. The essential landing page for these auto-generated declarations and support classes [is here](https://msdn.microsoft.com/en-us/library/h31ekh7e.aspx). – Hans Passant Jul 23 '18 at 17:40
  • the problem is that i have (in TLI file) define inline _bstr_t IRequestInfo::Getbarcode ( ) BUT the return value of the RequestInfo is _RequestInfoPtr – Evan Camilleri Jul 24 '18 at 10:33

0 Answers0