c# - WCF Com Interop GetRecordInfoFromGuids Returns Old Format Or Invalid Type Library -
i have struct in wcf service defined in c# as
[datacontract] [structlayout(layoutkind.sequential), serializable] [comvisible(true)] public struct mydata { [datamember] public int data1; [datamember] public string data2; } from mfc app trying create safearray of struct. when calling getrecordinfofromguids this
hr = getrecordinfofromguids(libid_mylib, 1, 0, locale_user_default, __uuidof(mydata), &pri); i getting return value of
0x80028019 old format or invalid type library. what wrong this?
i managed fix , found 3 or 4 identical questions searching google , none of them had answer, thought update mine 1 did have solution.
it turned out string data member being marshalled default lpstr. never occurred me might problem , in fact there no documentation state might be. when passed single object there no problem. however, turns out when passing array of these objects string member must marshalled bstr. otherwise error in getrecordinfofromguids type library not valid. there no documentation hints reason why call returns type library not valid. merely trial , error found problem.
so above code needed altered this
[datacontract] [guid("xxx")] [structlayout(layoutkind.sequential), serializable] [comvisible(true)] public struct mydata { [datamember] public int data1; [datamember] [marshalas(unmanagedtype.bstr)] public string data2; } now getrecordinfofromtypeinfo succeeds , can create , pass data successfully.
Comments
Post a Comment