473,386 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

MarshalDirectiveException: marshaling fixed array

Hi!

I have IDL-file:

const byte DataStrLen = 255;

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

[
object,
uuid(...),
pointer_default(unique),
local
]
interface ISomeData : IUnknown
{
tSomeData* getDataPtr();
};

I trying to reproduce it in managed c++:

const Byte DataStrLen = 255;

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

[ComVisible(true)]
[Guid("...")]
[InterfaceType(ComInterfaceType::InterfaceIsIUnknow n)]
public interface class ISomeData
{
[PreserveSig]
tSomeData* getDataPtr();
};

[ComVisible(true)]
[Guid("...")]
[ClassInterface(ClassInterfaceType::None)]
public ref class SomeData : public ISomeData
{
public:
SomeData ()
{
m_tSomeData = gcnew tSomeData;
m_tSomeData->fDataStr= "ABC";
}

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

private:
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[])
{
HRESULT hr = ::CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hr))
return -1;

try
{
CComPtr<ISomeDataspSomeData;
hr = ::CoCreateInstance(__uuidof(SomeData), NULL,
CLSCTX_INPROC_SERVER,
__uuidof(ISomeData),
(void**)&spSomeData);
tSomeData *pSomeData = spSomeData->getDataPtr(); // !!!
MarshalDirectiveException !!!
}
catch (...)
{
}

::CoUninitialize();
return 0;
}

When I run test following error occurred while determining how to
marshal the parameters of member 'getDataPtr' of type
'SomeData.ISomeData':
"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 1525

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nikolay Petrov | last post by:
Guys, please help. I am trying to make this work from at least 4 months. I am new to programming and some things are difficult to me, but I really need to make my project work. I can't find...
3
by: Stephen Gennard | last post by:
Hello, I having a problem dynamically invoking a static method that takes a reference to a SByte*. If I do it directly it works just fine. Anyone any ideas why? I have include a example...
3
by: Rudy Velthuis | last post by:
Hello, Does anyone know how to create a struct that will marshal to the following C++ struct A, containing an array of the user defined String10 type: struct String10 { char SLen; char S;
2
by: Thomas Kent | last post by:
I have a dll that is expecting a 3x3 array which I'm am using DllImport to access. In addition, this array is located in a struct that is getting passed. I'm having problems that I think are...
0
by: Jeff | last post by:
Hi guys Mattias, thanx for answering my last question Well, I'm struggling with marshaling a struct that has **ptr to an array of arrays of struct. Why? I'm stuck with it 1. I need to know...
2
by: Pas de Spam | last post by:
Hi, I have some problem in marshaling array of structure. I have to exchange a structure of data with a C++ program. This structure data contains a field which is an array of a custom type. I...
6
by: Tom | last post by:
I'm trying to pass this structure to a dll: <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=1)> _ Public Structure udtINTER01 <VBFixedString(8),...
4
by: Bjarne Nielsen | last post by:
Hi all From a C# program, I need to call an unmanaged (C++) dll. The dll fills an array with variables and returns that to the C# program. When I have a fixed sized array, this works fine by...
0
by: kishor14 | last post by:
I need an example of how to marshal a structure that has an array of another structures as a member. An example as mentioned below public struct strcutdata { ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.