473,767 Members | 8,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MarshalDirectiv eException: 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(La youtKind::Seque ntial, Pack = 1, CharSet =
CharSet::Unicod e)]
public value struct tSomeData
{
[MarshalAs(Unman agedType::ByVal TStr, SizeConst = DataStrLen)]
String ^fDataStr;
};

[ComVisible(true )]
[Guid("...")]
[InterfaceType(C omInterfaceType ::InterfaceIsIU nknown)]
public interface class ISomeData
{
[PreserveSig]
tSomeData* getDataPtr();
};

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

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

private:
tSomeData ^m_tSomeData;
};

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

#import "SomeData.t lb" no_namespace raw_interfaces_ only

int _tmain(int argc, _TCHAR* argv[])
{
HRESULT hr = ::CoInitializeE x(0, COINIT_MULTITHR EADED);
if (FAILED(hr))
return -1;

try
{
CComPtr<ISomeDa taspSomeData;
hr = ::CoCreateInsta nce(__uuidof(So meData), NULL,
CLSCTX_INPROC_S ERVER,
__uuidof(ISomeD ata),
(void**)&spSome Data);
tSomeData *pSomeData = spSomeData->getDataPtr() ; // !!!
MarshalDirectiv eException !!!
}
catch (...)
{
}

::CoUninitializ e();
return 0;
}

When I run test following error occurred while determining how to
marshal the parameters of member 'getDataPtr' of type
'SomeData.ISome Data':
"System.Runtime .InteropService s.MarshalDirect iveException: 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 1546

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

Similar topics

3
2666
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 anything helpfull in internet for 4 months ;-( . Please someone who is more expirenced help me. I am trying to use the Terminal Server APIs There is as an API function WTSEnumerateSessions, which returns a WTS_SESSION_INFO custom structure n times....
3
1312
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 below... --
3
3644
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
8696
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 located somewhere in how I'm marshaling it. Any input would be appreciated. (examples are shortened for clarity, let me know if something more complete would be useful /*C code* typedef float RotMtxType typedef struct double ccNum RotMtxType...
0
1472
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 how to get to the contents of "dumberstruct" contained within "dumbstruct" (i.e. dumbstruct.dstruct) 2. How to get to dumbstruct.tag_field_value and dumbstruct.field_value Code follows
2
1874
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 can't find the correct sequence to declare the marshal attributes of my structures, I always got an exception at runtime when marshaling my data. Here an example of code, which gives me the exception "Type TypeData can not be marshaled as an...
6
4228
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), MarshalAs(UnmanagedType.ByValArray, SizeConst:=8)> Public action As Char() <VBFixedString(7), MarshalAs(UnmanagedType.ByValArray, SizeConst:=7)> Public equip_key As Char() <VBFixedString(256), MarshalAs(UnmanagedType.ByValArray, SizeConst:=256)> Public message As Char()
4
9665
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 using the attribute The calling program doesn't know the size of the array, so I would like the dll to dynamically expand the array, and return the right sized array.
0
952
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 { public System.UInt16 ln; public int in; public System.UInt32 tn;
0
10170
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10014
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9960
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8840
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7384
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6656
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5280
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5425
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2808
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.