472,958 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 1504

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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.