Guest User

Untitled

a guest
Jan 16th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. HRESULT GetList([in,out] SAFEARRAY(struct MyStruct)* myStructs);
  2. // I have also tried with [out] instead of [in, out]
  3.  
  4. [uuid(628913FC-CC26-1654-472F-0B70CC39DEE0)]
  5. struct MyStruct
  6. {
  7. int myInt;
  8. DOUBLE myDouble;
  9.  
  10. };
  11.  
  12. STDMETHODIMP MyClass::GetList(SAFEARRAY** myStructs)
  13. {
  14. SAFEARRAY* psa = *myStructs;
  15. SAFEARRAYBOUND sab = {someSize, 0};
  16. MyStruct *pData;
  17. IRecordInfo *pRI;
  18. HRESULT hr;
  19.  
  20. hr = GetRecordInfoFromGuids(LIBID_MyCOMLib, 1, 0, 0x409, __uuidof(MyStruct), &pRI);
  21. psa = SafeArrayCreateEx(VT_RECORD, 1, &sab, pRI);
  22. pRI->Release();
  23. pRI = NULL;
  24. hr = SafeArrayAccessData(psa, (void**)&pData);
  25. for (size_t i = 0; i < someSize; i++)
  26. {
  27. pData[i].myInt = someInt;
  28. pData[i].myDouble = somedouble;
  29. }
  30. hr = SafeArrayUnaccessData(psa);
  31.  
  32. return S_OK;
  33. }
  34.  
  35. Option Strict
  36. ...
  37. <MarshalAs(UnmanagedType.SafeArray, safearraysubtype:=VarEnum.VT_RECORD)>
  38. Private m_List As MyStruct()
  39.  
  40. Private Sub btnGetList_Click(sender As System.Object, e As System.EventArgs)
  41. Dim m_List() As MyStruct
  42. m_ComObject.GetList(m_List)
  43.  
  44. ' I have tried several other things, getting different errors with each of them'
  45. 'm_ComObject.GetList(CType(m_List, Array))'
  46.  
  47. 'Dim structs() As MyStruct'
  48. 'Dim arr as System.Array = structs '
  49. 'm_ComObject.GetList(arr)'
  50.  
  51. For Each o In cortes
  52. Dim s As MyStruct = CType(o, MyStruct)
  53. MsgBox(s.myInt)
  54. Exit For
  55. Next
  56. End Sub
  57.  
  58. Dim m_List() As SceneCutInfo
  59. m_ComObject.GetList(m_List)
  60.  
  61. Dim m_List() As MyStruct
  62. m_ComObject.GetList(m_List)
Add Comment
Please, Sign In to add comment