471,348 Members | 1,150 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

MarshalDirectiveException: marshaling fixed array


I have IDL-file:

const byte DataStrLen = 255;

#pragma pack(1)
typedef struct
wchar_t fDataStr[DataStrLen];
} tSomeData;
#pragma pack()

interface ISomeData : IUnknown
tSomeData* getDataPtr();

I trying to reproduce it in managed c++:

const Byte DataStrLen = 255;

[StructLayout(LayoutKind::Sequential, Pack = 1, CharSet =
public value struct tSomeData
[MarshalAs(UnmanagedType::ByValTStr, SizeConst = DataStrLen)]
String ^fDataStr;

[InterfaceType(ComInterfaceType::InterfaceIsIUnknow n)]
public interface class ISomeData
tSomeData* getDataPtr();

public ref class SomeData : public ISomeData
SomeData ()
m_tSomeData = gcnew tSomeData;
m_tSomeData->fDataStr= "ABC";

virtual tSomeData* getDataPtr()
pin_ptr pinPtr = &*m_tSomeData;
return pinPtr;

tSomeData ^m_tSomeData;

After processing in tlbexp.exe I use tlb-file in test application:

#import "SomeData.tlb" no_namespace raw_interfaces_only

int _tmain(int argc, _TCHAR* argv[])
if (FAILED(hr))
return -1;

hr = ::CoCreateInstance(__uuidof(SomeData), NULL,
tSomeData *pSomeData = spSomeData->getDataPtr(); // !!!
MarshalDirectiveException !!!
catch (...)

return 0;

When I run test following error occurred while determining how to
marshal the parameters of member 'getDataPtr' of type
"System.Runtime.InteropServices.MarshalDirectiveEx ception: Cannot
marshal 'parameter #4294967295': Pointers cannot reference marshaled
structures. Use ByRef instead. This is most likely due to an
incompatible MarshalAs attribute on one of the parameters."

Where is error? What shall i do to implement such component?
Jun 27 '08 #1
0 1406

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Nikolay Petrov | last post: by
3 posts views Thread by Stephen Gennard | last post: by
3 posts views Thread by Rudy Velthuis | last post: by
2 posts views Thread by Thomas Kent | last post: by
2 posts views Thread by Pas de Spam | last post: by
4 posts views Thread by Bjarne Nielsen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.